Scopira 20080306

agent.h

00001 
00002 /*
00003  *  Copyright (c) 2005-2007    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_AGENT_AGENT_H__
00015 #define __INCLUDED_SCOPIRA_AGENT_AGENT_H__
00016 
00017 #include <scopira/basekit/narray.h>
00018 #include <scopira/tool/object.h>
00019 #include <scopira/tool/uuid.h>
00020 #include <scopira/tool/bufferflow.h>
00021 #include <scopira/tool/export.h>
00022 #include <scopira/agent/task.h>
00023 
00024 namespace scopira
00025 {
00026   namespace agent
00027   {
00028     class uuid_query;
00029     class agenterror_reactor_i;
00030     class taskmsg_reactor_i;
00031     class agent_i;
00032   }
00033 }
00034 
00047 class scopira::agent::uuid_query
00048 {
00049   public:
00057     SCOPIRA_EXPORT uuid_query(void);
00065     SCOPIRA_EXPORT explicit uuid_query(scopira::tool::uuid simplecase);
00066 
00071     SCOPIRA_EXPORT bool query(scopira::tool::uuid testid) const;
00072 
00073     //
00074     // The expression building operations.
00075     //
00076 
00082     SCOPIRA_EXPORT uuid_query & match_any(void);
00089     SCOPIRA_EXPORT uuid_query & match_one(scopira::tool::uuid id);
00096     SCOPIRA_EXPORT uuid_query & match_group(scopira::basekit::const_nslice<scopira::tool::uuid> ids);
00097 
00102     SCOPIRA_EXPORT uuid_query & op_and(void);
00107     SCOPIRA_EXPORT uuid_query & op_or(void);
00112     SCOPIRA_EXPORT uuid_query & op_xor(void);
00117     SCOPIRA_EXPORT uuid_query & op_not(void);
00118 
00119   private:
00120     scopira::tool::uuid dm_simpleuuid;
00121     // otherwise, this is the complex expression
00122     enum {
00123       match_any_c,    // this is basicaly a literal "true"
00124       match_one_c,   // + index
00125       match_group_c, // + index + size
00126       op_and_c,
00127       op_or_c,
00128       op_xor_c,
00129       op_not_c,
00130     };
00131     // the expression and its data
00132     std::vector<size_t> dm_exp;    // if this is empty, then use the simple case uuid
00133     std::vector<scopira::tool::uuid> dm_data;
00134 };
00135 
00140 class scopira::agent::agenterror_reactor_i
00141 {
00142   public:
00143     virtual ~agenterror_reactor_i() { }
00150     SCOPIRA_EXPORT virtual void react_agenterror(scopira::agent::agent_i *a) = 0;
00151 };
00152 
00158 class scopira::agent::taskmsg_reactor_i
00159 {
00160   public:
00161     virtual ~taskmsg_reactor_i() { }
00162 
00170     SCOPIRA_EXPORT virtual void react_taskmsg(scopira::agent::agent_i *a, scopira::tool::uuid srcid, scopira::tool::uuid destid) = 0;
00171 };
00172 
00177 class scopira::agent::agent_i : public scopira::tool::object
00178 {
00179   public:
00182     static agent_i * instance(void) { return dm_instance; }
00183 
00190     SCOPIRA_EXPORT static agent_i * new_agent(void);
00197     SCOPIRA_EXPORT static bool get_cluster_server_url(std::string &serverurl);
00198 
00200     SCOPIRA_EXPORT virtual ~agent_i();
00201 
00203     SCOPIRA_EXPORT virtual void notify_stop(void) = 0;
00206     SCOPIRA_EXPORT virtual void wait_stop(void) = 0;
00209     SCOPIRA_EXPORT virtual void enqueue_network_quit(void) = 0;
00210 
00213     SCOPIRA_EXPORT virtual bool failed(void) const = 0;
00214 
00216     SCOPIRA_EXPORT virtual void set_agenterror_reactor(agenterror_reactor_i *r) = 0;
00217 
00219     SCOPIRA_EXPORT virtual void reg_context(scopira::tool::uuid &ctxid, taskmsg_reactor_i *reac) = 0;
00221     SCOPIRA_EXPORT virtual void unreg_context(scopira::tool::uuid ctxid) = 0;
00222 
00223     SCOPIRA_EXPORT virtual int find_services(scopira::tool::uuid &serviceid, scopira::basekit::narray<scopira::tool::uuid> &out) = 0;
00224 
00225     SCOPIRA_EXPORT virtual int universe_size(void) = 0;
00226     SCOPIRA_EXPORT virtual scopira::tool::uuid get_agent_id(void) = 0;
00227 
00228     SCOPIRA_EXPORT virtual scopira::tool::uuid launch_task(const std::type_info &t, scopira::tool::uuid where) = 0;
00229     SCOPIRA_EXPORT virtual scopira::tool::uuid launch_group(int numps, const std::type_info &t) = 0;
00230     SCOPIRA_EXPORT virtual void launch_slaves(scopira::tool::uuid masterid, int numtotalps, const std::type_info &t,
00231       scopira::basekit::narray<scopira::tool::uuid> &peers) = 0;
00232     SCOPIRA_EXPORT virtual void kill_task(scopira::tool::uuid ps) = 0;
00233     SCOPIRA_EXPORT virtual bool wait_task(scopira::tool::uuid ps, int msec) = 0;
00234     SCOPIRA_EXPORT virtual bool is_alive_task(scopira::tool::uuid ps) = 0;    // only designed for checking the "this" class
00235     SCOPIRA_EXPORT virtual bool is_killed_task(scopira::tool::uuid ps) = 0;
00236 
00237     SCOPIRA_EXPORT virtual bool wait_msg(const uuid_query &srcq, scopira::tool::uuid &foundsrc,  scopira::tool::uuid dest, int timeout) = 0;
00238     SCOPIRA_EXPORT virtual void send_msg(scopira::tool::uuid src, scopira::tool::uuid dest, scopira::tool::bufferflow *buf) = 0;
00239     // service broadcast ONLY (will be removed eventually?)
00240     SCOPIRA_EXPORT virtual void send_msg_bcast(scopira::tool::uuid src, scopira::tool::uuid destserviceid, scopira::tool::bufferflow *buf) = 0;
00241     // src will be filled with the actual source, after
00242     SCOPIRA_EXPORT virtual void recv_msg(const uuid_query &srcq, scopira::tool::uuid &foundsrc, scopira::tool::uuid dest, scopira::tool::count_ptr<scopira::tool::bufferflow> &buf) = 0;
00243 
00244   protected:
00246     SCOPIRA_EXPORT agent_i(void);
00247 
00248   private:
00249     SCOPIRA_EXPORT static agent_i *dm_instance;
00250 };
00251 
00252 #endif
00253