00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MicoleAgent_H
00024 #define MicoleAgent_H
00025 #include <micolelib.h>
00026
00027 #include <iostream>
00028 #include <string>
00029 #include <vector>
00030 using namespace std;
00031
00032 #include "Binding.h"
00033 #include "MicoleBus.h"
00034
00035 enum AgentState {ACTIVE, SUSPENDED, UNKNOWN, UNACTIVE };
00036 namespace AgentModuleConstants {
00037
00038
00039 const static char * PHANTOM = "^Phantom:(.*)";
00040 const static char * SOUND = "^Sound:(.*)";
00041 const static char * OUTPUT = "^Output:(.*)";
00042 const static char * PHANTOM_INPUT = "^Phantom_input:(*.)";
00043 const static char * MAGELLAN_INPUT = "^Magellan_input:(.*)";
00044 const static char * KEYBOARD_INPUT = "^Keyboard_input:(.*)";
00045
00046 const static char * QUIT = "^Quit$";
00047 const static char * PING = "^Ping$";
00048 const static char * SUSPEND = "^Suspend:(.*)";
00049 const static char * RESUME ="^Resume:(.*)";
00050
00051 const static char * LOCALHOST = "127.0.0.1";
00052 const static char * MULTICAST = "127.255.255.255";
00053
00054
00055
00056 const static int REGISTER_REPLY = 100;
00057 const static int SUSPEND_REQUEST = 101;
00058 }
00059
00060
00074 class MICOLELIB_API MicoleAgent
00075 {
00076 friend class SuspendMsgListener;
00077 friend class RegisterMsgListener;
00078
00079 public:
00080 virtual ~MicoleAgent();
00081 string getAgentName();
00082 string getAgentType();
00083 void onApplicationConnected( MicoleBus *app );
00084 void onApplicationDisconnected( MicoleBus *app );
00085
00086
00087 void handlePingMessage( MicoleBus *app, int argc, const char **argv);
00088 void handleQuitMessage( MicoleBus *app, int argc, const char **argv);
00089
00090
00091
00092 void handleSuspendMessage( MicoleBus *app, int argc, const char **argv);
00093 void handleResumeMessage( MicoleBus *app, int argc, const char **argv);
00094
00095 void handleRegisterReply( MicoleBus *app, int argc, const char **argv);
00096 void handleStartMessage( MicoleBus *app, int argc, const char **argv);
00097 void handlePrintIDMessage( MicoleBus *app, int argc, const char **argv);
00098
00099
00101 int sendMessage( const char *message);
00102
00104 int sendMessage( const string message);
00105
00111 void sendMessage(const char *to, const char *message);
00112
00113 protected:
00121 MicoleAgent(const string &name, const string &type, const char *domain = "127.255.255.255:2010");
00122
00130 int bindMessage(const char *regexp, MicoleCallback * cb);
00131 void unBindMessage(int messageId);
00132 void unBindMessage(MicoleBinding &binding);
00133
00138 virtual void suspendAgent();
00139
00143 virtual void resumeAgent();
00144
00149 virtual void stopAgent();
00150
00154 void obtainIdentifier();
00155
00156 static MicoleBus* bus;
00157
00158 vector<MicoleBinding> bindings;
00159 AgentState state;
00160 int resumeId;
00161
00162 private:
00163 string agentName;
00164 string agentType;
00165
00166 string identifier;
00167 };
00168
00170
00171 #endif