iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConnectorBase.H
Go to the documentation of this file.
1 /*! @file
2  @author Laurent Itti
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_CORE_BLACKBOARD_CONNECTORBASE_H
37 #define INCLUDE_NRT_CORE_BLACKBOARD_CONNECTORBASE_H
38 
39 #include <sys/types.h> // for pid_t
40 #include <string>
41 #include <boost/thread/shared_mutex.hpp> // for shared_mutex, shared_lock and friends
42 #include <nrt/Core/Typing/Enum.H>
43 
44 namespace nrt
45 {
46  class ConnectorBase;
47 
48  // ######################################################################
49  //! Type of connector
50  /*! Intra-connectors connect modules within one namespace. Border connectors establish a bridge between a namespace
51  and its parent namespace.
52 
53  \ingroup connector */
54  NRT_DEFINE_ENUM_CLASS(ConnectorType, (Intra) (Border));
55 
56  // ######################################################################
57  //! Type for Connector unique ID data
58  /*! This used internally by Blackboard ONLY to keep track of connectors across distributed systems. Users should only
59  care about the Module type and possibly its (less efficient) instance defined in the Connector class.
60 
61  \ingroup connector */
62  struct ConnectorUID
63  {
64  //! Constructor
65  ConnectorUID(ConnectorBase const * con);
66 
67  //! Equality test
68  bool operator==(nrt::ConnectorUID const & other) const;
69 
70  //! As a string for printing debug messages
71  std::string const & str() const;
72 
73  long hostID;
74  pid_t procID;
75  ConnectorBase const * conID;
76  std::string strID; // the ID as a string
77  };
78 
79  // ######################################################################
80  //! Flavor of Connector
81  /*! \ingroup connector */
82  NRT_DEFINE_ENUM_CLASS(ConnectorFlavor, (Poster) (Checker) (Subscriber));
83 
84  // ######################################################################
85  //! Base class for Connector
86  /*! Everything is private in this class, only its friends can use it. Others, use nrt::Connector instead.
87 
88  \ingroup connector */
90  {
91  public:
92  //! Public destructor so std::shared_ptr<ConnectorBase> can delete the Connector
93  virtual ~ConnectorBase();
94 
95  private:
96  //! Construct a new connector
97  ConnectorBase(ConnectorFlavor const flavor_, std::string const & msgtype_, std::string const & rettype_,
98  std::string const & instance_, std::string const & namespc_, ConnectorType const type_,
99  std::string const & topic_, std::string const & topicfitl_);
100 
101  // This class can be confusing so nobody except for us the gurus of NRT should access these functions directly
102  template <class Posting> friend class MessagePosterConnector;
103  template <class Checking> friend class MessageCheckerConnector;
104  template <class Subscription> friend class MessageSubscriberConnector;
105 
106  ConnectorFlavor const flavor;
107  std::string const msgtype;
108  std::string const rettype;
109  std::string const instance;
110  std::string namespc;
111  ConnectorType const type;
112  std::string topic;
113  std::string topicfilt;
114  ConnectorUID const uid;
115  int sequence; //!< Connector sequence number within the namespace, used for ordering of ports in the GUI
116 
117  // Allow the BlackboardMaster to mess with our guts
118  friend class BlackboardMaster;
119  };
120 
121 } // namespace nrt
122 
123 #endif // INCLUDE_NRT_CORE_BLACKBOARD_CONNECTORBASE_H
124