00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "RioMMEmul.h"
00019 #include "RioError.h"
00020
00021 #ifdef RIO_EMUL
00022
00023 using namespace std;
00024
00025
00026
00027
00028
00029
00030
00031
00032 RioMMEmul::RioMMEmul( const char *filename, CRioMMObject *object )
00033 {
00034 this->object = object;
00035 this->sessions = fopen( filename, "r" );
00036
00037 if( sessions == NULL )
00038 {
00039 Rioperror("[RioMMEmul open]");
00040 exit(-1);
00041 }
00042
00043 RioErr << "[RioMMEmul] Actions gotten from file " << filename << endl;
00044 }
00045
00046 RioMMEmul::~RioMMEmul()
00047 {
00048 if( fclose(sessions) )
00049 {
00050 Rioperror(NULL);
00051 exit(-1);
00052 }
00053
00054 }
00055
00056
00057
00058
00059
00060 double RioMMEmul::run()
00061 {
00062 double currtime = 0;
00063 double tmp = 0;
00064 int param = 0;
00065 char oper[20] = "UNKNOWN";
00066 static char line[80] = " ";
00067 static bool isFirstRead = true;
00068
00069
00070
00071 if( isFirstRead )
00072 {
00073 if( fgets(line, 80, sessions) == NULL )
00074 {
00075 Rioperror(NULL);
00076 RioErr << "[RioMMEmul] Error fgets function" << endl;
00077 exit(1);
00078 }
00079 else
00080 {
00081 isFirstRead = false;
00082 }
00083 }
00084
00085 if( sscanf(line, "%lf %s %d\n", &tmp, oper, ¶m) != 3 )
00086 {
00087 RioErr << "[RioMMEmul] Wrong input format (" << line << ")." << endl;
00088 exit(1);
00089 }
00090
00091 switch( getOperand( oper ) )
00092 {
00093 case OPEN:
00094 {
00095 RioErr << "[RioMMEmul]------------------------------------" << endl;
00096 RioErr << "[RioMMEmul] Open" << endl;
00097
00098 play();
00099 if( fgets(line, 80, sessions) == NULL )
00100 {
00101 Rioperror(NULL);
00102 exit(1);
00103 }
00104 if( sscanf(line, "%lf %*s %*d\n", &currtime ) != 1 )
00105 {
00106 RioErr << "[RioMMEmul] Wrong input format (" << line << ")."
00107 << endl;
00108 exit(1);
00109 }
00110 tmp = currtime - tmp;
00111 RioErr << "[RioMMEmul] Open() - valor retornado: " << tmp << endl;
00112 break;
00113 }
00114 case PLAY:
00115 {
00116 RioErr << "[RioMMEmul]------------------------------------" << endl;
00117 RioErr << "[RioMMEmul] PLAY" << endl;
00118
00119 play();
00120
00121 if( fgets(line, 80, sessions) == NULL )
00122 {
00123 Rioperror( NULL );
00124 exit( 1 );
00125 }
00126 if( sscanf(line, "%lf %*s %*d\n", &currtime ) != 1 )
00127 {
00128 RioErr << "[RioMMEmul] Wrong input format (" << line << ")."
00129 << endl;
00130 exit(1);
00131 }
00132 tmp = currtime - tmp;
00133 RioErr << "[RioMMEmul] Play() - valor retornado: " << tmp << endl;
00134 break;
00135 }
00136 case STOP:
00137 {
00138 RioErr << "[RioMMEmul]------------------------------------" << endl;
00139 RioErr << "[RioMMEmul] STOP" << endl;
00140
00141 stop();
00142 if( fgets(line, 80, sessions) == NULL )
00143 {
00144 Rioperror(NULL);
00145 exit(1);
00146 }
00147 if( sscanf(line, "%lf %*s %*d\n", &currtime ) != 1 )
00148 {
00149 RioErr << "[RioMMEmul] Wrong input format (" << line << ")."
00150 << endl;
00151 exit(1);
00152 }
00153 tmp = currtime - tmp;
00154
00155 RioErr << "[RioMMEmul] Stop() - valor retornado: " << tmp << endl;
00156 break;
00157 }
00158 case JUMP:
00159 {
00160 RioErr << "[RioMMEmul]------------------------------------" << endl;
00161 RioErr << "[RioMMEmul] JUMP " << param << endl;
00162
00163 jump( param );
00164 if( fgets(line, 80, sessions) == NULL )
00165 {
00166 Rioperror(NULL);
00167 exit(1);
00168 }
00169 if( sscanf(line, "%lf %*s %*d\n", &currtime ) != 1 )
00170 {
00171 RioErr << "[RioMMEmul] Wrong input format (" << line << ")."
00172 << endl;
00173 exit(1);
00174 }
00175 tmp = currtime - tmp;
00176
00177 RioErr << "[RioMMEmul] Jump() - valor retornado: "
00178 << tmp << endl;
00179
00180 break;
00181 }
00182 case PAUSE:
00183 {
00184 RioErr << "[RioMMEmul]------------------------------------" << endl;
00185 RioErr << "[RioMMEmul] PAUSE" << endl;
00186
00187 pause();
00188 if( fgets(line, 80, sessions) == NULL )
00189 {
00190 Rioperror(NULL);
00191 exit(1);
00192 }
00193 if( sscanf(line, "%lf %*s %*d\n", &currtime ) != 1 )
00194 {
00195 RioErr << "[RioMMEmul] Wrong input format (" << line << ")."
00196 << endl;
00197 exit(1);
00198 }
00199 tmp = currtime - tmp;
00200
00201 RioErr << "[RioMMEmul] Pause() - valor retornado: " << tmp << endl;
00202
00203 break;
00204 }
00205 case UNPAUSE:
00206 {
00207 RioErr << "[RioMMEmul]------------------------------------" << endl;
00208 RioErr << "[RioMMEmul] UNPAUSE" << endl;
00209
00210 unpause();
00211 if( fgets(line, 80, sessions) == NULL )
00212 {
00213 Rioperror(NULL);
00214 exit(1);
00215 }
00216 if( sscanf(line, "%lf %*s %*d\n", &currtime ) != 1 )
00217 {
00218 RioErr << "[RioMMEmul] Wrong input format (" << line << ")."
00219 << endl;
00220 exit(1);
00221 }
00222 tmp = currtime - tmp;
00223
00224 RioErr << "[RioMMEmul] Unpause() - valor retornado: " << tmp << endl;
00225
00226 break;
00227 }
00228 case QUIT:
00229 {
00230 RioErr << "[RioMMEmul]------------------------------------" << endl;
00231 RioErr << "[RioMMEmul] QUIT" << endl;
00232
00233 quit();
00234 tmp = -1;
00235
00236 RioErr << "[RioMMEmul] Quit() - valor retornado: " << tmp << endl;
00237 break;
00238 }
00239 default:
00240 RioErr << "[RioMMEmul] Unknown operation: " << line << endl;
00241 exit(1);
00242 }
00243
00244 return( tmp );
00245 }
00246
00247
00248
00249
00250 void RioMMEmul::play()
00251 {
00252 RioErr << "[RioMMEmul] Entrando no Play." << endl;
00253 object->Play();
00254 }
00255
00256
00257
00258
00259 void RioMMEmul::pause()
00260 {
00261 RioErr << "[RioMMEmul] Entrando no Pause." << endl;
00262 object->Pause();
00263 }
00264
00265
00266
00267 void RioMMEmul::unpause()
00268 {
00269 RioErr << "[RioMMEmul] Entrando no unpause." << endl;
00270 object->Play();
00271 }
00272
00273
00274
00275 void RioMMEmul::stop()
00276 {
00277 RioErr << "[RioMMEmul] Entrando no stop." << endl;
00278 object->Stop();
00279 RioErr << "[RioMMEmul] Retornando do stop." << endl;
00280 }
00281
00282
00283
00284 void RioMMEmul::quit()
00285 {
00286 RioErr << "[RioMMEmul] Entrando no quit." << endl;
00287 object->Quit();
00288 RioErr << "[RioMMEmul] Retornando do quit." << endl;
00289 }
00290
00291
00292
00293
00294 void RioMMEmul::jump( int block )
00295 {
00296 RioErr << "[RioMMEmul] jumping to block " << block << endl;
00297 object->GoTo( block );
00298 }
00299
00300 int RioMMEmul::getOperand( char *oper )
00301 {
00302 int intoper = UNKNOWN;
00303
00304 if( strcmp( oper, "OPEN") == 0 )
00305 intoper = OPEN;
00306 else if( strcmp( oper, "PLAY") == 0 )
00307 intoper = PLAY;
00308 else if( strcmp( oper, "STOP") == 0 )
00309 intoper = STOP;
00310 else if( strcmp( oper, "JUMP") == 0 )
00311 intoper = JUMP;
00312 else if( strcmp( oper, "PAUSE") == 0 )
00313 intoper = PAUSE;
00314 else if( strcmp( oper, "UNPAUSE") == 0 )
00315 intoper = UNPAUSE;
00316 else if( strcmp( oper, "QUIT") == 0 )
00317 intoper = QUIT;
00318
00319 return intoper;
00320 }
00321 #endif