AndroMeta  2.0.0
AndroMeta/include/AndroMeta/MMLEntity.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009-2012 AndroMeta LLC. All rights reserved.
00003  *
00004  * AndroMeta LLC retains all intellectual property and proprietary 
00005  * rights to this software and related documentation and any modifications 
00006  * thereto.  Any use, reproduction, disclosure, or distribution of this 
00007  * software and related documentation without an express license agreement 
00008  * from AndroMeta LLC is strictly prohibited.
00009  * 
00010  */
00011 
00018 #ifndef ANDROMETA_MML_ENTITY_H
00019 #define ANDROMETA_MML_ENTITY_H
00020 
00021 #include <AndroMeta/MObject.h>
00022 #include <AndroMeta/MTime.h>
00023 #include <AndroMeta/MVar.h>
00024 #include <AndroMeta/MProc.h>
00025 #include <AndroMeta/MNode.h>
00026 
00027 namespace Meta{
00028   
00029   class MProcTask;
00030   class MMessageBuffer;
00031   class MMLRoot;
00032   
00045   class MMLEntity : public MObject{
00046   public:
00047     
00048     static const ClassIdType ClassId;
00049     
00053     MMLEntity();
00054     
00061     MMLEntity(int id);
00062     
00068     MMLEntity(const MMLEntity& entity, bool recursive=false); 
00069     
00076     MMLEntity(const mvar& v, RestoreOpt opt, MMLRoot* root=0);
00077     
00081     MMLEntity(MMLRoot* root);
00082     
00086     virtual ~MMLEntity();
00087     
00091     virtual void store(mvar& v) const;
00092     
00098     virtual void store(mvar& v, bool recursive) const;
00099     
00109     static MMLEntity* ptr(const mvar& v, bool dynamic=false);
00110     
00114     virtual MObject* clone() const;
00115     
00119     virtual mnode process(mnode n, uint32_t flags=0);
00120     
00124     virtual bool instanceOf(ClassIdType classId) const;
00125     
00130     virtual void assignId();
00131     
00136     virtual void releaseId();
00137     
00141     virtual mvar init();
00142     
00146     void setId(int id);
00147     
00151     int id() const;
00152     
00156     void setTag(const mvar& tag);
00157     
00161     const mvar& tag() const;
00162     
00168     virtual mstr name() const;
00169     
00173     bool isThreaded() const;
00174     
00180     void setThreaded(bool flag);
00181     
00186     virtual MMessageBuffer* initPrivateBuffer();
00187     
00192     virtual MMessageBuffer* initSharedBuffer();
00193     
00198     MMessageBuffer* privateBuffer() const;
00199     
00204     MMessageBuffer* sharedBuffer() const;
00205     
00215     void connect(MMLEntity* ent,
00216                  const mvar& data=undef,
00217                  const mstr& edgeTag="");
00218     
00228     void connect(const mvar& ent,
00229                  const mvar& data=undef,
00230                  const mstr& edgeTag="");
00231     
00237     virtual void onConnect(MMLEntity* ent, const mstr& edgeTag);
00238     
00242     void disconnect(MMLEntity* ent, const mstr& edgeTag);
00243     
00247     void disconnect(const mvar& ent, const mstr& edgeTag);
00248     
00252     void disconnect(MMLEntity* ent);
00253     
00257     void disconnect(const mvar& ent);
00258     
00262     void disconnect();
00263     
00267     void addLocality(const mstr& attribute, double radius);
00268     
00272     void addLocality(const mstr& attribute, double radius, MMLEntity* ent);
00273     
00277     void addLocality(const mstr& attribute, double radius, const mvar& ent);
00278     
00282     size_t localityCount() const;
00283     
00287     const mstr& localityAttribute(size_t i) const;
00288     
00292     double localityRadius(size_t i) const;
00293     
00297     MMLEntity* localityEntity(size_t i) const;
00298     
00302     void removeLocality(const mstr& attribute);
00303         
00309     virtual void onDisconnect(MMLEntity* ent, const mstr& edgeTag);
00310     
00315     const mvar& edgeData(const MMLEntity* ent, const mstr& edgeTag="") const;
00316 
00321     const mvar& edgeData(const mvar& ent, const mstr& edgeTag="") const;
00322     
00327     void setEdgeData(const mvar& ent,
00328                      const mvar& edgeData,
00329                      const mstr& edgeTag="");
00330 
00335     void setEdgeData(const MMLEntity* ent,
00336                      const mvar& edgeData,
00337                      const mstr& edgeTag="");
00338     
00344     virtual void onAttach(MMLEntity* ent, const mstr& edgeTag);
00345     
00349     void detach();
00350     
00356     virtual void onDetach(MMLEntity* ent, const mstr& edgeTag);
00357     
00362     void signal(MMLEntity* ent, const mstr& edgeTag="");
00363     
00368     void signal(const mvar& ent, const mstr& edgeTag="");
00369     
00373     void signal(MMLEntity* ent, const mvar& v, const mstr& edgeTag);
00374     
00378     void signal(const mvar& ent, const mvar& v, const mstr& edgeTag);
00379     
00383     void signalAll();
00384     
00388     void signalAll(const mvar& v);
00389     
00393     size_t outEdgeCount() const;
00394     
00398     size_t inEdgeCount() const;
00399     
00404     void outEdges(mvec& ents, mvec& edgeTags) const;
00405     
00411     void outEdges(mvec& ents) const;
00412     
00418     mvec outEdges() const;
00419     
00423     void setActive(bool flag);
00424     
00428     bool isActive() const;
00429     
00434     void queue();
00435     
00439     void queue(MProcTask* task,
00440                MProc::SignalMap* signalMap=0,
00441                double priority=0,
00442                const mtime* time=0);
00443     
00447     mvar time() const;
00448     
00452     mvar interval() const;
00453     
00460     virtual mvar run();
00461     
00467     void setRunAll(bool flag);
00468     
00474     bool runAll() const;
00475     
00479     bool isRunCycle() const;
00480     
00485     virtual mvar endRun();
00486     
00491     const mvar& state() const;
00492     
00498     void setKept(bool kept);
00499     
00503     bool isKept() const;
00504     
00519     void query(mnode func,
00520                mvec& results,
00521                bool recursive,
00522                bool self,
00523                bool error) const;
00524     
00539     mvar query(mnode func,
00540                bool recursive=false,
00541                bool self=true,
00542                bool error=true) const;
00543     
00557     void execute(mnode func,
00558                  bool recursive=false,
00559                  bool self=true,
00560                  bool error=true) const;
00561     
00575     void find(const mstr& name,
00576               mvec& results,
00577               bool recursive,
00578               bool self) const;
00579     
00593     mvar find(const mstr& name,
00594               bool recursive=false,
00595               bool self=true) const;
00596     
00600     void await();
00601     
00608     bool await(const mtime& timeout);
00609     
00614     void handleEvents();
00615     
00620     virtual mvar handleEvent(const mvar& evt);
00621     
00632     void send(MMLEntity* ent, const mvar& evt, const mvar& delay);
00633     
00644     void send(const mvar& ent, const mvar& evt, const mvar& delay);
00645     
00655     void send(MMLEntity* ent, const mvar& evt);
00656     
00666     void send(const mvar& ent, const mvar& evt);
00667     
00675     void relay(const mvar& evt, const mvar& delay);
00676     
00683     void relay(const mvar& evt);
00684     
00694     void post(MMLEntity* ent, const mvar& evt, const mvar& delay);
00695     
00705     void post(const mvar& ent, const mvar& evt, const mvar& delay);
00706     
00715     void post(MMLEntity* ent, const mvar& evt);
00716     
00725     void post(const mvar& ent, const mvar& evt);
00726     
00735     void log(const mvar& msg, bool concise=true) const;
00736     
00740     void listen(MMLEntity* ent);
00741     
00745     void listen(const mvar& ent);
00746     
00751     virtual mvar end();
00752     
00761     mvar getLinks(mnode f=mfunc("List"));
00762     
00766     void lock();
00767     
00771     void unlock();
00772     
00773     friend class MMLEntity_;
00774     friend class MMLRoot_;
00775   
00779     MMLRoot* rootPtr();
00780     
00781   protected:
00782     mvar root;
00783     
00784   private:
00785     MMLEntity& operator=(const MMLEntity&);
00786     
00787     class MMLEntity_* x_;
00788   };
00789   
00790   std::ostream& operator<<(std::ostream& ostr, const MMLEntity& ent);
00791   
00792 } // end namespace Meta
00793 
00794 #endif // ANDROMETA_MML_ENTITY_H