Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

coreThread.cpp

Go to the documentation of this file.
00001 /********************************************************************
00002 Description: The Client Core Thread
00003 part of the 3Dsia project
00004 created: xandi, 080400
00005 
00006 History:
00007     date,   name,       changes,                    in funtion
00008     180400  StonedBones added dynamic packet length
00009 
00010 ********************************************************************/
00011 
00012 
00013 
00014 /*...................................................................
00015 Description: The Client Core Thread
00016 Args: ThreadArgs* targs
00017 Returns: none
00018 Created: xandi, 080400
00019 [ToDo:]
00020 [Comments:]
00021 Changes:
00022 -------------------------------------------------------------------*/
00023 
00024 #include "misc.h"
00025 #include "coreClass.h"
00026 
00027 #include "../common/databaseAccess.h"
00028 #include "parseObject.h"
00029 
00030 Buffer* coreBufferIn = 0;//< the buffer the core Thread reads from
00031 
00032 extern map<int,Buffer*> clientBufferIn; //< the buffers the matrixThread uses to send its clients replies
00033 
00034 void* coreThread ( void* targz )
00035     {
00036     ThreadArgs* targs = (ThreadArgs*) targz;
00037     coreClass* cc = new coreClass ( targs );
00038 
00039     extern Buffer* outputBufferIn;
00040 
00041     Buffer* coreIn = 0;
00042     Buffer* comOut = 0;
00043 
00044     packet* pak = 0;
00045 
00046     if ( cc->connectNow() )
00047         {
00048         fprintf(stderr,"[coreThread] unable to connect to host\n");
00049         pthread_exit (NULL);
00050         }
00051 
00052     if ( ! (coreIn = cc->getBuffer ( INCOMING ) ) )
00053         exit (1);
00054     if ( ! (comOut = cc->getBuffer ( OUTGOING ) ) )
00055         exit (1);
00056     if ( !outputBufferIn )
00057         exit (1);
00058 
00059 
00060     clientBufferIn[CLIENT_CORE] = coreIn;
00061     DatabaseAccess dbAccess ( CLIENT_CORE );
00062 
00063     int myObjectID = 0;
00064 
00065     // <TEMPORARILY>
00066     coreBufferIn = coreIn;
00067     // </TEMPORARILY>
00068 
00069     cc->startQuartz    ( 25 );
00070 //    cc->setUpdateFreq ( 10 );
00071 
00072     while (1)
00073         {
00074         if ( !coreIn->isEmpty() )
00075             {
00076             pak = coreIn->read ();
00077 
00078 #ifdef DEBUG
00079             fprintf ( stderr, "[coT] got a packet %d \n", pak->h.header[0]);
00080 #endif
00081 
00082             switch ( pak->h.header[0] )
00083                 {
00084 /*                case PROT_ACCESS_MATRIX:
00085                     {
00086                     cc->accessMatrix ( pak->data );
00087                     delete pak;
00088                     break;
00089                     }
00090 */
00091                 case PROT_REGISTER_ENTITY_REPLY:
00092                     {
00093 
00094                     //OK, You can now send your avatardata!!! COOL!! :))
00095                     myObjectID = pak->h.header[1];
00096                     fprintf(stderr,"[coT] my Avatar ID is %d\n",myObjectID);
00097 
00098                     pak->h.header[0] = PROT_AVATAR_HULL;
00099                     pak->data = readFile( "clonewar.avatar" );
00100 
00101                     comOut->write ( pak );
00102 
00103 
00104                     packet* xpak = new packet;
00105                     xpak->h.header[0] = PROT_OUTPUT_VISUAL;
00106                     xpak->h.header[1] = VISUAL_MY_OBJECT;
00107                     xpak->h.header[2] = myObjectID;
00108 
00109                     outputBufferIn->write ( xpak );
00110 
00111                     break;
00112                     }
00113 
00114 
00115                 case PROT_SEND_MSG:
00116                     {
00117 #ifdef DEBUG
00118                     fprintf(stderr,"[coT] trying to send a message...\n");
00119 #endif
00120                     comOut->write (pak);
00121                     break;
00122                     }
00123 
00124                 case PROT_TEXT_MSG:
00125                     {
00126                     outputBufferIn->write ( pak );
00127                     break;
00128                     }
00129 
00130                 case PROT_CHAT_MSG:
00131                     {
00132                     fprintf(stderr,"[coT] trying to send a message...\n");
00133 
00134                     comOut->write (pak);
00135                     break;
00136                     }
00137 
00138 
00139                 case PROT_CHANGE_POSITION:
00140                     {
00141                     comOut->write ( pak );
00142                     break;
00143                     }
00144 
00145                 case PROT_RECEIVE_OBJECT:
00146                     {
00147                     /*******************************************************
00148                     header[1]   ObjectID
00149                     data        the name of the object
00150                     *******************************************************/
00151 #ifdef DEBUG
00152                     fprintf(stderr,"[coT] Received an object\n");
00153 #endif
00154                     dbAccess.addObject ( pak->h.header[1], pak->data  );
00155 
00156                     delete pak;
00157                     pak = 0;
00158                     break;
00159                     }
00160 
00161 
00162                 case PROT_RECEIVE_ATOM:
00163                     {
00164                     /*******************************************************
00165                     header[1]   ObjectID
00166                     header[2]   atom Type
00167                     header[3]   atomID
00168                     header[4]   valueType
00169                     data        the atom data
00170                     *******************************************************/
00171 
00172 #ifdef DEBUG2
00173                     fprintf(stderr,"[coT] Received an atom %d %d %d %d %s\n",pak->h.header[1], pak->h.header[2], pak->h.header[3],pak->h.header[4], pak->data.c_str());
00174 #endif
00175 
00176                     dbAccess.addAtom ( pak->h.header[3], pak->h.header[1], pak->h.header[2], pak->data );
00177 //                    dbAccess.addAtom ( pak->h.header[3], pak->h.header[1], pak->h.header[2],pak->h.header[4], pak->data );
00178 
00179                     delete pak;
00180                     pak = 0;
00181                     break;
00182                     }
00183 
00184 
00185                 case PROT_OUTPUT_VISUAL:
00186                     {
00187 #ifdef DEBUG
00188                     fprintf(stderr,"[coT] getting a PROT_OUTPUT_VISUAL\n");
00189 #endif
00190                     outputBufferIn->write ( pak );
00191                     break;
00192                     }
00193 
00194                 case PROT_OUTPUT_DUMMY:
00195                     {
00196 #ifdef DEBUG
00197                     fprintf(stderr,"[coT] getting a PROT_OUTPUT_DUMMY\n");
00198 #endif
00199                     outputBufferIn->write ( pak );
00200                     break;
00201                     }
00202 
00203 
00204                 default:
00205                     {
00206 //#ifdef DEBUG
00207                     fprintf(stderr,"[coreThread] packet number: %d\n",pak->h.header[0]);
00208 //#endif
00209                     delete pak;
00210                     pak = 0;
00211                     break;
00212                     }
00213                 }
00214             }
00215         }
00216     }
00217 
00218 
00219 
00220 
00221 /*
00222                 case PROT_REQUEST_REPLY:
00223                     {
00224 #ifdef DEBUG
00225                     fprintf(stderr,"[coreThread] matrix successfully accessed\n");
00226 #endif
00227                     delete pak;
00228                     break;
00229                     }
00230 
00231                 case PROT_MATRIX_STUFF_REPLY:
00232                     {
00233 #ifdef DEBUG
00234                     fprintf(stderr,"[coT] PROT_MATRIX_STUFF_REPLY!\n");
00235 #endif
00236                     switch ( pak->h.header[1] )
00237                         {
00238                         default:
00239 #ifdef DEBUG
00240                             fprintf(stderr,"[coT] h.header[1] = %d\n", pak->h.header[1]);
00241 #endif
00242                             break;
00243                         }
00244                     delete pak;
00245                     break;
00246                     }
00247 
00248 */
00249 

Generated at Sat May 13 13:50:18 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000