00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00079
00080
00081 Entry e(arg, ACTIVE);
00082 e.setApp(app);
00083 agents[e.getId()] = e;
00084
00085
00086
00087
00088
00089 }
00090
00091 void RegistryAgent::handlePrintRequest(MicoleBus *app, int argc, const char **argv)
00092 {
00093
00094
00095
00096
00097
00098
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 }