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

coreThread.cpp File Reference

#include "misc.h"
#include "coreClass.h"
#include "../common/databaseAccess.h"
#include "parseObject.h"

Go to the source code of this file.

Functions

void* coreThread ( void* targz )
 The coreThread. More...


Variables

BuffercoreBufferIn = 0
 The coreThread's buffer. More...

map<int,Buffer*> clientBufferIn
 The buffers the matrixThread's clients (those are coreThread and outputThread) read from. More...


Function Documentation

void * coreThread ( void * targs)

The coreThread.

Parameters:
targs   passes the arguments which came from main()

Definition at line 34 of file coreThread.cpp.

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     }

Variable Documentation

map<int,Buffer *> clientBufferIn

The buffers the matrixThread's clients (those are coreThread and outputThread) read from.

Definition at line 32 of file coreThread.cpp.

Buffer * coreBufferIn = 0

The coreThread's buffer.

Definition at line 30 of file coreThread.cpp.


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