The Output Thread.
00036 {
00037 ThreadArgs* targs = (ThreadArgs*) targz;
00038 fprintf(stderr,"[opT] OutputThread alive...\n");
00039
00040
00041 //TODO: loading all plugins and start them as thread
00042
00043 // <TEMPORARILY>
00044 ThreadArgs* vargs;
00045 vargs = new ThreadArgs;
00046 vargs->argc = 1;
00047 vargs->argv = targs->argv;
00048
00049 ThreadArgs* cargs = new ThreadArgs;
00050 cargs->argc = 1;
00051 cargs->argv = targs->argv;
00052 Buffer* commandBufferIn = cargs->in = new Buffer();
00053
00054 while ( !outputBufferIn ) usleep(10000);
00055 cargs->out = outputBufferIn;
00056
00057 Buffer* visBufferIn = vargs->in = new Buffer();
00058
00059 pthread_t vThread; //THOSE THINGS SHALL BECOME PLUGINS VERY SOON!!
00060 pthread_t commandThread;
00061
00062 pthread_create (&vThread, NULL, VisualizationThread, vargs);
00063 pthread_create (&commandThread, NULL, CommandThread, cargs);
00064
00065 DatabaseAccess dbAccess ( CLIENT_OUTPUT );
00066
00067 while (1)
00068 {
00069 if ( !outputBufferIn->isEmpty() )
00070 {
00071 #ifdef DEBUG
00072 fprintf(stderr,"[opT] getting a packet.. :)\n");
00073 #endif
00074
00075 packet* pak = outputBufferIn->read ( );
00076
00077 switch ( pak->h.header[0] )
00078 {
00079 case PROT_OUTPUT_VISUAL:
00080 {
00081 switch ( pak->h.header[1] )
00082 {
00083 case VISUAL_CAMERA_MOVE:
00084 {
00085 #ifdef DEBUG
00086 fprintf(stderr,"[oT] VISUAL_CAMERA_MOVE\n");
00087 #endif
00088
00089 pak->h.header[0] = pak->h.header[1];
00090 pak->h.header[1] = pak->h.header[2];
00091 visBufferIn->write ( pak );
00092 break;
00093 }
00094
00095 case VISUAL_CAMERA_LOOKTO:
00096 {
00097 #ifdef DEBUG
00098 fprintf(stderr,"[oT] VISUAL_CAMERA_LOOKTO\n");
00099 #endif
00100
00101 pak->h.header[0] = pak->h.header[1];
00102 pak->h.header[1] = pak->h.header[2];
00103 visBufferIn->write ( pak );
00104 break;
00105 }
00106
00107 case VISUAL_NEW_OBJECT:
00108 {
00109 fprintf(stderr,"[oT] Received a new object\n");
00110 pak->h.header[0] = pak->h.header[1];
00111 visBufferIn->write ( pak );
00112 break;
00113 }
00114
00115 case VISUAL_MY_OBJECT:
00116 {
00117 pak->h.header[0] = pak->h.header[1];
00118 visBufferIn->write ( pak );
00119 break;
00120 }
00121
00122 default:
00123 {
00124 #ifdef DEBUG
00125 fprintf(stderr,"[oT] OUTPUT_VISUAL: i don't know this action..\n");
00126 #endif
00127
00128 delete pak;
00129 break;
00130 }
00131 }
00132
00133 break;
00134 }
00135
00136 case PROT_OUTPUT_DUMMY: //just for testing purpose..
00137 {
00138 fprintf(stderr,"[opT] *-*-*-*-*-*-*-* Output Dummy: %s *-*-*-*-*-*-*-*\n",pak->data.c_str ());
00139 delete pak;
00140 break;
00141 }
00142 case PROT_GET_ALL_CHANGED:
00143 {
00144 #ifdef DEBUG
00145 fprintf(stderr,"pgac.");
00146 #endif
00147 dbAccess.getAllObjects();
00148
00149 delete pak;
00150 break;
00151 }
00152
00153 case PROT_GET_ALL_OBJECTS_REPLY:
00154 {
00155 /****************************************+
00156 header[1] Object ID
00157 header[2] classtype
00158 *****************************************/
00159
00160 #ifdef DEBUG
00161 fprintf(stderr,"[oT] PROT_GET_ALL_OBJECTS_REPLY..\n");
00162 #endif
00163
00164 dbAccess.getObject ( pak->h.header[1] );
00165
00166 delete pak;
00167 break;
00168 }
00169
00170 case PROT_GET_OBJECT_REPLY:
00171 {
00172 /******************************************
00173 header[1] ObjectID
00174 data name of object
00175 ******************************************/
00176
00177 #ifdef DEBUG
00178 fprintf(stderr,"[oT] PROT_GET_OBJECT_REPLY\n");
00179 #endif
00180
00181 pak->h.header[0] = VISUAL_NEW_OBJECT;
00182
00183 visBufferIn->write ( pak );
00184
00185 break;
00186 }
00187
00188 case PROT_GET_ALL_ATOMS_REPLY:
00189 {
00190 /*****************************************
00191 header[1] AtomID
00192 header[2] ObjectID
00193 header[3] atomType of Atom
00194 *****************************************/
00195
00196 #ifdef DEBUG3
00197 fprintf(stderr,"[oT] PROT_GET_ALL_ATOMS_REPLY\n");
00198 #endif
00199
00200 switch ( pak->h.header[3] )
00201 {
00202 case AT_POSITION:
00203 {
00204 #ifdef DEBUG3
00205 fprintf(stderr,"[oT] pos-change\n");
00206 #endif
00207 dbAccess.getAtom ( pak->h.header[1], pak->h.header[2], pak->h.header[3] );
00208
00209 break;
00210 }
00211
00212 case AT_3DSIAGRAPH:
00213 {
00214 #ifdef DEBUG3
00215 fprintf(stderr,"[oT] graphics\n");
00216 #endif
00217 dbAccess.getAtom ( pak->h.header[1], pak->h.header[2], pak->h.header[3] );
00218 break;
00219 }
00220
00221 case AT_CHATMSG:
00222 {
00223 #ifdef DEBUG3
00224 fprintf(stderr,"chatmsg\n");
00225 #endif
00226 dbAccess.getAtom ( pak->h.header[1], pak->h.header[2], pak->h.header[3] );
00227
00228 break;
00229 }
00230
00231 default:
00232 {
00233 #ifdef DEBUG3
00234 fprintf(stderr,"[oT] i don't want that (%d)!\n",pak->h.header[2]);
00235 #endif
00236 break;
00237 }
00238 }
00239
00240
00241 delete pak;
00242 break;
00243 }
00244
00245 case PROT_GET_ATOM_REPLY:
00246 {
00247 #ifdef DEBUG3
00248 fprintf(stderr,"[oT] PROT_GET_ATOM_REPLY\n");
00249 #endif
00250
00251 pak->h.header[0] = VISUAL_NEW_ATOM;
00252
00253 #ifdef DEBUG
00254 fprintf(stderr,"[oT] [%d] - [%d]\n",pak->h.header[2],pak->h.header[3]);
00255 #endif
00256
00257 visBufferIn->write ( pak );
00258
00259 #ifdef DEBUG
00260 fprintf(stderr,"[oT] successful..\n");
00261 #endif
00262 break;
00263 }
00264
00265 case PROT_TEXT_MSG:
00266 {
00267 commandBufferIn->write ( pak );
00268 break;
00269 }
00270
00271
00272 case PROT_CHAT_MSG:
00273 {
00274 coreBufferIn->write ( pak);
00275 break;
00276 }
00277
00278 case PROT_TURN_AVATAR_OFF:
00279 {
00280 pak->h.header[0] = VISUAL_TURN_AVATAR_OFF;
00281 visBufferIn->write ( pak );
00282 break;
00283 }
00284
00285 default:
00286 {
00287 fprintf(stderr,"[oT] default...\n");
00288 delete pak;
00289 break;
00290 }
00291 }
00292 }
00293 }
00294 }