00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "Agent.h"
00013
#include <OpenCAL/System.h>
00014
using namespace OpenCAL;
00015
00016
#include <OpenCAL/NullParentException.h>
00017
using Exceptions::NullParentException;
00018
00019
00020
00021
00022
00023
00024 Agent::Agent(
System *parent)
00025 : m_parent(parent), m_initialized(false), m_enabled(true)
00026 {
00027
#ifdef VERBOSE
00028
Debug::print(
"Agent constructor", 2);
00029
#endif // VERBOSE
00030
00031
if(!parent)
00032
throw NullParentException(__FILE__, __LINE__);
00033
00034
#ifdef VERBOSE
00035
Debug::print(
"Parent is given, adding to the the parent's agent list...", 2);
00036
#endif // VERBOSE
00037
00038 parent->
addAgent(
this);
00039 }
00040
00041 Agent::~Agent()
00042 {
00043
#ifdef VERBOSE
00044
Debug::print(
"Agent destructor", 2);
00045
#endif // VERBOSE
00046
00047 m_parent->
deleteAgent(
this);
00048 }
00049
00050
00051
00052
00053
00054
00055
void Agent::initialize()
00056 {
00057
#ifdef VERBOSE
00058
Debug::print(
"Agent initialize", 2);
00059
#endif // VERBOSE
00060
00061 m_initialized =
true;
00062 }
00063
00064
void Agent::satisfy()
00065 {
00066
#ifdef VERBOSE
00067
Debug::print(
"Agent satisfy", Debug::maxLevel);
00068
#endif // VERBOSE
00069
00070
if(!isInitialized())
00071 {
00072
#ifdef VERBOSE
00073
Debug::initWarning(
"agent");
00074
#endif // VERBOSE
00075
initialize();
00076 }
00077 }