Scopira  20080306
agent.h
1 
2 /*
3  * Copyright (c) 2005-2007 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED_SCOPIRA_AGENT_AGENT_H__
15 #define __INCLUDED_SCOPIRA_AGENT_AGENT_H__
16 
17 #include <typeinfo>
18 
19 #include <scopira/basekit/narray.h>
20 #include <scopira/tool/object.h>
21 #include <scopira/tool/uuid.h>
22 #include <scopira/tool/bufferflow.h>
23 #include <scopira/tool/export.h>
24 #include <scopira/agent/task.h>
25 
26 namespace scopira
27 {
28  namespace agent
29  {
30  class uuid_query;
32  class taskmsg_reactor_i;
33  class agent_i;
34  }
35 }
36 
50 {
51  public:
59  SCOPIRA_EXPORT uuid_query(void);
67  SCOPIRA_EXPORT explicit uuid_query(scopira::tool::uuid simplecase);
68 
73  SCOPIRA_EXPORT bool query(scopira::tool::uuid testid) const;
74 
75  //
76  // The expression building operations.
77  //
78 
84  SCOPIRA_EXPORT uuid_query & match_any(void);
91  SCOPIRA_EXPORT uuid_query & match_one(scopira::tool::uuid id);
99 
104  SCOPIRA_EXPORT uuid_query & op_and(void);
109  SCOPIRA_EXPORT uuid_query & op_or(void);
114  SCOPIRA_EXPORT uuid_query & op_xor(void);
119  SCOPIRA_EXPORT uuid_query & op_not(void);
120 
121  private:
122  scopira::tool::uuid dm_simpleuuid;
123  // otherwise, this is the complex expression
124  enum {
125  match_any_c, // this is basicaly a literal "true"
126  match_one_c, // + index
127  match_group_c, // + index + size
128  op_and_c,
129  op_or_c,
130  op_xor_c,
131  op_not_c,
132  };
133  // the expression and its data
134  std::vector<size_t> dm_exp; // if this is empty, then use the simple case uuid
135  std::vector<scopira::tool::uuid> dm_data;
136 };
137 
143 {
144  public:
145  virtual ~agenterror_reactor_i() { }
152  SCOPIRA_EXPORT virtual void react_agenterror(scopira::agent::agent_i *a) = 0;
153 };
154 
161 {
162  public:
163  virtual ~taskmsg_reactor_i() { }
164 
172  SCOPIRA_EXPORT virtual void react_taskmsg(scopira::agent::agent_i *a, scopira::tool::uuid srcid, scopira::tool::uuid destid) = 0;
173 };
174 
180 {
181  public:
184  static agent_i * instance(void) { return dm_instance; }
185 
192  SCOPIRA_EXPORT static agent_i * new_agent(void);
199  SCOPIRA_EXPORT static bool get_cluster_server_url(std::string &serverurl);
200 
202  SCOPIRA_EXPORT virtual ~agent_i();
203 
205  SCOPIRA_EXPORT virtual void notify_stop(void) = 0;
208  SCOPIRA_EXPORT virtual void wait_stop(void) = 0;
211  SCOPIRA_EXPORT virtual void enqueue_network_quit(void) = 0;
212 
215  SCOPIRA_EXPORT virtual bool failed(void) const = 0;
216 
218  SCOPIRA_EXPORT virtual void set_agenterror_reactor(agenterror_reactor_i *r) = 0;
219 
221  SCOPIRA_EXPORT virtual void reg_context(scopira::tool::uuid &ctxid, taskmsg_reactor_i *reac) = 0;
223  SCOPIRA_EXPORT virtual void unreg_context(scopira::tool::uuid ctxid) = 0;
224 
225  SCOPIRA_EXPORT virtual int find_services(scopira::tool::uuid &serviceid, scopira::basekit::narray<scopira::tool::uuid> &out) = 0;
226 
227  SCOPIRA_EXPORT virtual int universe_size(void) = 0;
228  SCOPIRA_EXPORT virtual scopira::tool::uuid get_agent_id(void) = 0;
229 
230  SCOPIRA_EXPORT virtual scopira::tool::uuid launch_task(const std::type_info &t, scopira::tool::uuid where) = 0;
231  SCOPIRA_EXPORT virtual scopira::tool::uuid launch_group(int numps, const std::type_info &t) = 0;
232  SCOPIRA_EXPORT virtual void launch_slaves(scopira::tool::uuid masterid, int numtotalps, const std::type_info &t,
234  SCOPIRA_EXPORT virtual void kill_task(scopira::tool::uuid ps) = 0;
235  SCOPIRA_EXPORT virtual bool wait_task(scopira::tool::uuid ps, int msec) = 0;
236  SCOPIRA_EXPORT virtual bool is_alive_task(scopira::tool::uuid ps) = 0; // only designed for checking the "this" class
237  SCOPIRA_EXPORT virtual bool is_killed_task(scopira::tool::uuid ps) = 0;
238 
239  SCOPIRA_EXPORT virtual bool wait_msg(const uuid_query &srcq, scopira::tool::uuid &foundsrc, scopira::tool::uuid dest, int timeout) = 0;
240  SCOPIRA_EXPORT virtual void send_msg(scopira::tool::uuid src, scopira::tool::uuid dest, scopira::tool::bufferflow *buf) = 0;
241  // service broadcast ONLY (will be removed eventually?)
242  SCOPIRA_EXPORT virtual void send_msg_bcast(scopira::tool::uuid src, scopira::tool::uuid destserviceid, scopira::tool::bufferflow *buf) = 0;
243  // src will be filled with the actual source, after
244  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;
245 
246  protected:
248  SCOPIRA_EXPORT agent_i(void);
249 
250  private:
251  SCOPIRA_EXPORT static agent_i *dm_instance;
252 };
253 
254 #endif
255 
uuid_query & match_any(void)
Definition: archiveflow.h:20
uuid_query & match_one(scopira::tool::uuid id)
Definition: bufferflow.h:40
Definition: object.h:71
static agent_i * instance(void)
Definition: agent.h:184
Definition: uuid.h:183
Definition: context.h:82
Definition: agent.h:160
uuid_query & match_group(scopira::basekit::const_nslice< scopira::tool::uuid > ids)
bool query(scopira::tool::uuid testid) const
Definition: agent.h:49
uuid_query & op_and(void)
Definition: agent.h:179
uuid_query & op_not(void)
uuid_query & op_or(void)
Definition: narray.h:101
Definition: context.h:132
uuid_query & op_xor(void)