summaryrefslogtreecommitdiffstats
path: root/mpeglib/example/yaf/yafcore/outputDecoder.cpp
blob: 0993add0fde0f2db701d7df407ad2b9b3a1479f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
  Default output decoder
  Copyright (C) 1998  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */

#include "outputDecoder.h"
#include <iostream>

using namespace std;

#define DEBUG cout << "Command:1 Msg:"


OutputDecoder::OutputDecoder() {
  yafCommands=new CommandTableYAF();
  yafRuntime=new RuntimeTableYAF();

  appendCommandTable(yafCommands);
  appendRuntimeTable(yafRuntime);
  
}



OutputDecoder::~OutputDecoder() {
  delete yafCommands;
  delete yafRuntime;
}



void OutputDecoder::appendCommandTable(CommandTable* table) {
  commandTable.join(table);
}


void OutputDecoder::appendRuntimeTable(CommandTable* table) {
  runtimeTable.join(table);
}



CommandTable* OutputDecoder::getCommandTable() {
  return &commandTable;
}


CommandTable* OutputDecoder::getRuntimeTable() {
  return &runtimeTable;
}




void OutputDecoder::processCommandLine(CommandLine* commandLine){
  CommandTable* ct=&commandTable;  // ct , rt are shorter..
  CommandTable* rt=&runtimeTable;

  
  int command;
  int commandNr;
  const char* commandStr;
  const char* retString;
  const char* args;


  // The number of the command (unique for every command)
  commandNr=atoi(commandLine->getValue(0));

  // if commandNr is greater zero then we have a return command from decoder
  if (commandNr >= 40) {

    // the command (longName or shortName )
    commandStr=ct->getCommand(commandLine->getValue(2));
    // the int value of the command (faster for compare)
    command=ct->getNr(commandStr);

    // the Arguments of the command
    args=ct->getArgs(commandStr,commandLine->getValue(2));
    retString=commandLine->getValue(1);
    
    processReturnCommand(commandNr,command,retString,args);
    return;
  }

  // if commandNr < 40 then we have a runtime command from decoder

  if (commandNr < 40) {
    // the command (longName or shortName )
    commandStr=rt->getCommand(commandLine->getValue(1));
    // the int value of the command (faster for compare)
    command=rt->getNr(commandStr);

    // here I make a hack because it cannot be expected
    // that during debugging every debug-info has its clean
    // installed debug-identifer.
    // hack:
    // if the commandNr==1 (debug) and we have NO defined
    // debug identifier then we do not send -1 (as in all other case)
    // but the number 1 itsself.
    
    if ((commandNr == 1) && (command == -1)) {
     args=rt->getArgs(commandStr,commandLine->getValue(1));
     processRuntimeCommand(1,args);
     return;
    }

    // in *all* other cases the developer should
    // implement a clean protokoll with identifiers
    // (this leads to well defined interfaces :-)

    // the Arguments of the command
    args=rt->getArgs(commandStr,commandLine->getValue(1));
    
    processRuntimeCommand(command,args);
    return;
  }


}



int OutputDecoder::processRuntimeCommand(int command,const char* args){
  cout << command <<" * "<< args <<" * "<< endl;
  return false;
}

int OutputDecoder::processReturnCommand(int cmdNr,int cmdId,
					const char* ret,const char* args){
  cout << cmdNr <<" * "<< cmdId<<" * "<< ret<<" * " << args << endl;
  return false;
}