HostState.h

00001 /* -*- mode:c++ -*- ********************************************************
00002  * Energy Framework for Omnet++, version 0.9
00003  *
00004  * Author:  Laura Marie Feeney
00005  *
00006  * Copyright 2009 Swedish Institute of Computer Science.
00007  *
00008  * This software is provided `as is' and without any express or implied
00009  * warranties, including, but not limited to, the implied warranties of
00010  * merchantability and fitness for a particular purpose.
00011  *
00012  ***************************************************************************/
00013 
00014 #ifndef HOSTSTATE_H
00015 #define HOSTSTATE_H
00016 
00017 #include "ImNotifiable.h"
00018 
00034 class HostState : public BBItem
00035 {
00036     BBITEM_METAINFO(BBItem)
00037 
00038 public:
00042     enum States
00043         {
00044           ACTIVE, 
00045           FAILED, 
00047           BROKEN, 
00049           SLEEP,  
00050           OFF     
00051         };
00052     // we could make a nice 'info' field here, to allow us to specify
00053     // the cause of failure (e.g. battery, stochastic hardware failure)
00054 
00055 private:
00059     States state;
00060 
00061 public:
00065     HostState(States state = ACTIVE):
00066     state(state)
00067   {}
00068 
00070     States get() const { return state; }
00072     void set(States s) { state = s; }
00073 
00077     std::string info() const {
00078     std::ostringstream ost;
00079     switch(state) {
00080     case ACTIVE:
00081       ost << "ACTIVE";
00082       break;
00083     case FAILED:
00084       ost << "FAILED";
00085       break;
00086     case BROKEN:
00087       ost << "BROKEN";
00088       break;
00089     case SLEEP:
00090       ost << "SLEEP";
00091       break;
00092     case OFF:
00093       ost << "OFF";
00094       break;
00095     default:
00096       ost << "Unknown";
00097       break;
00098     }
00099     return ost.str();
00100   }
00101 };
00102 
00103 #endif