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

rmControl.cpp

Go to the documentation of this file.
00001 #include "rmControl.h"
00002 #include "rmClientError.h"
00003 
00004 // #include "stdio.h"
00005 
00018 int
00019 rmGenericMonitorControl::removeElement(unsigned long aID)
00020 {
00021   int ret;
00022   ret = findId(aID);
00023   if(ret)
00024     return ret;
00025 
00026   int tid = mElementArray[aID].thresholdControlId;
00027   int lid = mElementArray[aID].leakyBucketControlId;
00028 
00029   ret = rmRefArray<GenericControl>::removeElement(aID);
00030   if(ret) {
00031     return ret;
00032   }
00033 
00034   if(tid > 0) {
00035     mThresholdControl->release(tid);
00036   }
00037   if(lid > 0) {
00038     mLeakyBucketControl->release(lid);
00039   }
00040 
00041 
00042   return RMCLIENT_SUCCESS;
00043 }
00044 
00045 bool
00046 rmGenericMonitorControl::elementIsReady(const GenericControl & aElement) const
00047 {
00048   if(aElement.control.monitorType < rmThresholding || aElement.control.monitorType > rmLeakyBucket) 
00049     return false;
00050 
00051   if(aElement.control.location < rmInLine || aElement.control.location > rmInLineDaemon)
00052     return false;
00053 
00054   /*
00055   if(aElement.control.monitoringInterval == 0)
00056     return false;
00057   */
00058 
00059   if(aElement.control.monitoringRate == 0 && aElement.control.microMonitoringRate == 0)
00060     return false;
00061 
00062   if(aElement.control.monitorType == rmThresholding && 
00063       aElement.thresholdControlId == 0)
00064     return false;
00065 
00066   if(aElement.control.monitorType == rmLeakyBucket && 
00067       aElement.leakyBucketControlId == 0)
00068     return false;
00069 
00070   return true;
00071 }
00072 
00073 int
00074 rmGenericMonitorControl::getInteger32(RMAttribute aName, unsigned long aID, long & aValue)
00075 {
00076   aValue = -1;
00077   const GenericControl * control = getConstElement(aID);
00078   if(!control)
00079     return RMCLIENT_ERROR_GENERIC_CONTROL;
00080 
00081   switch(aName) {
00082 
00083     case GENERICCONTROL_MONITORTYPE:
00084       aValue = control->control.monitorType;
00085       break;
00086 
00087     case GENERICCONTROL_MONITORLOCATION:
00088       aValue = control->control.location;
00089       break;
00090 
00091     case GENERICCONTROL_REFCOUNT:
00092       aValue = control->refCnt;
00093       break;
00094 
00095     case GENERICCONTROL_STATUS:
00096       aValue = control->status;
00097       break;
00098 
00099     default:
00100       return RMCLIENT_ERROR_NOSUCHNAME;
00101   }
00102 
00103   return RMCLIENT_SUCCESS;
00104 }
00105 
00106 int
00107 rmGenericMonitorControl::setInteger32(RMAttribute aName, unsigned long aID, long aValue)
00108 {
00109   GenericControl * control = getElement(aID);
00110   if(!control)
00111     return RMCLIENT_ERROR_GENERIC_CONTROL;
00112 
00113   if(control->refCnt > 0)
00114     return RMCLIENT_ERROR_CC_REFCNT;
00115 
00116   switch(aName) {
00117 
00118     case GENERICCONTROL_MONITORTYPE:
00119       if(aValue < rmThresholding || aValue > rmLeakyBucket)
00120         return RMCLIENT_ERROR_NOSUCHVALUE;
00121 
00122       control->control.monitorType = (enum rmMonitorType) aValue;
00123       break;
00124 
00125     case GENERICCONTROL_MONITORLOCATION:
00126       if(aValue < rmInLine || aValue > rmInLineDaemon)
00127         return RMCLIENT_ERROR_NOSUCHVALUE;
00128 
00129       control->control.location = (enum rmMonitorLocation) aValue;
00130       break;
00131 
00132     case GENERICCONTROL_STATUS:
00133       return setStatus(*control, aID, aValue);
00134 
00135     default:
00136       return RMCLIENT_ERROR_NOSUCHNAME;
00137   }
00138 
00139   updateStatus(*control);
00140   return RMCLIENT_SUCCESS;
00141 }
00142 
00143 int
00144 rmGenericMonitorControl::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00145 {
00146   aValue = 0;
00147   const GenericControl * control = getConstElement(aID);
00148   if(!control)
00149     return RMCLIENT_ERROR_GENERIC_CONTROL;
00150 
00151   switch(aName) {
00152 
00153     case GENERICCONTROL_MONITORLIFE:
00154       aValue = control->control.monitoringInterval;
00155       break;
00156 
00157     case GENERICCONTROL_MONITORRATE:
00158       aValue = control->control.monitoringRate;
00159       break;
00160 
00161     case GENERICCONTROL_MONITORMICRORATE:
00162       aValue = control->control.microMonitoringRate;
00163       break;
00164 
00165     case GENERICCONTROL_THRESHOLDID:
00166       aValue = control->thresholdControlId;
00167       break;
00168 
00169     case GENERICCONTROL_LEAKYBUCKETID:
00170       aValue = control->leakyBucketControlId;
00171       break;
00172 
00173     default:
00174       return RMCLIENT_ERROR_NOSUCHNAME;
00175   }
00176 
00177   return RMCLIENT_SUCCESS;
00178 }
00179 
00180 int
00181 rmGenericMonitorControl::setUnsigned(RMAttribute aName, unsigned long aID, unsigned long aValue)
00182 {
00183   int ret;
00184 
00185   GenericControl * control = getElement(aID);
00186   if(!control)
00187     return RMCLIENT_ERROR_GENERIC_CONTROL;
00188 
00189   if(control->refCnt > 0)
00190     return RMCLIENT_ERROR_CC_REFCNT;
00191 
00192   ThresholdControl * tcontrol;
00193   LeakyBucketControl * lcontrol;
00194 
00195   switch(aName) {
00196 
00197     case GENERICCONTROL_MONITORLIFE:
00198       control->control.monitoringInterval = aValue;
00199       break;
00200 
00201     case GENERICCONTROL_MONITORRATE:
00202       control->control.monitoringRate = aValue;
00203       break;
00204 
00205     case GENERICCONTROL_MONITORMICRORATE:
00206       control->control.microMonitoringRate = aValue;
00207       break;
00208 
00209     case GENERICCONTROL_THRESHOLDID:
00210       // release the old id
00211       mThresholdControl->release(control->thresholdControlId);
00212 
00213       if(aValue > 0) {
00214 
00215         // validate the new
00216         tcontrol = mThresholdControl->getElement(aValue);
00217         if(!tcontrol || tcontrol->status != ACTIVE)
00218           return RMCLIENT_ERROR_NOSUCHVALUE;
00219 
00220         control->control.typeControl.threshold = tcontrol->control;
00221 
00222         // addref the new
00223         ret = mThresholdControl->addRef(aValue);
00224         if(ret <0)
00225           return RMCLIENT_ERROR_CC_REFCNT;
00226       }
00227       else {
00228         memset(&(control->control.typeControl.threshold), 0, 
00229             sizeof(rmThresholdControl));
00230       }
00231       
00232       control->thresholdControlId = aValue;
00233       break;
00234 
00235     case GENERICCONTROL_LEAKYBUCKETID:
00236       // release the old id
00237       mLeakyBucketControl->release(control->leakyBucketControlId);
00238 
00239       if(aValue > 0) {
00240 
00241         // validate the new
00242         lcontrol = mLeakyBucketControl->getElement(aValue);
00243         if(!lcontrol || lcontrol->status != ACTIVE)
00244           return RMCLIENT_ERROR_NOSUCHVALUE;
00245 
00246         control->control.typeControl.leakyBucket = lcontrol->control;
00247 
00248         // addref the new
00249         ret = mLeakyBucketControl->addRef(aValue);
00250         if(ret <0)
00251           return RMCLIENT_ERROR_CC_REFCNT;
00252       }
00253       else {
00254         memset(&(control->control.typeControl.leakyBucket), 0, 
00255             sizeof(rmLeakyBucketControl));
00256       }
00257       
00258       control->leakyBucketControlId = aValue;
00259       break;
00260 
00261     default:
00262       return RMCLIENT_ERROR_NOSUCHNAME;
00263   }
00264 
00265   updateStatus(*control);
00266   return RMCLIENT_SUCCESS;
00267 }
00268 
00269 int
00270 rmGenericMonitorControl::getUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00271 {
00272   if(aUUIDStr == NULL)
00273     return RMCLIENT_ERROR_BAD_POINTER;
00274 
00275   aUUIDStr[0] = '\0';
00276 
00277   const GenericControl * control = getConstElement(aID);
00278   if(!control)
00279     return RMCLIENT_ERROR_GENERIC_CONTROL;
00280 
00281   switch(aName) {
00282 
00283     case GENERICCONTROL_MONITORUUID:
00284       uuid_unparse((unsigned char*)control->control.uid, aUUIDStr);
00285       break;
00286 
00287     case GENERICCONTROL_DATACAPTURE:
00288       uuid_unparse((unsigned char*)control->control.dataCapture, aUUIDStr);
00289       break;
00290 
00291     default:
00292       return RMCLIENT_ERROR_NOSUCHNAME;
00293   }
00294 
00295   aUUIDStr[UUID_STRING_LENGTH - 1] = '\0';
00296   return RMCLIENT_SUCCESS;
00297 }
00298 
00299 int
00300 rmGenericMonitorControl::setUUIDString(RMAttribute aName, unsigned long aID, char * aUUIDStr)
00301 {
00302   if(aUUIDStr == NULL)
00303     return RMCLIENT_ERROR_BAD_POINTER;
00304 
00305   int ret;
00306   uuid_t uuid;
00307 
00308   GenericControl * control = getElement(aID);
00309   if(!control)
00310     return RMCLIENT_ERROR_GENERIC_CONTROL;
00311 
00312   if(control->refCnt > 0)
00313     return RMCLIENT_ERROR_CC_REFCNT;
00314 
00315   uuid_clear(uuid);
00316   ret = uuid_parse(aUUIDStr, uuid);
00317   if(ret)
00318     return RMCLIENT_ERROR_NOSUCHVALUE;
00319 
00320   switch(aName) {
00321 
00322     case GENERICCONTROL_MONITORUUID:
00323       control->control.uid = uuid;
00324       break;
00325 
00326     case GENERICCONTROL_DATACAPTURE:
00327       control->control.dataCapture = uuid;
00328       break;
00329 
00330     default:
00331       return RMCLIENT_ERROR_NOSUCHNAME;
00332   }
00333 
00334   updateStatus(*control);
00335   return RMCLIENT_SUCCESS;
00336 }
00337 
00338 int
00339 rmGenericMonitorControl::getUUID(RMAttribute aName, unsigned long aID, uuid_t aUUID)
00340 {
00341   if(aUUID == NULL)
00342     return RMCLIENT_ERROR_BAD_POINTER;
00343 
00344   uuid_clear(aUUID);
00345 
00346   const GenericControl * control = getConstElement(aID);
00347   if(!control)
00348     return RMCLIENT_ERROR_GENERIC_CONTROL;
00349 
00350   switch(aName) {
00351 
00352     case GENERICCONTROL_MONITORUUID:
00353       uuid_copy(aUUID, (unsigned char*)control->control.uid);
00354       break;
00355 
00356     case GENERICCONTROL_DATACAPTURE:
00357       uuid_copy(aUUID, (unsigned char*)control->control.dataCapture);
00358       break;
00359 
00360     default:
00361       return RMCLIENT_ERROR_NOSUCHNAME;
00362   }
00363 
00364   return RMCLIENT_SUCCESS;
00365 }
00366 
00367 long
00368 rmGenericMonitorControl::addRef(unsigned long aID)
00369 {
00370   int ret;
00371   map<unsigned long, GenericControl>::iterator pos;
00372 
00373   ret = findId(aID, &pos);
00374   if(ret)
00375     return -1;
00376 
00377   // genericControl can only be addrefed once.
00378   if(pos->second.refCnt > 0)
00379     return -1;
00380 
00381   if(pos->second.status != ACTIVE)
00382     return -1;
00383 
00384   return ++(pos->second.refCnt);
00385 }
00386 
00387 bool
00388 rmThresholdMonitorControl::elementIsReady(const ThresholdControl & aElement) const
00389 {
00390   /*
00391   if(aElement.control.tolerance.rmValue32 == 0)
00392     return false;
00393 
00394   if(aElement.control.samples == 0)
00395     return false;
00396 
00397   if(aElement.control.loggingRate == 0)
00398     return false;
00399   */
00400 
00401   return true;
00402 }
00403 
00404 int
00405 rmThresholdMonitorControl::getInteger32(RMAttribute aName, unsigned long aID, long & aValue)
00406 {
00407   aValue = -1;
00408   const ThresholdControl * control = getConstElement(aID);
00409   if(!control)
00410     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00411 
00412   switch(aName) {
00413 
00414     case THRESHOLDCONTROL_REFCOUNT:
00415       aValue = control->refCnt;
00416       break;
00417 
00418     case THRESHOLDCONTROL_STATUS:
00419       aValue = control->status;
00420       break;
00421 
00422     default:
00423       return RMCLIENT_ERROR_NOSUCHNAME;
00424   }
00425 
00426   return RMCLIENT_SUCCESS;
00427 }
00428 
00429 int
00430 rmThresholdMonitorControl::setInteger32(RMAttribute aName, unsigned long aID, long aValue)
00431 {
00432   ThresholdControl * control = getElement(aID);
00433   if(!control)
00434     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00435 
00436   if(control->refCnt > 0)
00437     return RMCLIENT_ERROR_CC_REFCNT;
00438 
00439   switch(aName) {
00440 
00441     case THRESHOLDCONTROL_STATUS:
00442       updateStatus(*control);
00443       return setStatus(*control, aID, aValue);
00444 
00445     default:
00446       return RMCLIENT_ERROR_NOSUCHNAME;
00447   }
00448 
00449   updateStatus(*control);
00450   return RMCLIENT_SUCCESS;
00451 }
00452 
00453 int
00454 rmThresholdMonitorControl::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00455 {
00456   aValue = 0;
00457   const ThresholdControl * control = getConstElement(aID);
00458   if(!control)
00459     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00460 
00461   switch(aName) {
00462 
00463     case THRESHOLDCONTROL_TOLERANCE32:
00464       aValue = control->control.tolerance.rmValueU32;
00465       break;
00466 
00467     case THRESHOLDCONTROL_SAMPLETIME:
00468       aValue = control->control.samples;
00469       break;
00470 
00471     case THRESHOLDCONTROL_LOGRATE:
00472       aValue = control->control.loggingRate;
00473       break;
00474 
00475     default:
00476       return RMCLIENT_ERROR_NOSUCHNAME;
00477   }
00478 
00479   return RMCLIENT_SUCCESS;
00480 }
00481 
00482 int
00483 rmThresholdMonitorControl::setUnsigned(RMAttribute aName, unsigned long aID, unsigned long aValue)
00484 {
00485   ThresholdControl * control = getElement(aID);
00486   if(!control)
00487     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00488 
00489   if(control->refCnt > 0)
00490     return RMCLIENT_ERROR_CC_REFCNT;
00491 
00492   switch(aName) {
00493 
00494     case THRESHOLDCONTROL_TOLERANCE32:
00495       control->control.tolerance.rmValueU32 = aValue;
00496       break;
00497 
00498     case THRESHOLDCONTROL_SAMPLETIME:
00499       control->control.samples = aValue;
00500       break;
00501 
00502     case THRESHOLDCONTROL_LOGRATE:
00503       control->control.loggingRate = aValue;
00504       break;
00505 
00506     default:
00507       return RMCLIENT_ERROR_NOSUCHNAME;
00508   }
00509 
00510   updateStatus(*control);
00511   return RMCLIENT_SUCCESS;
00512 }
00513 
00514 int
00515 rmThresholdMonitorControl::getUnsigned64(RMAttribute aName, unsigned long aID, u_int64_t & aValue)
00516 {
00517   aValue = 0;
00518   const ThresholdControl * control = getConstElement(aID);
00519   if(!control)
00520     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00521 
00522   switch(aName) {
00523 
00524     case THRESHOLDCONTROL_TOLERANCE64:
00525       aValue = control->control.tolerance.rmValueU64;
00526       break;
00527 
00528     default:
00529       return RMCLIENT_ERROR_NOSUCHNAME;
00530   }
00531 
00532   return RMCLIENT_SUCCESS;
00533 }
00534 
00535 int
00536 rmThresholdMonitorControl::setUnsigned64(RMAttribute aName, unsigned long aID, u_int64_t aValue)
00537 {
00538   ThresholdControl * control = getElement(aID);
00539   if(!control)
00540     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00541 
00542   if(control->refCnt > 0)
00543     return RMCLIENT_ERROR_CC_REFCNT;
00544 
00545   switch(aName) {
00546 
00547     case THRESHOLDCONTROL_TOLERANCE64:
00548       control->control.tolerance.rmValueU64 = aValue;
00549       break;
00550 
00551     default:
00552       return RMCLIENT_ERROR_NOSUCHNAME;
00553   }
00554 
00555   updateStatus(*control);
00556   return RMCLIENT_SUCCESS;
00557 }
00558 
00559 bool
00560 rmLeakyBucketMonitorControl::elementIsReady(const LeakyBucketControl & aElement) const
00561 {
00562   return true;
00563 }
00564 
00565 int
00566 rmLeakyBucketMonitorControl::getInteger32(RMAttribute aName, unsigned long aID, long & aValue)
00567 {
00568   aValue = -1;
00569   const LeakyBucketControl * control = getConstElement(aID);
00570   if(!control)
00571     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00572 
00573   switch(aName) {
00574 
00575     case LEAKYBUCKETCONTROL_REFCOUNT:
00576       aValue = control->refCnt;
00577       break;
00578 
00579     case LEAKYBUCKETCONTROL_STATUS:
00580       aValue = control->status;
00581       break;
00582 
00583     default:
00584       return RMCLIENT_ERROR_NOSUCHNAME;
00585   }
00586 
00587   return RMCLIENT_SUCCESS;
00588 }
00589 
00590 int
00591 rmLeakyBucketMonitorControl::setInteger32(RMAttribute aName, unsigned long aID, long aValue)
00592 {
00593   LeakyBucketControl * control = getElement(aID);
00594   if(!control)
00595     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00596 
00597   if(control->refCnt > 0)
00598     return RMCLIENT_ERROR_CC_REFCNT;
00599 
00600   switch(aName) {
00601 
00602     case LEAKYBUCKETCONTROL_STATUS:
00603       updateStatus(*control);
00604       return setStatus(*control, aID, aValue);
00605 
00606     default:
00607       return RMCLIENT_ERROR_NOSUCHNAME;
00608   }
00609 
00610   updateStatus(*control);
00611   return RMCLIENT_SUCCESS;
00612 }
00613 
00614 int
00615 rmLeakyBucketMonitorControl::getUnsigned(RMAttribute aName, unsigned long aID, unsigned long & aValue)
00616 {
00617   aValue = 0;
00618   const LeakyBucketControl * control = getConstElement(aID);
00619   if(!control)
00620     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00621 
00622   switch(aName) {
00623 
00624     case LEAKYBUCKETCONTROL_LOGGINGRATE:
00625       aValue = control->control.loggingRate;
00626       break;
00627 
00628     default:
00629       return RMCLIENT_ERROR_NOSUCHNAME;
00630   }
00631 
00632   return RMCLIENT_SUCCESS;
00633 }
00634 
00635 int
00636 rmLeakyBucketMonitorControl::setUnsigned(RMAttribute aName, unsigned long aID, unsigned long aValue)
00637 {
00638   LeakyBucketControl * control = getElement(aID);
00639   if(!control)
00640     return RMCLIENT_ERROR_THRESHOLD_CONTROL;
00641 
00642   if(control->refCnt > 0)
00643     return RMCLIENT_ERROR_CC_REFCNT;
00644 
00645   switch(aName) {
00646 
00647     case LEAKYBUCKETCONTROL_LOGGINGRATE:
00648       control->control.loggingRate = aValue;
00649       break;
00650 
00651     default:
00652       return RMCLIENT_ERROR_NOSUCHNAME;
00653   }
00654 
00655   updateStatus(*control);
00656   return RMCLIENT_SUCCESS;
00657 }
00658 
00659 
00660 

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