Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phWifiLinkData.cpp

Go to the documentation of this file.
00001 #include <phWifiLinkData.h>
00002 #include <phbase.h>
00003     
00004 /* ------------------------------------------------------------------------ */
00005 phWifiLinkData::phWifiLinkData()
00006 {
00007     phFUNCTION("phWifiLinkData::phWifiLinkData")
00008     int locked = 0;
00009     int rwlocked = 0;
00010     
00011     phTHIS_LOOSE_LOCK(locked);
00012     phTHIS_WRITELOCK_LOOSE(rwlocked);
00013     
00014     this->setName("phWifiLinkData");
00015     
00016     memset(this->m_mac,  0, sizeof(uint8_t)*32);
00017     memset(this->m_ip,   0, sizeof(uint8_t)*32);
00018     memset(this->m_essid,0, sizeof(char)*32);
00019 
00020     this->m_mode        = -1;
00021     this->m_encrypt     = 0;
00022     this->m_freq        = 0.0;
00023     this->m_qual        = 0;
00024     this->m_level       = 0;
00025     this->m_noise       = 0;
00026     this->m_id          = -1;
00027 
00028     phTHIS_RWUNLOCK_LOOSE(rwlocked);
00029     phTHIS_LOOSE_UNLOCK(locked);
00030 }
00031 
00032 /* ------------------------------------------------------------------------ */
00033 int phWifiLinkData::copy( phObject *copyto_object )
00034 {
00035     phFUNCTION("phWifiLinkData::copy")
00036     
00037     if (this->isNamed(((phObject *)copyto_object)->getName()))
00038     {
00039         phWifiLinkData *copyto_data = (phWifiLinkData *)copyto_object;
00040         return copyto_data->copyData(*this);
00041     }
00042     /* Otherwise I'll assume they are incompatible */
00043     else
00044     {
00045         phPRINT_RC(-1,NULL, "Invalid object pairing in update."
00046                           "[ this:%s != target:%s ]",
00047                  this->getName(), ((phObject *)copyto_object)->getName());
00048         return phFAIL;
00049     }
00050 }
00051 
00052 /* ------------------------------------------------------------------------ */
00053 int phWifiLinkData::swap( phObject *object )
00054 {
00055     phFUNCTION("phWifiLinkData::swap")
00056 
00057     if (this->isNamed(((phObject *)object)->getName()))
00058     {
00059         phWifiLinkData *data = (phWifiLinkData *)object;
00060 
00061         return data->swapData(*this);
00062     }
00063     /* Otherwise I'll assume they are incompatible */
00064     else
00065     {
00066         phPRINT_RC(-1,NULL, "Invalid object pairing in update."
00067                           "[ this:%s != target:%s ]",
00068                  this->getName(), ((phObject *)object)->getName());
00069         return phFAIL;
00070     }    
00071 }
00072 
00073 /* ------------------------------------------------------------------------ */
00074 int phWifiLinkData::copyData( phWifiLinkData &copyfrom )
00075 {
00076     phFUNCTION("phWifiLinkData::copyData")
00077     int rwlocked = 0;
00078     int other_rwlocked = 0;
00079    
00080     phTHIS_WRITELOCK(rwlocked);
00081     phREADLOCK(copyfrom,other_rwlocked);
00082     
00083     memcpy(this->m_mac, copyfrom.m_mac,     sizeof(uint8_t)*32);
00084     memcpy(this->m_ip,  copyfrom.m_ip,      sizeof(uint8_t)*32);
00085     memcpy(this->m_essid,copyfrom.m_essid,  sizeof(char)*32);
00086 
00087     this->m_mode        = copyfrom.m_mode;
00088     this->m_encrypt     = copyfrom.m_encrypt;
00089     this->m_freq        = copyfrom.m_freq;
00090     this->m_qual        = copyfrom.m_qual;
00091     this->m_level       = copyfrom.m_level;
00092     this->m_noise       = copyfrom.m_noise;
00093     this->m_id          = copyfrom.m_id;
00094 
00095     rc = this->notify();
00096     phPRINT_RC(rc,NULL,"this->notify()");
00097 
00098     phRWUNLOCK(copyfrom,other_rwlocked);
00099     phTHIS_RWUNLOCK(rwlocked);
00100 
00101     return phSUCCESS;
00102 error:
00103     phRWUNLOCK_ERROR(copyfrom,other_rwlocked);
00104     phTHIS_RWUNLOCK_ERROR(rwlocked);
00105     
00106     return phFAIL;    
00107 }
00108 
00109 /* ------------------------------------------------------------------------ */
00110 int phWifiLinkData::swapData( phWifiLinkData &data )
00111 {
00112     phFUNCTION("phWifiLinkData::swapData")
00113     int rwlocked = 0;
00114     int other_rwlocked = 0;
00115     
00116     uint8_t t_mac[32]       = {0};
00117     uint8_t t_ip[32]        = {0};
00118     char    t_essid[32]     = {0};
00119     int     t_mode          = -1;
00120     int     t_encrypt       = 0;
00121     double  t_freq          = 0.0;
00122     int     t_qual          = 0;
00123     int     t_level         = 0;
00124     int     t_noise         = 0;
00125     int     t_id            = -1;
00126 
00127     phTHIS_WRITELOCK(rwlocked);
00128         
00129     if (this->isSwapEnabled())
00130     {
00131         phWRITELOCK(data,other_rwlocked);
00132     
00133         /* Data to temp */
00134         memcpy(t_mac, data.m_mac,     sizeof(uint8_t)*32);
00135         memcpy(t_ip,  data.m_ip,      sizeof(uint8_t)*32);
00136         memcpy(t_essid,data.m_essid,  sizeof(char)*32);
00137         t_mode          = data.m_mode;
00138         t_encrypt       = data.m_encrypt;
00139         t_freq          = data.m_freq;
00140         t_qual          = data.m_qual;
00141         t_level         = data.m_level;
00142         t_noise         = data.m_noise;
00143         t_id            = data.m_id;
00144 
00145         /* this to data */
00146         memcpy(data.m_mac, this->m_mac,     sizeof(uint8_t)*32);
00147         memcpy(data.m_ip,  this->m_ip,      sizeof(uint8_t)*32);
00148         memcpy(data.m_essid,this->m_essid,  sizeof(char)*32);
00149         data.m_mode        = this->m_mode;
00150         data.m_encrypt     = this->m_encrypt;
00151         data.m_freq        = this->m_freq;
00152         data.m_qual        = this->m_qual;
00153         data.m_level       = this->m_level;
00154         data.m_noise       = this->m_noise;
00155         data.m_id           = this->m_id;
00156 
00157         /* temp to this */    
00158         memcpy(this->m_mac, t_mac,     sizeof(uint8_t)*32);
00159         memcpy(this->m_ip,  t_ip,      sizeof(uint8_t)*32);
00160         memcpy(this->m_essid,t_essid,  sizeof(char)*32);
00161         this->m_mode        = t_mode;
00162         this->m_encrypt     = t_encrypt;
00163         this->m_freq        = t_freq;
00164         this->m_qual        = t_qual;
00165         this->m_level       = t_level;
00166         this->m_noise       = t_noise;
00167         this->m_id          = t_id;
00168 
00169         rc = this->notify();
00170         phPRINT_RC(rc,NULL,"this->notify()");
00171 
00172         rc = data.notify();
00173         phPRINT_RC(rc,NULL,"data.notify()");
00174 
00175         phRWUNLOCK(data,other_rwlocked);
00176     }
00177     else
00178     {
00179         rc = this->copyData(data);
00180         phCHECK_RC(rc,NULL,"this->copyData(data)");
00181     }
00182     phTHIS_RWUNLOCK(rwlocked);
00183 
00184     return phSUCCESS;
00185 error:
00186     phRWUNLOCK_ERROR(data,other_rwlocked);
00187     phTHIS_RWUNLOCK_ERROR(rwlocked);
00188 
00189     return phFAIL;    
00190 }
00191 
00192 /* ------------------------------------------------------------------------ */
00193 int phWifiLinkData::reset()
00194 {
00195     phFUNCTION("phWifiLinkData::reset")
00196     int rwlocked = 0;
00197 
00198     phTHIS_WRITELOCK(rwlocked);
00199 
00200     memset(this->m_mac,  0, sizeof(uint8_t)*32);
00201     memset(this->m_ip,   0, sizeof(uint8_t)*32);
00202     memset(this->m_essid,0, sizeof(char)*32);
00203 
00204     this->m_mode        = -1;
00205     this->m_encrypt     = 0;
00206     this->m_freq        = 0.0;
00207     this->m_qual        = 0;
00208     this->m_level       = 0;
00209     this->m_noise       = 0;
00210     this->m_id          = -1;
00211 
00212     phTHIS_RWUNLOCK_RET(rwlocked,phSUCCESS,phFAIL);
00213 }
00214 
00215 
00216 /* ------------------------------------------------------------------------ */
00217 int phWifiLinkData::set(uint8_t mac     [32],
00218                         uint8_t ip      [32],
00219                         char    essid   [32],
00220                         int     mode,
00221                         int     encrypt,
00222                         double  freq,
00223                         int     qual,
00224                         int     level,
00225                         int     noise,
00226                         int     id      )
00227 {
00228     phFUNCTION("phWifiLinkData::set")
00229     int rwlocked = 0;
00230     int i = 0;
00231     
00232     phTHIS_WRITELOCK(rwlocked);
00233             
00234     memcpy(this->m_mac, mac,     sizeof(uint8_t)*32);
00235     memcpy(this->m_ip,  ip,      sizeof(uint8_t)*32);
00236     memcpy(this->m_essid,essid,  sizeof(char)*32);
00237     this->m_mode        = mode;
00238     this->m_encrypt     = encrypt;
00239     this->m_freq        = freq;
00240     this->m_qual        = qual;
00241     this->m_level       = level;
00242     this->m_noise       = noise;
00243     this->m_id          = id;
00244 
00245     rc = this->notify();
00246     phPRINT_RC(rc,NULL,"this->notify()");
00247 
00248     this->print_data();
00249     
00250     phTHIS_RWUNLOCK_RET(rwlocked,phSUCCESS,phFAIL);
00251 }
00252 
00253 /* ------------------------------------------------------------------------ */
00254 int phWifiLinkData::get(uint8_t *mac,
00255                         uint8_t *ip,
00256                         char    *essid,
00257                         int     *mode,
00258                         int     *encrypt,
00259                         double  *freq,
00260                         int     *qual,
00261                         int     *level,
00262                         int     *noise,
00263                         int     *id )
00264 {
00265     phFUNCTION("phWifiLinkData::get")
00266     int rwlocked = 0;
00267 
00268     phTHIS_READLOCK(rwlocked);
00269 
00270     if (mac != NULL)
00271         memcpy(mac,   this->m_mac,   sizeof(uint8_t)*32);
00272     if (ip != NULL)
00273         memcpy(ip,    this->m_ip,    sizeof(uint8_t)*32);
00274     if (essid != NULL)
00275         memcpy(essid, this->m_essid, sizeof(char)*32);
00276 
00277     if (mode != NULL)
00278         *mode        = this->m_mode;
00279     if (encrypt != NULL)
00280         *encrypt     = this->m_encrypt;
00281     if (freq != NULL)
00282         *freq        = this->m_freq;
00283     if (qual != NULL)
00284         *qual        = this->m_qual;
00285     if (level != NULL)
00286         *level       = this->m_level;
00287     if (noise != NULL)
00288         *noise       = this->m_noise;
00289     if (id != NULL)
00290         *id          = this->m_id;
00291 
00292     phTHIS_RWUNLOCK_RET(rwlocked,phSUCCESS,phFAIL);
00293 }
00294 
00295 /* ------------------------------------------------------------------------ */
00296 int phWifiLinkData::getMac( uint8_t *mac )
00297 {
00298     phFUNCTION("phWifiLinkData::get")
00299     int rwlocked = 0;
00300  
00301     phTHIS_READLOCK(rwlocked);
00302 
00303     if (mac != NULL)
00304         memcpy(mac,this->m_mac,sizeof(uint8_t)*32);
00305 
00306     phTHIS_RWUNLOCK_RET(rwlocked,phSUCCESS,phFAIL);
00307 }
00308 
00309 /* ------------------------------------------------------------------------ */
00310 int phWifiLinkData::getIp( uint8_t *ip )
00311 {
00312     phFUNCTION("phWifiLinkData::get")
00313     int rwlocked = 0;
00314  
00315     phTHIS_READLOCK(rwlocked);
00316     
00317     if (ip != NULL)
00318         memcpy(ip,this->m_ip,sizeof(uint8_t)*32);
00319 
00320     phTHIS_RWUNLOCK_RET(rwlocked,phSUCCESS,phFAIL);
00321 }
00322 
00323 /* ------------------------------------------------------------------------ */
00324 int phWifiLinkData::getEssid( char *essid )
00325 {
00326     phFUNCTION("phWifiLinkData::getEssid")
00327     int rwlocked = 0;
00328  
00329     phTHIS_READLOCK(rwlocked);
00330 
00331     if (essid != NULL)
00332         memcpy(essid,this->m_essid,sizeof(uint8_t)*32);
00333 
00334     phTHIS_RWUNLOCK_RET(rwlocked,phSUCCESS,phFAIL);
00335 }
00336 
00337 /* ------------------------------------------------------------------------ */
00338 int phWifiLinkData::getMode(  )
00339 {
00340     phFUNCTION("phWifiLinkData::getMode")
00341     int rwlocked = 0;
00342     int retval = 0;
00343  
00344     phTHIS_READLOCK(rwlocked);
00345 
00346     retval = this->m_mode;
00347 
00348     phTHIS_RWUNLOCK_RET(rwlocked,retval,-1);
00349 }
00350 /* ------------------------------------------------------------------------ */
00351 int phWifiLinkData::getEncrypt(  )
00352 {
00353     phFUNCTION("phWifiLinkData::getEncrypt")
00354     int rwlocked = 0;
00355     int retval = 0;
00356  
00357     phTHIS_READLOCK(rwlocked);
00358 
00359     retval = this->m_encrypt;
00360 
00361     phTHIS_RWUNLOCK_RET(rwlocked,retval,0);
00362 }
00363 
00364 /* ------------------------------------------------------------------------ */
00365 double phWifiLinkData::getFreq(  )
00366 {
00367     phFUNCTION("phWifiLinkData::getFreq")
00368     int rwlocked = 0;
00369     double retval = 0;
00370  
00371     phTHIS_READLOCK(rwlocked);
00372 
00373     retval = this->m_freq;
00374 
00375     phTHIS_RWUNLOCK_RET(rwlocked,retval,0);
00376 }
00377 
00378 /* ------------------------------------------------------------------------ */
00379 int phWifiLinkData::getQuality(  )
00380 {
00381     phFUNCTION("phWifiLinkData::getQuality")
00382     int rwlocked = 0;
00383     int retval = 0;
00384  
00385     phTHIS_READLOCK(rwlocked);
00386 
00387     retval = this->m_qual;
00388 
00389     phTHIS_RWUNLOCK_RET(rwlocked,retval,0);
00390 }
00391 
00392 /* ------------------------------------------------------------------------ */
00393 int phWifiLinkData::getLevel(  )
00394 {
00395     phFUNCTION("phWifiLinkData::getLevel")
00396     int rwlocked = 0;
00397     int retval = 0;
00398  
00399     phTHIS_READLOCK(rwlocked);
00400 
00401     retval = this->m_level;
00402 
00403     phTHIS_RWUNLOCK_RET(rwlocked,retval,0);
00404 }
00405 
00406 /* ------------------------------------------------------------------------ */
00407 int phWifiLinkData::getNoise(  )
00408 {
00409     phFUNCTION("phWifiLinkData::getNoise")
00410     int rwlocked = 0;
00411     int retval = 0;
00412  
00413     phTHIS_READLOCK(rwlocked);
00414 
00415     retval = this->m_noise;
00416 
00417     phTHIS_RWUNLOCK_RET(rwlocked,retval,0);
00418 }
00419 
00420 /* ------------------------------------------------------------------------ */
00421 int phWifiLinkData::getId(  )
00422 {
00423     phFUNCTION("phWifiLinkData::getId")
00424     int rwlocked = 0;
00425     int retval = 0;
00426  
00427     phTHIS_READLOCK(rwlocked);
00428 
00429     retval = this->m_id;
00430 
00431     phTHIS_RWUNLOCK_RET(rwlocked,retval,0);
00432 }
00433 
00434 /* ------------------------------------------------------------------------ */
00435 void phWifiLinkData::print_data( )
00436 {
00437     phFUNCTION("phWifiLinkData::print_data")
00438     int i           = 0;
00439     int j           = 0;
00440     int rwlocked    = 0;
00441 
00442     phTHIS_READLOCK_LOOSE(rwlocked);
00443     
00444     fprintf(stderr,"----------------------------------------------------\n");
00445     fprintf(stderr,"%s (%p)\n",this->getName(),this);
00446     fprintf(stderr,"----------------------------------------------------\n");
00447     fprintf(stderr,"Id: %d\n",this->m_id);
00448     fprintf(stderr,"Mac: ");
00449     for (i = 0; i < 32; i++ )
00450     {
00451         fprintf(stderr,"%02d-",this->m_mac[i]);
00452     }
00453     fprintf(stderr,"\n");
00454 
00455     fprintf(stderr,"Ip: ");
00456     for (i = 0; i < 32; i++ )
00457     {
00458         fprintf(stderr,"%02d-",this->m_ip[i]);
00459     }
00460     fprintf(stderr,"\n");
00461 
00462     fprintf(stderr,"ESSID: ");
00463     for (i = 0; i < 32; i++ )
00464     {
00465         fprintf(stderr,"%02d-",this->m_essid[i]);
00466     }
00467     fprintf(stderr,"\n");
00468     fprintf(stderr,"mode: %d encrypt: %d freq: %0.8f qual: %d level: %d noise: %d\n",
00469             this->m_mode,this->m_encrypt,this->m_freq,this->m_qual,
00470             this->m_level, this->m_noise );
00471 
00472     fprintf(stderr,"----------------------------------------------------\n");
00473     
00474     phTHIS_RWUNLOCK_LOOSE(rwlocked);
00475 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:07 2007 for phission by  doxygen 1.4.4