Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

rmSysInfo.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <wchar.h>
00003 
00004 #include <cassert>
00005 
00006 #include <ResourceMonitor/ResourceMonitor.h>
00007 
00008 #include "rmSysInfo.h"
00009 #include "rmClientError.h"
00010 
00023 int
00024 subsystemInfo::init(resourceInfo * aResourceInfo, statisticInfo * aStatisticInfo)
00025 {
00026   // init pointers to other info tables.
00027   mResourceInfo = aResourceInfo;
00028   mStatisticInfo = aStatisticInfo;
00029 
00030   size_t count;
00031   int ret;
00032   unsigned long id;
00033   SubsystemInfo info;
00034 
00035   count = ResourceMonitor::rmGetSubsystemCount();
00036   if(count == 0)
00037     return RMCLIENT_SUCCESS;
00038 
00039   rmSubsystemInfo *subInfo;
00040   subInfo = new rmSubsystemInfo[count];
00041   if(!subInfo)
00042     return RMCLIENT_ERROR_MEMORY;
00043 
00044   ret = ResourceMonitor::rmGetAvailableSubsystems(subInfo, count);
00045   if(ret)
00046     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00047 
00048   for(size_t i = 0; i<count; i++) {
00049 
00050     info.info = subInfo[i];
00051     ret = newElement(info, id);
00052     if(ret)
00053       return ret;
00054 
00055   }
00056 
00057   delete [] subInfo;
00058   return RMCLIENT_SUCCESS;
00059 }
00060 
00061 int
00062 subsystemInfo::getUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00063 {
00064   if(aUUIDStr == NULL)
00065     return RMCLIENT_ERROR_BAD_POINTER;
00066 
00067   aUUIDStr[0] = '\0';
00068 
00069   const SubsystemInfo * info = getConstElement(aID);
00070   if(!info)
00071     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00072 
00073   switch(aName) {
00074     case SUBSYSTEMINFO_UUID:
00075       uuid_unparse((unsigned char*)info->info.id, aUUIDStr);
00076       break;
00077 
00078     default:
00079       return  RMCLIENT_ERROR_NOSUCHNAME;
00080   }
00081 
00082   aUUIDStr[UUID_STRING_LENGTH - 1] = '\0';
00083   return RMCLIENT_SUCCESS;
00084 }
00085 
00086 int
00087 subsystemInfo::getUUID(RMAttribute aName, unsigned long aID, uuid_t aUUID)
00088 {
00089   if(aUUID == NULL)
00090     return RMCLIENT_ERROR_BAD_POINTER;
00091 
00092   uuid_clear(aUUID);
00093 
00094   const SubsystemInfo * info = getConstElement(aID);
00095   if(!info)
00096     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00097 
00098   switch(aName) {
00099     case SUBSYSTEMINFO_UUID:
00100       uuid_copy(aUUID, (unsigned char*)info->info.id);
00101       break;
00102 
00103     default:
00104       return  RMCLIENT_ERROR_NOSUCHNAME;
00105   }
00106 
00107   return RMCLIENT_SUCCESS;
00108 }
00109 
00110 int
00111 subsystemInfo::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00112 {
00113   aValue = 0;
00114 
00115   const SubsystemInfo * info = getConstElement(aID);
00116   if(!info)
00117     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00118 
00119   switch(aName) {
00120     case SUBSYSTEMINFO_RESOURCECOUNT:
00121       aValue = info->info.noResources;
00122       break;
00123 
00124     case SUBSYSTEMINFO_STATISTICCOUNT:
00125       aValue = info->info.noStatistics;
00126       break;
00127 
00128     default:
00129       return  RMCLIENT_ERROR_NOSUCHNAME;
00130   }
00131 
00132   return RMCLIENT_SUCCESS;
00133 }
00134 
00135 int
00136 subsystemInfo::getString(RMAttribute aName, unsigned long aID, char * & aBuf)
00137 {
00138   aBuf = NULL;
00139 
00140   unsigned long len;
00141   char * str;
00142 
00143   const SubsystemInfo * info = getConstElement(aID);
00144   if(!info)
00145     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00146 
00147   switch(aName) {
00148     case SUBSYSTEMINFO_NAME:
00149       str = ResourceMonitor::rmGetSubsystemDescription(info->info.id, rmShortDescription);
00150       break;
00151 
00152     case SUBSYSTEMINFO_DESCRIPTION:
00153       str = ResourceMonitor::rmGetSubsystemDescription(info->info.id, rmLongDescription);
00154       break;
00155 
00156     default:
00157       return  RMCLIENT_ERROR_NOSUCHNAME;
00158   }
00159 
00160   if(!str)
00161     return RMCLIENT_ERROR_SUBSYSTEM_STRING;
00162 
00163   aBuf = str;
00164 
00165   return RMCLIENT_SUCCESS;
00166 }
00167 
00168 unsigned long
00169 subsystemInfo::getSubsystemIDByUUID(const uuid_t aUUID) 
00170 {
00171   int ret;
00172 
00173   unsigned long id(0), nid(0);
00174   const SubsystemInfo * info;
00175 
00176   while(!getNextId(id, nid)) {
00177 
00178     id = nid;
00179     info = getConstElement(id);
00180 
00181     ret = uuid_compare((unsigned char*)aUUID, (unsigned char*)info->info.id);
00182     if(!ret) {
00183       return id;
00184     }
00185   }
00186   return 0;
00187 }
00188 
00189 int
00190 subsystemInfo::addSubsystemByUUID(const uuid_t aUUID)
00191 {
00192   int ret;
00193 
00194   // make sure it is a new subsystem
00195   unsigned long id = getSubsystemIDByUUID(aUUID);
00196   if(id != 0)
00197     return RMCLIENT_ERROR_SUBSYSTEM_ID;
00198 
00199   rmSubsystemInfo subInfo;
00200   ret = ResourceMonitor::rmGetSubsystemInfo(aUUID, &subInfo);
00201   if(ret)
00202     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00203 
00204   SubsystemInfo info;
00205   info.info = subInfo;
00206 
00207   // adding subsystem
00208   ret = newElement(info, id);
00209   if(ret)
00210     return ret;
00211 
00212   // adding resources
00213   return mResourceInfo->initResourceInfoBySubsystemID(id, true);
00214 }
00215 
00216 int
00217 subsystemInfo::removeSubsystemByUUID(const uuid_t aUUID)
00218 {
00219   int ret;
00220   unsigned long id(0), nid(0), sid;
00221 
00222   const ResourceInfo * rinfo;
00223   const StatisticInfo * sinfo;
00224 
00225   sid = getSubsystemIDByUUID(aUUID);
00226   if (sid == 0)
00227     return RMCLIENT_ERROR_SUBSYSTEM_ID;
00228 
00229   // statistics first
00230   while (!mStatisticInfo->getNextId(id, nid)) {
00231     id = nid;
00232 
00233     sinfo = mStatisticInfo->getConstElement(id);
00234     if (sinfo->subsystemId == sid) {
00235       mStatisticInfo->removeElement(id);
00236     }
00237   }
00238 
00239   // resources next
00240   id = 0;
00241   nid = 0;
00242   while (!mResourceInfo->getNextId(id, nid)) {
00243     id = nid;
00244 
00245     rinfo = mResourceInfo->getConstElement(id);
00246     if (rinfo->subsystemId == sid) {
00247       mResourceInfo->removeElement(id);
00248     }
00249   }
00250 
00251   return removeElement(sid);
00252 }
00253 
00266 int
00267 resourceInfo::init(subsystemInfo * aSubsystemInfo, statisticInfo * aStatisticInfo)
00268 {
00269   mSubsystemInfo = aSubsystemInfo;
00270   mStatisticInfo = aStatisticInfo;
00271 
00272   int ret;
00273   unsigned long id(0), nid(0);
00274 
00275   while(!mSubsystemInfo->getNextId(id, nid)) {
00276 
00277     id = nid;
00278     ret = initResourceInfoBySubsystemID(id);
00279     if(ret)
00280       return ret;
00281   }
00282 
00283   return RMCLIENT_SUCCESS;
00284 }
00285 
00286 int
00287 resourceInfo::initResourceInfoBySubsystemID(unsigned long aID, bool initStatistics = false)
00288 {
00289   int ret;
00290   const SubsystemInfo * sinfo;
00291   size_t resCount;
00292   unsigned long resid;
00293 
00294   rmResourceInfo * resInfo(NULL);
00295   ResourceInfo info;
00296 
00297   sinfo = mSubsystemInfo->getConstElement(aID);
00298   if(!sinfo)
00299     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00300 
00301   resCount = sinfo->info.noResources;
00302 
00303   if(resCount) {
00304 
00305     resInfo = new rmResourceInfo[resCount];
00306     if(!resInfo)
00307       return RMCLIENT_ERROR_MEMORY;
00308 
00309     ret = ResourceMonitor::rmGetActiveResources(sinfo->info.id, resInfo, resCount);
00310     if(ret)
00311       return RMCLIENT_ERROR_RESOURCE_INFO;
00312 
00313     for(size_t j=0; j < resCount; j++) {
00314       info.info = resInfo[j];
00315       info.subsystemId = aID;
00316 
00317       ret = newElement(info, resid);
00318       if(ret)
00319         return ret;
00320 
00321       if(initStatistics == true) {
00322         ret = mStatisticInfo->initStatisticInfoByResourceID(resid);
00323         if(ret)
00324           return ret;
00325       }
00326     }
00327 
00328     delete [] resInfo;
00329   }
00330 
00331   return RMCLIENT_SUCCESS;
00332 }
00333 
00334 int
00335 resourceInfo::getUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00336 {
00337   if(aUUIDStr == NULL)
00338     return RMCLIENT_ERROR_BAD_POINTER;
00339 
00340   aUUIDStr[0] = '\0';
00341 
00342   const ResourceInfo * info = getConstElement(aID);
00343   if(!info)
00344     return RMCLIENT_ERROR_RESOURCE_INFO;
00345 
00346   switch(aName) {
00347     case RESOURCEINFO_SUBSYSTEMUUID:
00348 
00349       uuid_unparse((unsigned char*)info->info.SubsystemId, aUUIDStr);
00350       break;
00351 
00352     default:
00353       return  RMCLIENT_ERROR_NOSUCHNAME;
00354   }
00355 
00356   aUUIDStr[UUID_STRING_LENGTH - 1] = '\0';
00357   return RMCLIENT_SUCCESS;
00358 }
00359 
00360 int
00361 resourceInfo::getUUID(RMAttribute aName, unsigned long aID, uuid_t aUUID)
00362 {
00363   if(aUUID == NULL)
00364     return RMCLIENT_ERROR_BAD_POINTER;
00365 
00366   uuid_clear(aUUID);
00367 
00368   const ResourceInfo * info = getConstElement(aID);
00369   if(!info)
00370     return RMCLIENT_ERROR_RESOURCE_INFO;
00371 
00372   switch(aName) {
00373     case RESOURCEINFO_SUBSYSTEMUUID:
00374       uuid_copy(aUUID, (unsigned char*)info->info.SubsystemId);
00375       break;
00376 
00377     default:
00378       return  RMCLIENT_ERROR_NOSUCHNAME;
00379   }
00380 
00381   return RMCLIENT_SUCCESS;
00382 }
00383 
00384 int
00385 resourceInfo::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00386 {
00387   aValue = 0;
00388 
00389   const ResourceInfo * info = getConstElement(aID);
00390   if(!info)
00391     return RMCLIENT_ERROR_RESOURCE_INFO;
00392 
00393   switch(aName) {
00394     case RESOURCEINFO_RESOURCEID:
00395       aValue = info->info.id;
00396       break;
00397 
00398     case RESOURCEINFO_SUBSYSTEMID:
00399       aValue = info->subsystemId;
00400       break;
00401 
00402     default:
00403       return  RMCLIENT_ERROR_NOSUCHNAME;
00404   }
00405 
00406   return RMCLIENT_SUCCESS;
00407 }
00408 
00409 int
00410 resourceInfo::getString(RMAttribute aName, unsigned long aID, char * & aBuf)
00411 {
00412   aBuf = NULL;
00413 
00414   unsigned long len;
00415   char * str;
00416 
00417   const ResourceInfo * info = getConstElement(aID);
00418   if(!info)
00419     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00420 
00421   switch(aName) {
00422     case RESORUCEINFO_NAME:
00423       str = ResourceMonitor::rmGetResourceDescription(info->info.SubsystemId,
00424                               info->info.id, rmShortDescription);
00425       break;
00426 
00427     case RESOURCEINFO_DESCRIPTION:
00428       str = ResourceMonitor::rmGetResourceDescription(info->info.SubsystemId,
00429                                info->info.id, rmLongDescription);
00430       break;
00431 
00432     default:
00433       return  RMCLIENT_ERROR_NOSUCHNAME;
00434   }
00435 
00436   if(!str)
00437     return RMCLIENT_ERROR_RESOURCE_STRING;
00438 
00439   aBuf = str;
00440 
00441   return RMCLIENT_SUCCESS;
00442 }
00443 
00444 int
00445 resourceInfo::addResource(const uuid_t aUUID, unsigned long aID)
00446 {
00447   int ret;
00448   unsigned long resid;
00449 
00450   unsigned long id = mSubsystemInfo->getSubsystemIDByUUID(aUUID);
00451   if(id == 0) {
00452     // hum, somehow the subsystem is not present at this moment.
00453     // let's see if we need to fix it later. for now, just return.
00454     return RMCLIENT_ERROR_SUBSYSTEM_ID;
00455   }
00456 
00457   rmResourceInfo resInfo;
00458   ret = ResourceMonitor::rmGetResourceInfo(aUUID, aID, &resInfo);
00459   if(ret)
00460     return RMCLIENT_ERROR_RESOURCE_INFO;
00461 
00462   ResourceInfo info;
00463   info.info = resInfo;
00464   info.subsystemId = id;
00465 
00466   ret = newElement(info, resid);
00467   if(ret)
00468     return ret;
00469 
00470   // adding statistics
00471   return mStatisticInfo->initStatisticInfoByResourceID(resid);
00472 }
00473 
00474 int
00475 resourceInfo::removeResource(const uuid_t aUUID, unsigned long aID)
00476 {
00477   int ret;
00478   unsigned long id(0), nid(0), subid;
00479   const ResourceInfo * rinfo;
00480   const StatisticInfo * sinfo;
00481 
00482   subid = mSubsystemInfo->getSubsystemIDByUUID(aUUID);
00483   if(subid == 0) {
00484     // hum, didn't find that subsystem.
00485     return RMCLIENT_ERROR_SUBSYSTEM_ID;
00486   }
00487 
00488   bool found = false;
00489   while(!getNextId(id, nid)) {
00490     id = nid;
00491 
00492     rinfo = getConstElement(id);
00493     if (subid == rinfo->subsystemId && aID == rinfo->info.id) {
00494       // found it.
00495       found = true;
00496       break;
00497     }
00498   }
00499 
00500   if(!found)
00501     return RMCLIENT_ERROR_RESOURCE_ID;
00502 
00503   unsigned long sid(0), snid(0);
00504   while(!mStatisticInfo->getNextId(sid, snid)) {
00505     sid = snid;
00506 
00507     sinfo = mStatisticInfo->getConstElement(sid);
00508     if(sinfo->resourceId == id) {
00509 
00510       if(sinfo->subsystemId != subid)
00511         return RMCLIENT_ERROR_STATISTIC_ID;
00512 
00513       mStatisticInfo->removeElement(sid);
00514     }
00515   }
00516   return removeElement(id);
00517 }
00518 
00519 
00520 int
00521 statisticInfo::init(subsystemInfo * aSubsystemInfo, resourceInfo * aResourceInfo)
00522 {
00523   mSubsystemInfo = aSubsystemInfo;
00524   mResourceInfo = aResourceInfo;
00525 
00526   int ret;
00527   unsigned long id(0), nid(0);
00528 
00529   while(!mResourceInfo->getNextId(id, nid)) {
00530 
00531     id = nid;
00532 
00533     ret = initStatisticInfoByResourceID(id);
00534     if(ret)
00535       return ret;
00536   }
00537 
00538   return RMCLIENT_SUCCESS;
00539 }
00540 
00541 int
00542 statisticInfo::initStatisticInfoByResourceID(unsigned long aID)
00543 {
00544   int ret;
00545   size_t statCount;
00546   unsigned long resid(0), statid, subid;
00547   const SubsystemInfo * sinfo;
00548 
00549   rmStatisticInfo * statInfo(NULL);
00550   StatisticInfo info;
00551 
00552   ret = mResourceInfo->getUnsigned(RESOURCEINFO_SUBSYSTEMID, aID, subid);
00553   if(ret)
00554     return ret;
00555 
00556   ret = mResourceInfo->getUnsigned(RESOURCEINFO_RESOURCEID, aID, resid);
00557   if(ret)
00558     return ret;
00559 
00560   sinfo = mSubsystemInfo->getConstElement(subid);
00561   if(!sinfo)
00562     return RMCLIENT_ERROR_SUBSYSTEM_INFO;
00563 
00564   statCount = sinfo->info.noStatistics;
00565 
00566   if(statCount) {
00567 
00568     statInfo = new rmStatisticInfo[statCount];
00569     if(!statInfo)
00570       return RMCLIENT_ERROR_MEMORY;
00571 
00572     ret = ResourceMonitor::rmGetAvailableStatistics(sinfo->info.id, statInfo, statCount);
00573     if(ret)
00574       return RMCLIENT_ERROR_STATISTIC_INFO;
00575 
00576     for(size_t j=0; j < statCount; j++) {
00577       info.info = statInfo[j];
00578       info.subsystemId = subid;
00579       info.resourceId = resid;
00580       info.guageUpperBound.rmValueU64 = 0;
00581       info.counterValue.rmValueU64 = 0;
00582 
00583       ret = newElement(info, statid);
00584       if(ret)
00585         return ret;
00586     }
00587   }
00588   delete [] statInfo;
00589 
00590   return RMCLIENT_SUCCESS;
00591 }
00592 
00593 int
00594 statisticInfo::getUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00595 {
00596   if(aUUIDStr == NULL)
00597     return RMCLIENT_ERROR_BAD_POINTER;
00598 
00599   aUUIDStr[0] = '\0';
00600 
00601   const StatisticInfo * info = getConstElement(aID);
00602   if(!info)
00603     return RMCLIENT_ERROR_STATISTIC_INFO;
00604 
00605   switch(aName) {
00606 
00607     case STATISTICINFO_SUBSYSTEMUUID:
00608       uuid_unparse((unsigned char*)info->info.SubsystemId, aUUIDStr);
00609       break;
00610 
00611     default:
00612       return RMCLIENT_ERROR_NOSUCHNAME;
00613   }
00614 
00615   aUUIDStr[UUID_STRING_LENGTH - 1] = '\0';
00616   return RMCLIENT_SUCCESS;
00617 }
00618 
00619 int
00620 statisticInfo::getUUID(RMAttribute aName, unsigned long aID, uuid_t aUUID)
00621 {
00622   if(aUUID == NULL)
00623     return RMCLIENT_ERROR_BAD_POINTER;
00624 
00625   uuid_clear(aUUID);
00626 
00627   const StatisticInfo * info = getConstElement(aID);
00628   if(!info)
00629     return RMCLIENT_ERROR_STATISTIC_INFO;
00630 
00631   switch(aName) {
00632 
00633     case STATISTICINFO_SUBSYSTEMUUID:
00634       uuid_copy(aUUID, (unsigned char*)info->info.SubsystemId);
00635       break;
00636 
00637     default:
00638       return RMCLIENT_ERROR_NOSUCHNAME;
00639   }
00640 
00641   return RMCLIENT_SUCCESS;
00642 
00643 }
00644 
00645 int
00646 statisticInfo::getInteger32(RMAttribute aName, unsigned long aID, long & aValue)
00647 {
00648   aValue = -1;
00649 
00650   const StatisticInfo * info = getConstElement(aID);
00651   if(!info)
00652     return RMCLIENT_ERROR_STATISTIC_INFO;
00653 
00654   switch(aName) {
00655 
00656     case STATISTICINFO_TYPE:
00657       aValue = info->info.type;
00658       break;
00659 
00660     case STATISTICINFO_SIZE:
00661       aValue = info->info.size;
00662       break;
00663 
00664     case STATISTICINFO_SCALE:
00665       aValue = info->info.scale;
00666       break;
00667 
00668     case STATISTICINFO_COUNTERRESET:
00669       aValue = 0;
00670       break;
00671 
00672     default:
00673       return RMCLIENT_ERROR_NOSUCHNAME;
00674   }
00675 
00676   return RMCLIENT_SUCCESS;
00677 }
00678 
00679 int
00680 statisticInfo::setInteger32(RMAttribute aName, unsigned long aID, long aValue)
00681 {
00682   int ret;
00683   rmStatisticId statid;
00684 
00685   StatisticInfo * info = getElement(aID);
00686   if(!info)
00687     return RMCLIENT_ERROR_STATISTIC_INFO;
00688 
00689   switch(aName) {
00690 
00691     case STATISTICINFO_COUNTERRESET:
00692       statid.ResourceId = info->resourceId;
00693       statid.StatisticId = info->info.id;
00694 
00695       uuid_clear(statid.SubsystemId);
00696       ret = mSubsystemInfo->getUUID(SUBSYSTEMINFO_UUID, info->subsystemId, statid.SubsystemId);
00697       if(ret)
00698         return RMCLIENT_ERROR_SUBSYSTEM_UUID;
00699 
00700       ret = ResourceMonitor::rmResetCounterStatistic(statid, &info->counterValue);
00701       if(ret)
00702         return RMCLIENT_ERROR_STATISTIC_UPPERBOUND;
00703 
00704       break;
00705 
00706     default:
00707       return RMCLIENT_ERROR_NOSUCHNAME;
00708   }
00709 
00710   return RMCLIENT_SUCCESS;
00711 }
00712   
00713 int
00714 statisticInfo::setUnsigned(RMAttribute aName, unsigned long aID, unsigned long aValue)
00715 {
00716   int ret;
00717 
00718   StatisticInfo * info = getElement(aID);
00719   if(!info)
00720     return RMCLIENT_ERROR_STATISTIC_INFO;
00721 
00722   switch(aName) {
00723 
00724     case STATISTICINFO_COUNTERRESETVALUE32:
00725       info->counterValue.rmValueU32 = aValue;
00726       break;
00727 
00728     default:
00729       return RMCLIENT_ERROR_NOSUCHNAME;
00730   }
00731 
00732   return RMCLIENT_SUCCESS;
00733 }
00734 
00735 int
00736 statisticInfo::setUnsigned64(RMAttribute aName, unsigned long aID, u_int64_t aValue)
00737 {
00738   int ret;
00739 
00740   StatisticInfo * info = getElement(aID);
00741   if(!info)
00742     return RMCLIENT_ERROR_STATISTIC_INFO;
00743 
00744   switch(aName) {
00745 
00746     case STATISTICINFO_COUNTERRESETVALUE64:
00747       info->counterValue.rmValueU64 = aValue;
00748       break;
00749 
00750     default:
00751       return RMCLIENT_ERROR_NOSUCHNAME;
00752   }
00753 
00754   return RMCLIENT_SUCCESS;
00755 }  
00756 
00757 int
00758 statisticInfo::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00759 {
00760   aValue = 0;
00761 
00762   int ret;
00763   rmValue value;
00764   rmStatisticId statid;
00765 
00766   const StatisticInfo * info = getConstElement(aID);
00767   if(!info)
00768     return RMCLIENT_ERROR_STATISTIC_INFO;
00769 
00770   switch(aName) {
00771 
00772     case STATISTICINFO_ID:
00773       aValue = info->info.id;
00774       break;
00775 
00776     case STATISTICINFO_SUBSYSTEMID:
00777       aValue = info->subsystemId;
00778       break;
00779 
00780     case STATISTICINFO_RESOURCEID:
00781       aValue = info->resourceId;
00782       break;
00783 
00784     case STATISTICINFO_COUNTERRESETVALUE32:
00785       aValue = info->counterValue.rmValueU32;
00786       break;
00787 
00788     case STATISTICINFO_GAUGEUPPERBOUND32:
00789       statid.ResourceId = info->resourceId;
00790       statid.StatisticId = info->info.id;
00791 
00792       uuid_clear(statid.SubsystemId);
00793       ret = mSubsystemInfo->getUUID(SUBSYSTEMINFO_UUID, info->subsystemId, statid.SubsystemId);
00794       if(ret)
00795         return RMCLIENT_ERROR_SUBSYSTEM_UUID;
00796 
00797       ret = ResourceMonitor::rmGetUpperBound(statid, &value);
00798       if(ret)
00799         return RMCLIENT_ERROR_STATISTIC_UPPERBOUND;
00800 
00801       aValue = value.rmValueU32;
00802       break;
00803 
00804     default:
00805       return RMCLIENT_ERROR_NOSUCHNAME;
00806   }
00807 
00808   return RMCLIENT_SUCCESS;
00809 }
00810 
00811 int
00812 statisticInfo::getUnsigned64(RMAttribute aName, unsigned long aID, u_int64_t & aValue)
00813 {
00814   aValue = 0;
00815 
00816   int ret;
00817   rmValue value;
00818   rmStatisticId statid;
00819 
00820   const StatisticInfo * info = getConstElement(aID);
00821   if(!info)
00822     return RMCLIENT_ERROR_STATISTIC_INFO;
00823 
00824   switch(aName) {
00825 
00826     case STATISTICINFO_COUNTERRESETVALUE64:
00827       aValue = info->counterValue.rmValueU64;
00828       break;
00829 
00830     case STATISTICINFO_GAUGEUPPERBOUND64:
00831       statid.ResourceId = info->resourceId;
00832       statid.StatisticId = info->info.id;
00833 
00834       uuid_clear(statid.SubsystemId);
00835       ret = mSubsystemInfo->getUUID(SUBSYSTEMINFO_UUID, info->subsystemId, statid.SubsystemId);
00836       if(ret)
00837         return RMCLIENT_ERROR_SUBSYSTEM_UUID;
00838 
00839       ret = ResourceMonitor::rmGetUpperBound(statid, &value);
00840       if(ret)
00841         return RMCLIENT_ERROR_STATISTIC_UPPERBOUND;
00842 
00843       aValue = value.rmValueU64;
00844       break;
00845 
00846     default:
00847       return RMCLIENT_ERROR_NOSUCHNAME;
00848   }
00849 
00850   return RMCLIENT_SUCCESS;
00851 }
00852   
00853 int
00854 statisticInfo::getString(RMAttribute aName, unsigned long aID, char * & aBuf)
00855 {
00856   aBuf = NULL;
00857 
00858   unsigned long len;
00859   char * str;
00860 
00861   const StatisticInfo * info = getConstElement(aID);
00862   if(!info)
00863     return RMCLIENT_ERROR_STATISTIC_INFO;
00864 
00865   switch(aName) {
00866 
00867     case STATISTICINFO_NAME:
00868       str = ResourceMonitor::rmGetStatisticDescription(info->info.SubsystemId,
00869                               info->info.id, rmShortDescription);
00870       break;
00871 
00872     case STATISTICINFO_DESCRIPTION:
00873       str = ResourceMonitor::rmGetStatisticDescription(info->info.SubsystemId,
00874                               info->info.id, rmLongDescription);
00875       break;
00876 
00877     case STATISTICINFO_UNITS:
00878       str = ResourceMonitor::rmGetStatisticDescription(info->info.SubsystemId,
00879                               info->info.id, rmUnitsDescription);
00880       break;
00881 
00882     default:
00883       return RMCLIENT_ERROR_NOSUCHNAME;
00884   }
00885 
00886   if(!str)
00887     return RMCLIENT_ERROR_STATISTIC_STRING;
00888 
00889   aBuf = str;
00890 
00891   return RMCLIENT_SUCCESS;
00892 }
00893 
00894 int
00895 dataCaptureInfo::init()
00896 {
00897   mElementArray.clear();
00898 
00899   int ret;
00900   FILE * rmtab;
00901   char * cfile = "/etc/opt/resourcemon/rmtab";
00902   char buf[1024];
00903 
00904   string str, uuidstr, name;
00905   string::size_type idx;
00906   unsigned long id;
00907   rmUID uuid;
00908 
00909   DataCaptureInfo info;
00910   DataCaptureInfo * pinfo;
00911 
00912   if ((rmtab = fopen(cfile, "r")) == NULL) {
00913     return RMCLIENT_ERROR_DATACAPTURE_PLUGIN_FILE;
00914   }
00915 
00916   while (fgets(buf, 1024, rmtab)){
00917     str = buf;
00918 
00919     idx = str.find_first_of(" \t\f\r\v");
00920     uuidstr = str.substr(0, idx);
00921 
00922     idx = str.find_last_of(" \t\f\r\v");
00923     name = str.substr(idx+1);
00924 
00925     idx = name.find('\n');
00926     if(idx != string::npos)
00927       name = name.substr(0, idx);
00928 
00929     // fprintf(stdout, "uuid = %s, size = %d, name = %s, size = %d\n", uuidstr.c_str(), uuidstr.size(), name.c_str(), name.size());
00930     uuid_parse((char *)uuidstr.c_str(), uuid);
00931     id = mSubsystemInfo->getSubsystemIDByUUID(uuid);
00932     if(id)
00933       continue; // this is a subsystem, not a plugin.
00934 
00935     info.uuid = uuid;
00936     ret = newElement(info, id);
00937     if(ret)
00938       return ret;
00939     
00940     pinfo = getElement(id);
00941     pinfo->name = name;
00942   }
00943 
00944   fclose(rmtab);
00945 
00946   return RMCLIENT_SUCCESS;
00947 }
00948 
00949 int
00950 dataCaptureInfo::getUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00951 {
00952   if(aUUIDStr == NULL)
00953     return RMCLIENT_ERROR_BAD_POINTER;
00954 
00955   aUUIDStr[0] = '\0';
00956 
00957   const DataCaptureInfo * info = getConstElement(aID);
00958   if(!info)
00959     return RMCLIENT_ERROR_DATACAPTURE_PLUGIN;
00960 
00961   switch(aName) {
00962     case DATACAPTUREPLUGININFO_UUID:
00963       uuid_unparse((unsigned char*)info->uuid, aUUIDStr);
00964       break;
00965 
00966     default:
00967       return  RMCLIENT_ERROR_NOSUCHNAME;
00968   }
00969 
00970   aUUIDStr[UUID_STRING_LENGTH - 1] = '\0';
00971   return RMCLIENT_SUCCESS;
00972 }
00973 
00974 int
00975 dataCaptureInfo::getString(RMAttribute aName, unsigned long aID, char * & aBuf)
00976 {
00977   aBuf = NULL;
00978 
00979   unsigned long len;
00980   char * str(NULL);
00981 
00982   const DataCaptureInfo * info = getConstElement(aID);
00983   if(!info)
00984     return RMCLIENT_ERROR_DATACAPTURE_PLUGIN;
00985 
00986   switch(aName) {
00987 
00988     case DATACAPTUREPLUGININFO_NAME:
00989       len = info->name.size() + 1;
00990 
00991       if(!info->name.empty()) {
00992         str = (char *) malloc(sizeof(char) * len);
00993         if(!str)
00994           return RMCLIENT_ERROR_MEMORY;
00995 
00996         strncpy(str, info->name.c_str(), len);
00997       }
00998 
00999       break;
01000 
01001     default:
01002       return RMCLIENT_ERROR_NOSUCHNAME;
01003   }
01004 
01005   aBuf = str;
01006 
01007   return RMCLIENT_SUCCESS;
01008 }
01009 
01010 unsigned long 
01011 dataCaptureInfo::getIDByUUID(const rmUID aUUID)
01012 {
01013   int ret;
01014 
01015   unsigned long id, nid;
01016   const DataCaptureInfo * info;
01017 
01018   id = 0; nid = 0;
01019 
01020   while(!getNextId(id, nid)) {
01021     id = nid;
01022 
01023     info = getConstElement(id);
01024 
01025     ret = uuid_compare((unsigned char *) aUUID, (unsigned char *)info->uuid);
01026     if(!ret) {
01027       return id;
01028     }
01029   }
01030 
01031   return 0;
01032 }
01033 

Generated on Tue Sep 10 16:46:33 2002 for ResourceMonitorSNMPSubagent by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002