MicoleAgent.h

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 #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 };//Agent states
00036 namespace AgentModuleConstants {
00037 
00038         //Message prefixes
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         //Direct message types. Types start from 100. 
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                 //MicoleBus *app is the sender of the message.
00087                 void handlePingMessage( MicoleBus *app, int argc, const char **argv);
00088                 void handleQuitMessage( MicoleBus *app, int argc, const char **argv);
00089                 /*      Suspends the MicoleAgent. Suspending means that its methods are unbound from
00090                         the Micole bus. Sending Suspend message using sendMessage
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                 //virtual void onDirectMessage( MicoleBus *app, int id, const char *arg );
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                 //Ivy* bus;
00158                 vector<MicoleBinding> bindings;
00159                 AgentState state;
00160                 int resumeId;
00161 
00162         private:
00163                 string agentName;
00164                 string agentType;
00165                 //int identifier;//the agent identifier, received on start-up from agent network...(not used yet)
00166                 string identifier;      
00167 };
00168  //end core
00170 
00171 #endif

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