00001 /******************************************************************** 00002 Description: The Quartz ;) 00003 part of the 3Dsia project 00004 created: xandi, 250400 00005 00006 History: 00007 date, name, changes, in funtion 00008 00009 ********************************************************************/ 00010 00011 00012 /*................................................................... 00013 Description: quartz 00014 Args: ThreadArgs* targs 00015 Returns: none 00016 Created: xandi, 250400 00017 [ToDo:] 00018 [Comments:] 00019 Changes: 00020 -------------------------------------------------------------------*/ 00021 00022 #include "misc.h" 00023 #include "quartz.h" 00024 00025 QuartzClass::QuartzClass ( Buffer* bufferIn, int reqPackType, int freq ) 00026 { 00027 qbuf = bufferIn; 00028 requestPacket = reqPackType; 00029 frequency = freq; 00030 00031 #ifdef DEBUG 00032 fprintf(stderr,"[QUARTZCLASS (%d): %d %d %d\n",this,qbuf,requestPacket,frequency); 00033 #endif 00034 } 00035 00036 void QuartzClass::setFrequency ( int freq ) 00037 { 00038 frequency = freq; 00039 } 00040 00041 int QuartzClass::getFrequency ( void ) 00042 { 00043 return frequency; 00044 } 00045 00046 int QuartzClass::getRequestPacket ( void ) 00047 { 00048 return requestPacket; 00049 } 00050 00051 Buffer* QuartzClass::getBuf ( void ) 00052 { 00053 return qbuf; 00054 } 00055 00056 void* QuartzThread ( void* qObj ) 00057 { 00058 QuartzClass* myQuartzObject = (QuartzClass*) qObj; 00059 00060 fprintf(stderr,"[qT] Quartz Thread started.. frequency: %d\n",myQuartzObject->getFrequency()); 00061 00062 while (1) 00063 { 00064 #ifdef DEBUGEXTREME 00065 fprintf(stderr,"[qT] %d,%d,%d,%d",myQuartzObject 00066 ,myQuartzObject->getFrequency() 00067 ,myQuartzObject->getRequestPacket() 00068 ,myQuartzObject->getBuf()); 00069 #endif 00070 00071 int test = myQuartzObject->getFrequency(); 00072 00073 if ( !test ) test = 1; 00074 00075 usleep ( (int)( 1000000 / test ) ); 00076 00077 packet* pak; 00078 pak = new packet; 00079 00080 pak->h.header[0] = myQuartzObject->getRequestPacket(); 00081 00082 #ifdef DEBUG 00083 fprintf(stderr,"[asking myQuartzObject(%p)->getBuf()]\n",myQuartzObject); 00084 #endif 00085 00086 Buffer* myqbuf = myQuartzObject->getBuf(); 00087 00088 #ifdef DEBUG 00089 fprintf(stderr,"[attempting to write into buffer (%p)]\n",myqbuf); 00090 #endif 00091 00092 if ( myqbuf ) 00093 myqbuf->write ( pak ); 00094 else 00095 exit(1); 00096 00097 #ifdef DEBUG 00098 fprintf(stderr,"[sending update request successful]\n"); 00099 #endif 00100 } 00101 00102 } 00103 00104