00001 /* 00002 * This file is part of Micole Architecture 00003 * 00004 * Copyright (C) 2007 Micole partners 00005 * 00006 * Micole Architecture is free software: you can redistribute it 00007 * and/or modify it under the terms of the GNU Lesser General 00008 * Public License as published by the Free Software Foundation, 00009 * either version 3 of the License, or (at your option) any 00010 * later version. 00011 * 00012 * Micole Architecture is distributed in the hope that it will be 00013 * useful, * but WITHOUT ANY WARRANTY; without even the implied 00014 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 * PURPOSE. See the GNU Lesser General Public License for more 00016 * details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Micole Architecture. If not, see 00020 * <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 #include "stdafx.h" 00024 #include "MicoleAgentThread.h" 00025 //#include "agentmodule.h" 00026 00027 using namespace AgentModuleConstants; 00028 00029 MicoleAgentThread::MicoleAgentThread(const string &name, const string &type, const char * domain) 00030 : MicoleAgent(name,type,domain) 00031 { 00032 /* 00033 int count = bindMessage(QUIT, BUS_CALLBACK_OF(MicoleAgentThread, &MicoleAgentThread::handleQuitMessage)); 00034 count = bindMessage(SUSPEND, BUS_CALLBACK_OF(MicoleAgentThread, &MicoleAgentThread::handleSuspendMessage)); 00035 count = bindMessage(RESUME, BUS_CALLBACK_OF(MicoleAgentThread, &MicoleAgentThread::handleResumeMessage)); 00036 */ 00037 } 00038 00039 AgentState MicoleAgentThread::getState() 00040 { 00041 return state; 00042 } 00043 00044 MicoleAgentThread::~MicoleAgentThread() 00045 { 00046 cout<<"Terminating MicoleAgentThread..."<<endl; 00047 } 00048 00049 /* 00050 void MicoleAgentThread::handleQuitMessage(MicoleBus *app, int argc, const char **argv ){ 00051 prepareToStop(argc,argv); 00052 state = UNKNOWN; 00053 //terminate(); 00054 } 00055 */ 00056 void MicoleAgentThread::start() 00057 { 00058 state = ACTIVE; 00059 Thread::start(); 00060 } 00061 00062 /* 00063 void MicoleAgentThread::handleSuspendMessage(MicoleBus *app, int argc, const char **argv ){ 00064 state = SUSPENDED; 00065 prepareToSuspend(argc,argv); 00066 this->suspend(); 00067 00068 00069 } 00070 00071 void MicoleAgentThread::handleResumeMessage(MicoleBus *app, int argc, const char **argv ){ 00072 state = ACTIVE; 00073 this->resume(); 00074 00075 00076 }*/ 00077 void MicoleAgentThread::suspendAgent() 00078 { 00079 /* cout<<"Suspending MicoleAgentThread"<<endl; 00080 for (unsigned i = 0 ; i < bindings.size() ; ++i) 00081 unBindMessage(bindings[i]); 00082 00083 resumeId = bus->bindMsg("^Resume$",BUS_CALLBACK_OF(MicoleAgent, handleResumeMessage ));*/ 00084 // this->suspend(); 00085 //bindings.erase(bindings.begin(),bindings.end()); 00086 } 00087 00088 void MicoleAgentThread::resumeAgent() 00089 { 00090 /* 00091 -re-bind the agen's messages 00092 -unbind resume handler 00093 -resume thread 00094 */ 00095 /* for (unsigned i = 0 ; i < bindings.size() ; ++i) 00096 bindMessage( bindings[i]); 00097 00098 bus->UnbindMsg(resumeId); 00099 this->resume();*/ 00100 } 00101 00102 void MicoleAgentThread::stopAgent() 00103 { 00104 //prepareToStop(argc,argv); 00105 // this->terminate(); 00106 }