~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/example/yaf/yafcore/inputDecoder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  process Messages on the decoder
 
3
  Copyright (C) 1998  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include "inputDecoder.h"
 
15
 
 
16
#include "commandTable.h"
 
17
#include "commandTableYAF.h"
 
18
#include "yafRuntime.defs"
 
19
#include "commandLine.h"
 
20
 
 
21
 
 
22
InputDecoder::InputDecoder() {
 
23
  commandTable=new CommandTable();
 
24
  yafCommands=new CommandTableYAF();
 
25
  appendCommandTable(yafCommands);
 
26
  status=_DECODER_STATUS_IDLE;
 
27
  lRuntimeInfo=true;
 
28
  returnBuffer= new Buffer(200);
 
29
  returnLine= new Buffer(200);
 
30
 
 
31
  commandCounter=-1;
 
32
  commandCounter=-1;
 
33
  commandId=-1;
 
34
  commandCounterString=NULL;
 
35
  
 
36
}
 
37
 
 
38
 
 
39
InputDecoder::~InputDecoder(){
 
40
  delete yafCommands;
 
41
  delete returnBuffer;
 
42
  delete returnLine;
 
43
  delete commandTable;
 
44
}
 
45
 
 
46
 
 
47
 
 
48
void InputDecoder::setRuntimeInfo(int lRuntimeInfo) {
 
49
  this->lRuntimeInfo=lRuntimeInfo;
 
50
}
 
51
 
 
52
 
 
53
int InputDecoder::getRuntimeInfo() {
 
54
  return lRuntimeInfo;
 
55
}
 
56
 
 
57
 
 
58
void InputDecoder::appendCommandTable(CommandTable* table){
 
59
  commandTable->join(table);
 
60
}
 
61
 
 
62
 
 
63
 
 
64
 
 
65
void InputDecoder::processCommandLine(CommandLine* commandLine){
 
66
  CommandTable* ct=commandTable;  // "ct" is shorter
 
67
  commandId=-1;
 
68
 
 
69
  // The number of the command (unique for every command)
 
70
  commandCounterString=commandLine->getValue(0);
 
71
  commandCounter=atoi(commandCounterString);
 
72
 
 
73
  // the command (longName or shortName )
 
74
  if (commandLine->getCommandCount() == 0) {
 
75
    clearReturnBuffer();
 
76
    appendReturnBuffer("no Msg");
 
77
  }    
 
78
  commandMsg=ct->getCommand(commandLine->getValue(1));
 
79
  if ((commandMsg == NULL) || (strlen(commandMsg) == 0)) {
 
80
    clearReturnBuffer();
 
81
    appendReturnBuffer("unknown Command");
 
82
    commandMsg=commandLine->getValue(1);
 
83
 
 
84
    return ;
 
85
  }
 
86
 
 
87
  // the int value of the command (faster for compare)
 
88
  commandId=ct->getNr(commandMsg);
 
89
 
 
90
  // the Arguments of the command
 
91
  commandArgs=ct->getArgs(commandMsg,(const char*) commandLine->getValue(1));
 
92
 
 
93
  retString=processCommand(commandId,commandArgs);
 
94
 
 
95
  if ((retString == NULL) || (strlen(retString) == 0)) {
 
96
    retString=(char*)"ok";
 
97
  }
 
98
  clearReturnBuffer();
 
99
  appendReturnBuffer(retString);
 
100
}
 
101
 
 
102
 
 
103
const char* InputDecoder::processCommand(int command,const char* args){
 
104
 
 
105
  if (command == _YAF_I_HELP) {
 
106
    if (strlen(args)==0) {
 
107
      commandTable->print();
 
108
    } else {
 
109
      commandTable->print(commandTable->getNr(args),true);
 
110
    }
 
111
    return "";
 
112
  }
 
113
  if (command == _YAF_I_RUNTIME) {
 
114
    if (strcmp("off",args)==0) {
 
115
      setRuntimeInfo(false);
 
116
      return "";
 
117
    }
 
118
    setRuntimeInfo(true);
 
119
    return "";
 
120
  }
 
121
  if (command == _YAF_I_QUIT) {
 
122
    ::exit(0);
 
123
    return "";
 
124
  }
 
125
  if (command == _YAF_I_WHATIS) {
 
126
    cout << "Yaf <y>et <a>nother <f>rontend" << endl;
 
127
    cout << endl;
 
128
    cout << "Yaf is an interactive command line oriented shell for decoders." \
 
129
         << endl;
 
130
    cout << endl;
 
131
    cout << "Copyright (C) 1998,1999  Martin Vogt <mvogt@rhrk.uni-kl.de>"\
 
132
         <<endl;
 
133
    cout << "This program is free software; you can redistribute "\
 
134
         << "it and/or modify"<<endl;
 
135
    cout << "it under the terms of the GNU Library General Public License "\
 
136
         << "as published by"<<endl;
 
137
    cout << "the Free Software Foundation." <<endl;
 
138
 
 
139
    cout << "For more information look at the file COPYRIGHT in "\
 
140
         << "this package" <<endl;
 
141
    cout << endl;
 
142
    cout << "THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! " \
 
143
         << "USE AT YOUR OWN RISK!"<<endl;
 
144
    return "";
 
145
  }
 
146
      
 
147
  
 
148
  if (command == _YAF_I_PING) {
 
149
    return "";
 
150
  }
 
151
  if (command == _YAF_I_PROTOCOL) {
 
152
    return "";
 
153
  }
 
154
  if (command == _YAF_I_NOPROTOCOL) {
 
155
    return "";
 
156
  }
 
157
 
 
158
  return "unknown Command";
 
159
}
 
160
 
 
161
 
 
162
/**
 
163
   These two functions are entered by the decoder
 
164
   thread  [START]
 
165
*/
 
166
 
 
167
 
 
168
void InputDecoder::doSomething(){
 
169
  cout << "did something"<<endl;
 
170
}
 
171
 
 
172
 
 
173
 
 
174
int InputDecoder::getDecoderStatus() {
 
175
  return status;
 
176
}
 
177
 
 
178
 
 
179
 
 
180
void InputDecoder::setDecoderStatus(int newState) {
 
181
 
 
182
  // First start a new thread with start()!
 
183
  // Their is no recovery if the thread status is set to exit!
 
184
  if (status == _DECODER_STATUS_EXIT) {
 
185
    return;
 
186
  }
 
187
  status=newState;
 
188
}
 
189
 
 
190
 
 
191
 
 
192
void InputDecoder::clearReturnBuffer() {
 
193
  returnBuffer->clear();
 
194
}
 
195
 
 
196
 
 
197
void InputDecoder::appendReturnBuffer(const char* str) {
 
198
  returnBuffer->append(str);
 
199
}
 
200
 
 
201
 
 
202
 
 
203
const char* InputDecoder::getReturnCode() {
 
204
  // now we send back the return code
 
205
  
 
206
  if ((commandId != -1) && (commandTable->getReturnFlag(commandId)==false)) {
 
207
    return "";
 
208
  }
 
209
 
 
210
  returnLine->clear();
 
211
  returnLine->append("Command:");
 
212
 
 
213
 
 
214
  // The number of the command (unique for every command)
 
215
  // 0: the command nr
 
216
  returnLine->append(commandCounterString);
 
217
  returnLine->append(" Ret:(");
 
218
  returnLine->append(returnBuffer->getData());
 
219
  returnLine->append(") Msg:");
 
220
 
 
221
  
 
222
  // now get the part after Msg: (in the inputLine)
 
223
 
 
224
  returnLine->append(commandMsg);
 
225
  returnLine->append(" ");
 
226
  returnLine->append(commandArgs);
 
227
 
 
228
 
 
229
 
 
230
  return (const char*)returnLine->getData();
 
231
 
 
232
}
 
233
 
 
234
  
 
235