RegistryAgent.cpp

Go to the documentation of this file.
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 "registryagent.h"
00025 #include "Entry.h"
00026 
00027 #include "MicoleStringStream.h"
00028 
00029 
00030 using namespace AgentModuleConstants;
00031 
00032 RegistryAgent::RegistryAgent(const string &name, const string &domain)
00033 : MicoleAgent(name,"Registry","127.255.255.255:2010")
00034 {
00035         Entry e("Registry", ACTIVE);
00036         agents[e.getId()] = e;
00037         bindMessage("^Register:(.*)", BUS_CALLBACK_OF(RegistryAgent, handleRegisterMessage ));
00038         bindMessage("^Unregister:(.*)", BUS_CALLBACK_OF(RegistryAgent, handleUnRegisterMessage ));
00039         bindMessage("^PrintRegister$", BUS_CALLBACK_OF(RegistryAgent, handlePrintRequest ));
00040         
00041         bindMessage("^Set (.*) = (.*);$", BUS_CALLBACK_OF(RegistryAgent, handleSetVar ));
00042         bindMessage("^SET (.*) = (.*);$", BUS_CALLBACK_OF(RegistryAgent, handleSetVar ));
00043 
00044         bindMessage("^GET (.*);$", BUS_CALLBACK_OF(RegistryAgent, handleGetVar ));
00045 }
00046 
00047 RegistryAgent::~RegistryAgent()
00048 {
00049         cout << "RegistryAgent destructor" << endl;
00050 }
00051 
00052 
00053 void RegistryAgent::handleSetVar(MicoleBus *app, int argc, const char **argv) 
00054 {
00055         setVar(argv[0],argv[1]);
00056 }
00057 
00058 
00059 void RegistryAgent::handleGetVar(MicoleBus *app, int argc, const char **argv) 
00060 {
00061         MicoleStringStream mss;
00062         mss << "VAR " << string(argv[0]) << "=" << getVar(argv[0]); 
00063         sendMessage(mss.str());
00064 }
00065 
00066 
00067 void RegistryAgent::handleQuitMessage( MicoleBus *app, int argc, const char **argv)
00068 {
00069         cout << "registryAgent stopping..." << endl;
00070         agents.clear();
00071 }
00072 
00073 void RegistryAgent::handleRegisterMessage(MicoleBus *app, int argc, const char **argv)
00074 {
00075         cout << "HandleRegister..." << endl;
00076         
00077         const char* arg = (argc < 1) ? "" : argv[0];
00078         //ostringstream s;
00079 
00080         //string reply = "";
00081         Entry e(arg, ACTIVE);// = new Entry;
00082         e.setApp(app);
00083         agents[e.getId()] = e;
00084 
00085         //s<<e.id;
00086         //reply = string("RegisterReply:")+s.str();
00087         //reply = string("RegisterReply:")+string(e.id+0x30);
00088         //e.app->SendMsg(reply.data());
00089 }
00090 
00091 void RegistryAgent::handlePrintRequest(MicoleBus *app, int argc, const char **argv)
00092 {
00093         /*typedef map<int,Entry>::iterator i;
00094         Entry e;
00095         for (i p = agents.begin(); p!= agents.end(); ++p)
00096         {
00097                 e = p->second;
00098                 cout <<e.id<<'\t'<<e.name<<'\t'<<e.state<<'\n';
00099         }*/
00100         
00101         for (map<int,Entry>::iterator i = agents.begin() ; i != agents.end(); i++)
00102                 cout << (i->second).getId() << '\t' << (i->second).getName() << '\t' << (i->second).getState() << endl;
00103 }
00104 void RegistryAgent::handleUnRegisterMessage(MicoleBus *app, int argc, const char **argv)
00105 {
00106 }

Generated on Tue Oct 16 17:10:43 2007 for Micole by  doxygen 1.4.7