00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00085 #ifndef ACEDIA_H
00086 #define ACEDIA_H
00087
00088 #include "message.hpp"
00089 #include "actorref.hpp"
00090 #include "rulebuilder.hpp"
00091
00092 namespace acedia {
00093
00094
00095 namespace details { class AnyArrayProcessor; }
00096
00097 struct MatchAllRuleBuilder
00098 {
00099 details::AnyArrayProcessor* operator>>(void (*voidFunction)());
00100 details::AnyArrayProcessor* operator>>(const boost::function0<void> &f);
00101 };
00102
00103 class Actor;
00104
00110 void waitForAllActorsDone();
00111
00117 inline MatchAllRuleBuilder others() throw() { return MatchAllRuleBuilder(); }
00118
00122 template<typename T1>
00123 inline SingleRuleBuilder<T1> on()
00124 {
00125 return SingleRuleBuilder<T1>(new details::PatternChecker<1,T1>);
00126 }
00127
00128 template<typename T1, typename T2>
00129 inline RuleBuilder<2,0,T1,T2> on()
00130 {
00131 return RuleBuilder<2,0,T1,T2>(new details::PatternChecker<2,T1,T2>());
00132 }
00133
00134 template<typename T1, typename T2, typename T3>
00135 inline RuleBuilder<3,0,T1,T2,T3> on()
00136 {
00137 return RuleBuilder<3,0,T1,T2,T3>(new details::PatternChecker<3,T1,T2,T3>());
00138 }
00139
00140 template<typename T1, typename T2, typename T3, typename T4>
00141 inline RuleBuilder<4,0,T1,T2,T3,T4> on()
00142 {
00143 return RuleBuilder<4,0,T1,T2,T3,T4>(new details::PatternChecker<4,T1,T2,T3,T4>());
00144 }
00145
00150 template<typename T1, typename T2, typename T3, typename T4, typename T5>
00151 inline RuleBuilder<5,0,T1,T2,T3,T4,T5> on()
00152 {
00153 return RuleBuilder<5,0,T1,T2,T3,T4,T5>(new details::PatternChecker<5,T1,T2,T3,T4,T5>());
00154 }
00155
00162 void discard();
00163
00164 namespace details { ActorRef doSpawn(Actor *actor); }
00165
00169 void link(ActorRef actor1, ActorRef actor2);
00170
00180 template<class A>
00181 inline ActorRef spawn()
00182 {
00183 return details::doSpawn(new A());
00184 }
00185
00195 template<class A, typename T1>
00196 inline ActorRef spawn(const T1 &v1)
00197 {
00198 return details::doSpawn(new A(v1));
00199 }
00200
00204 template<class A, typename T1, typename T2>
00205 inline ActorRef spawn(const T1 &v1, const T2 &v2)
00206 {
00207 return details::doSpawn(new A(v1,v2));
00208 }
00209
00213 template<class A, typename T1, typename T2, typename T3>
00214 inline ActorRef spawn(const T1 &v1, const T2 &v2, const T3 &v3)
00215 {
00216 return details::doSpawn(new A(v1,v2,v3));
00217 }
00218
00222 template<class A, typename T1, typename T2, typename T3, typename T4>
00223 inline ActorRef spawn(const T1 &v1, const T2 &v2, const T3 &v3, const T4 &v4)
00224 {
00225 return details::doSpawn(new A(v1,v2,v3,v4));
00226 }
00227
00233 bool registerName(const String &name, const ActorRef &actor);
00234
00238 void unregisterName(const String &name);
00239
00248 ActorRef whereisName(const String &name);
00249
00255 StringList registeredNames();
00256
00257
00258
00259
00260
00266 template<typename T>
00267 GuardFunctor<T> *isEq(const T &x)
00268 {
00269 struct FuncImpl : public GuardFunctor<T>
00270 {
00271 T value;
00272 FuncImpl(const T &v) : value(v) { }
00273 virtual bool operator()(const T &what) { return what == value; }
00274 };
00275 return new FuncImpl(x);
00276 }
00277
00283 template<typename T>
00284 GuardFunctor<T> *isNe(const T &x)
00285 {
00286 struct FuncImpl : public GuardFunctor<T>
00287 {
00288 T value;
00289 FuncImpl(const T &v) : value(v) { }
00290 virtual bool operator()(const T &what) { return what != value; }
00291 };
00292 return new FuncImpl(x);
00293 }
00294
00300 template<typename T>
00301 GuardFunctor<T> *isGt(const T &x)
00302 {
00303 struct FuncImpl : public GuardFunctor<T>
00304 {
00305 T value;
00306 FuncImpl(const T &v) : value(v) { }
00307 virtual bool operator()(const T &what) { return what > value; }
00308 };
00309 return new FuncImpl(x);
00310 }
00311
00317 template<typename T>
00318 GuardFunctor<T> *isLt(const T &x)
00319 {
00320 struct FuncImpl : public GuardFunctor<T>
00321 {
00322 T value;
00323 FuncImpl(const T &v) : value(v) { }
00324 virtual bool operator()(const T &what) { return what < value; }
00325 };
00326 return new FuncImpl(x);
00327 }
00328
00332 void shutdown();
00333
00334 namespace details { void enqueueToScheduler(Actor *a); }
00335
00352 void setAppInfo(const char *appName,
00353 boost::uint32_t majorVersion,
00354 boost::uint32_t minorVersion,
00355 boost::uint32_t minCompatibleMajorVersion,
00356 boost::uint32_t minCompatibleMinorVersion,
00357 bool allowNewerMinorVersion = false,
00358 bool allowNewerMajorVersion = false);
00359
00360 namespace details
00361 {
00362
00363 const String &appIdentifier();
00364 const String &appName();
00365 boost::uint32_t appMajorVersion();
00366 boost::uint32_t appMinorVersion();
00367
00368
00369 bool isCompatible(const String &appName,
00370 boost::uint32_t major,
00371 boost::uint32_t minor);
00372 ActorRef getInstanceById(boost::uint32_t id);
00373 }
00374
00375 }
00376
00377 #endif // ACEDIA_H