2
process Messages on the decoder
3
Copyright (C) 1998 Martin Vogt
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.
9
For more information look at the file COPYRIGHT in this package
14
#include "inputDecoder.h"
16
#include "commandTable.h"
17
#include "commandTableYAF.h"
18
#include "yafRuntime.defs"
19
#include "commandLine.h"
22
InputDecoder::InputDecoder() {
23
commandTable=new CommandTable();
24
yafCommands=new CommandTableYAF();
25
appendCommandTable(yafCommands);
26
status=_DECODER_STATUS_IDLE;
28
returnBuffer= new Buffer(200);
29
returnLine= new Buffer(200);
34
commandCounterString=NULL;
39
InputDecoder::~InputDecoder(){
48
void InputDecoder::setRuntimeInfo(int lRuntimeInfo) {
49
this->lRuntimeInfo=lRuntimeInfo;
53
int InputDecoder::getRuntimeInfo() {
58
void InputDecoder::appendCommandTable(CommandTable* table){
59
commandTable->join(table);
65
void InputDecoder::processCommandLine(CommandLine* commandLine){
66
CommandTable* ct=commandTable; // "ct" is shorter
69
// The number of the command (unique for every command)
70
commandCounterString=commandLine->getValue(0);
71
commandCounter=atoi(commandCounterString);
73
// the command (longName or shortName )
74
if (commandLine->getCommandCount() == 0) {
76
appendReturnBuffer("no Msg");
78
commandMsg=ct->getCommand(commandLine->getValue(1));
79
if ((commandMsg == NULL) || (strlen(commandMsg) == 0)) {
81
appendReturnBuffer("unknown Command");
82
commandMsg=commandLine->getValue(1);
87
// the int value of the command (faster for compare)
88
commandId=ct->getNr(commandMsg);
90
// the Arguments of the command
91
commandArgs=ct->getArgs(commandMsg,(const char*) commandLine->getValue(1));
93
retString=processCommand(commandId,commandArgs);
95
if ((retString == NULL) || (strlen(retString) == 0)) {
96
retString=(char*)"ok";
99
appendReturnBuffer(retString);
103
const char* InputDecoder::processCommand(int command,const char* args){
105
if (command == _YAF_I_HELP) {
106
if (strlen(args)==0) {
107
commandTable->print();
109
commandTable->print(commandTable->getNr(args),true);
113
if (command == _YAF_I_RUNTIME) {
114
if (strcmp("off",args)==0) {
115
setRuntimeInfo(false);
118
setRuntimeInfo(true);
121
if (command == _YAF_I_QUIT) {
125
if (command == _YAF_I_WHATIS) {
126
cout << "Yaf <y>et <a>nother <f>rontend" << endl;
128
cout << "Yaf is an interactive command line oriented shell for decoders." \
131
cout << "Copyright (C) 1998,1999 Martin Vogt <mvogt@rhrk.uni-kl.de>"\
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;
139
cout << "For more information look at the file COPYRIGHT in "\
140
<< "this package" <<endl;
142
cout << "THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! " \
143
<< "USE AT YOUR OWN RISK!"<<endl;
148
if (command == _YAF_I_PING) {
151
if (command == _YAF_I_PROTOCOL) {
154
if (command == _YAF_I_NOPROTOCOL) {
158
return "unknown Command";
163
These two functions are entered by the decoder
168
void InputDecoder::doSomething(){
169
cout << "did something"<<endl;
174
int InputDecoder::getDecoderStatus() {
180
void InputDecoder::setDecoderStatus(int newState) {
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) {
192
void InputDecoder::clearReturnBuffer() {
193
returnBuffer->clear();
197
void InputDecoder::appendReturnBuffer(const char* str) {
198
returnBuffer->append(str);
203
const char* InputDecoder::getReturnCode() {
204
// now we send back the return code
206
if ((commandId != -1) && (commandTable->getReturnFlag(commandId)==false)) {
211
returnLine->append("Command:");
214
// The number of the command (unique for every command)
216
returnLine->append(commandCounterString);
217
returnLine->append(" Ret:(");
218
returnLine->append(returnBuffer->getData());
219
returnLine->append(") Msg:");
222
// now get the part after Msg: (in the inputLine)
224
returnLine->append(commandMsg);
225
returnLine->append(" ");
226
returnLine->append(commandArgs);
230
return (const char*)returnLine->getData();