00001 #ifndef __INSTANTIO_NAMESPACE_H
00002 #define __INSTANTIO_NAMESPACE_H
00003
00004 #ifdef _MSC_VER
00005 # pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "InstantIODef.h"
00027 #include "VariableReplacer.h"
00028 #include "Slot.h"
00029 #include <string>
00030 #include <map>
00031 #include <set>
00032 #include <vector>
00033 #include <memory>
00034 namespace Medusa
00035 {
00036 class Mutex;
00037 }
00038 namespace Hermes
00039 {
00040 class URL;
00041 }
00042 #ifdef _MSC_VER
00043 # pragma warning (push)
00044 # pragma warning (disable: 4251)
00045 #endif
00046
00047
00048 namespace InstantIO
00049 {
00050
00051
00052 class BasicOutSlot;
00053 class BasicInSlot;
00054 class Node;
00055
00056
00182 class INSTANTIO_DLLMAPPING Namespace
00183 {
00184 public:
00185
00194 class INSTANTIO_DLLMAPPING Listener
00195 {
00196 public:
00197
00199 virtual ~Listener();
00200
00207 virtual void outSlotAdded(Namespace &ns, const std::string &label, BasicOutSlot &outSlot);
00208
00215 virtual void outSlotRemoved(Namespace &ns, const std::string &label, BasicOutSlot &outSlot);
00216
00223 virtual void inSlotAdded(Namespace &ns, const std::string &label, BasicInSlot &inSlot);
00224
00231 virtual void inSlotRemoved(Namespace &ns, const std::string &label, BasicInSlot &inSlot);
00232
00239 virtual void routeAdded(Namespace &ns, const std::string &from, const std::string &to);
00240
00247 virtual void routeRemoved(Namespace &ns, const std::string &from, const std::string &to);
00248 };
00249
00251
00252
00258 Namespace();
00259
00263 virtual ~Namespace();
00264
00266
00273 void addListener(Listener &listener);
00274
00279 void removeListener(Listener &listener);
00280
00289 virtual void enable();
00290
00299 virtual void disable();
00300
00306 bool enabled() const;
00307
00312 const std::string &getLabel() const
00313 { return label_; }
00314
00319 virtual std::string typeName() const;
00320
00325 void clear();
00326
00335 virtual bool saveState() const;
00336
00341 bool dirty() const;
00342
00353 void setDirty(bool dirty);
00354
00360 void setBaseURL(const Hermes::URL &url);
00361
00367 const Hermes::URL &getBaseURL() const;
00368
00373 inline Medusa::Mutex *upMutex() const { return upMutex_; }
00374
00375
00376
00384 void setFieldValues(const std::string ¶mLine);
00385
00391 virtual void setFieldValue(const std::string &name, const std::string &value);
00392
00398 virtual std::string getFieldValue(const std::string &name) const
00399 ;
00400
00405 virtual void getFieldNames(std::vector<std::string> &names) const;
00406
00407
00408
00410
00411
00412 class LabeledOutSlot;
00413 class LabeledInSlot;
00414
00419 class LabeledSlot
00420 {
00421 public:
00422
00428 inline LabeledSlot(const std::string &l, Slot *s)
00429 : label(l), slot(s)
00430 {}
00431
00436 LabeledSlot(const LabeledOutSlot &labeledOutSlot);
00437
00442 LabeledSlot(const LabeledInSlot &labeledInSlot);
00443
00445 std::string label;
00446
00448 Slot *slot;
00449 };
00450
00452 typedef std::vector<LabeledSlot> LabeledSlotVector;
00453
00461 virtual void removeSlot(const std::string &label, Slot *slot);
00462
00470 virtual void getSlots(const std::string &label, Slot::Direction direction, LabeledSlotVector &slotVector);
00471
00473
00474
00475
00477
00478
00483 class LabeledOutSlot
00484 {
00485 public:
00486
00492 inline LabeledOutSlot(const std::string &l, BasicOutSlot *os)
00493 : label(l), outSlot(os), counter(0)
00494 {}
00495
00497 std::string label;
00498
00500 BasicOutSlot *outSlot;
00501
00503 int counter;
00504 };
00505
00507 typedef std::vector<LabeledOutSlot> LabeledOutSlotVector;
00508
00521 virtual void addOutSlot(const std::string &label, BasicOutSlot *outSlot);
00522
00530 virtual void removeOutSlot(const std::string &label, BasicOutSlot *outSlot);
00531
00538 virtual void getOutSlots(const std::string &label, LabeledOutSlotVector &outSlotVector);
00539
00541
00542
00543
00545
00546
00551 class LabeledInSlot
00552 {
00553 public:
00554
00560 inline LabeledInSlot(const std::string &l, BasicInSlot *is)
00561 : label(l), inSlot(is), counter(0)
00562 {}
00563
00565 std::string label;
00566
00568 BasicInSlot *inSlot;
00569
00571 int counter;
00572 };
00573
00575 typedef std::vector<LabeledInSlot> LabeledInSlotVector;
00576
00589 virtual void addInSlot(const std::string &label, BasicInSlot *inSlot);
00590
00598 virtual void removeInSlot(const std::string &label, BasicInSlot *inSlot);
00599
00606 virtual void getInSlots(const std::string &label, LabeledInSlotVector &inSlotVector);
00607
00609
00610
00611
00613
00614
00619 class ExternalRoute
00620 {
00621 public:
00622
00629 inline ExternalRoute(const Namespace &ns, const std::string &in, const std::string &ex)
00630 : internal(in), external(ex), namespace_(ns), variableReplacer_(ex)
00631 {}
00632
00638 std::string getExternalForInternal(const std::string &in) const;
00639
00641 std::string internal;
00642
00644 std::string external;
00645
00646 private:
00647
00649 const Namespace &namespace_;
00650
00652 VariableReplacer variableReplacer_;
00653 };
00654
00656 typedef std::vector<ExternalRoute*> ExternalRouteVector;
00657
00667 void addExternalRoute(const std::string &internal, const std::string &external);
00668
00676 void removeExternalRoute(const std::string &internal, const std::string &external);
00677
00683 void getExternalRoutes(ExternalRouteVector &externalRoutes) const;
00684
00691 ExternalRouteVector getExternalRoutesForInternal(const std::string &internal) const;
00692
00694 void clearExternalRoutes();
00695
00697
00698
00699
00701
00702
00707 class Route
00708 {
00709 public:
00710
00716 inline Route(const std::string &f, const std::string &t)
00717 : from(f), to(t)
00718 {}
00719
00721 std::string from;
00722
00724 std::string to;
00725 };
00726
00728 typedef std::vector<Route> RouteVector;
00729
00738 void addRoute(const std::string &from, const std::string &to);
00739
00746 void removeRoute(const std::string &from, const std::string &to);
00747
00753 void getRoutes(RouteVector &routes) const;
00754
00761 void getRoutesFrom(const std::string &from, RouteVector &routes);
00762
00769 void getRoutesTo(const std::string &to, RouteVector &routes);
00770
00772 void clearRoutes();
00773
00775
00776
00777
00779
00780
00787 inline const std::string &addNamespace(std::auto_ptr<Namespace> ns)
00788 {
00789 std::string typeName = ns->typeName();
00790 return addNamespace(typeName, ns);
00791 }
00792
00799 const std::string &addNamespace(std::auto_ptr<Node> ns);
00800
00808 const std::string &addNamespace(const std::string &label, std::auto_ptr<Namespace> ns);
00809
00817 const std::string &addNamespace(const std::string &label, std::auto_ptr<Node> ns);
00818
00826 std::auto_ptr<Namespace> removeNamespace(const std::string &label)
00827 ;
00828
00836 Namespace *getNamespace(const std::string &label) const
00837 ;
00838
00840 typedef std::map<std::string, Namespace*> NamespaceMap;
00841
00846 inline NamespaceMap &getNamespaces()
00847 { return namespaces_; }
00848
00853 inline const NamespaceMap &getNamespaces() const
00854 { return namespaces_; }
00855
00857 void clearNamespaces();
00858
00860
00861 protected:
00862
00864 Medusa::Mutex *upMutex_;
00865
00867 Medusa::Mutex *downMutex_;
00868
00870 Namespace *parentNamespace_;
00871
00873 bool enabled_;
00874
00876 std::string label_;
00877
00884 virtual void initialize();
00885
00892 virtual void shutdown();
00893
00894
00895
00897 LabeledOutSlotVector outSlots_;
00898
00907 LabeledOutSlotVector::iterator findOutSlot(const std::string &label, BasicOutSlot *outSlot);
00908
00916 void getRoutedOutSlots(const std::string &label, LabeledOutSlotVector &outSlotVector);
00917
00924 void getExportedOutSlots(const std::string &label, LabeledOutSlotVector &outSlotVector);
00925
00926
00927
00929 LabeledInSlotVector inSlots_;
00930
00939 LabeledInSlotVector::iterator findInSlot(const std::string &label, BasicInSlot *inSlot);
00940
00948 void getRoutedInSlots(const std::string &label, LabeledInSlotVector &inSlotVector);
00949
00956 void getExportedInSlots(const std::string &label, LabeledInSlotVector &inSlotVector);
00957
00958
00959
00961 ExternalRouteVector externalRoutes_;
00962
00971 ExternalRouteVector::iterator findExternalRoute(const std::string &internal, const std::string &external);
00972
00980 void removeExternalRoute(const ExternalRouteVector::const_iterator &it);
00981
00982
00983
00985 RouteVector routes_;
00986
00995 RouteVector::iterator findRoute(const std::string &from, const std::string &to);
00996
01002 void removeRoute(const RouteVector::const_iterator &it);
01003
01004
01005
01007 NamespaceMap namespaces_;
01008
01014 std::string createUniqueLabel(const std::string &label) const;
01015
01016 private:
01017
01019 Namespace(const Namespace &);
01020
01022 const Namespace &operator=(const Namespace &);
01023
01025 bool dirty_;
01026
01028 Hermes::URL *url_;
01029
01031 typedef std::map<std::string, std::pair<std::string, std::string> > FieldMap;
01032
01034 FieldMap fields_;
01035
01037 typedef std::set<Listener*> ListenerSet;
01038
01040 ListenerSet listeners_;
01041 };
01042
01043
01044 }
01045
01046
01047 #ifdef _MSC_VER
01048 # pragma warning (pop)
01049 #endif
01050
01051 #endif // __INSTANTIO_NAMESPACE_H