MIRA
IRigidModelProvider.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_IRIGIDMODELPROVIDER_H_
48 #define _MIRA_IRIGIDMODELPROVIDER_H_
49 
51 
52 #include <fw/Framework.h>
53 #include <fw/ServiceProperty.h>
54 
55 #include <model/RigidModel.h>
56 
57 namespace mira { namespace model {
58 
60 
61 Buffer<uint8> findAndLoadResourceFile(const std::string& filename,
62  bool compress, uint32 maxFileSize);
63 
65 
70 {
71 public:
72 
73  IRigidModelProvider() : mServiceRegistered(false) {}
74 
76  template<typename Reflector>
77  void reflect(Reflector& r)
78  {
79  }
80 
81  void reflect(RPCServer::RPCReflector& r) {
82  // only register once, even when called twice (diamond class structure)
83  if (mServiceRegistered)
84  return;
85 
86  r.interface("IRigidModelProvider");
87  r.method("getRigidModel", &IRigidModelProvider::getRigidModel, this,
88  "Return the current rigid model");
89 
90  r.interface("IResourceFileProvider");
91  r.property("MaxTransferFileSize", mMaxFileSize,
92  "Max size of files to transfer", std::numeric_limits<uint32>::max());
93  r.method("getResourceFile", &IRigidModelProvider::getResourceFile, this,
94  "Return a buffer containing the content of a resource file",
95  "filename", "The file's filename", "MyModel.mesh",
96  "compress", "Whether to compress the returned buffer", true);
97 
98  mServiceRegistered = true;
99  }
100 
102  virtual ~IRigidModelProvider() {}
103 
107  virtual model::RigidModelPtr getRigidModel() = 0;
108 
113  virtual Buffer<uint8> getResourceFile(const std::string& filename, bool compress) {
114  return findAndLoadResourceFile(filename, compress, mMaxFileSize);
115  }
116 
117 private:
118  bool mServiceRegistered;
119 
120  uint32 mMaxFileSize;
121 };
122 
124 
130 {
131 public:
132 
133  // Subclasses should set mModelProvider themselves if they expect a different
134  // (derived) interface
135  IRigidModelConsumer() : mModelProvider("IRigidModelProvider") {}
136  virtual ~IRigidModelConsumer() {}
137 
139  template<typename Reflector>
140  void reflect(Reflector& r)
141  {
142  r.property("ModelProvider", mModelProvider,
144  "The name of the service that provides a rigid model "
145  "(if empty, a suitable service should be chosen automatically)",
147 
148  r.method("getModelProviderChannel",
150  "Query channel where the service publishes changes of ModelProvider.");
151 
152  r.interface("IRigidModelConsumer");
153  }
154 
155  void setModelProvider(ServiceProperty service);
156 
157  virtual std::string getModelProviderChannel();
158 
159 protected:
160 
162  void initialize();
163 
165  virtual void setModelProviderInternal(ServiceProperty service) = 0;
166 
168  virtual Authority* getAuthority() = 0;
169 
176  virtual std::string getModelProviderChannelInternal();
177 
178 protected:
180 
182 };
183 
185 
186 }}
187 
188 #endif
void initialize()
Must be called in service&#39;s initialize() method, after initializing mModelProvider.
IRigidModelProvider()
Definition: IRigidModelProvider.h:73
ServiceProperty mModelProvider
Definition: IRigidModelProvider.h:179
virtual Authority * getAuthority()=0
Must be implemented and return a valid authority.
void reflect(Reflector &r)
Reflect method for serialization.
Definition: IRigidModelProvider.h:140
A rigid model representation.
void reflect(RPCServer::RPCReflector &r)
Definition: IRigidModelProvider.h:81
Setter< T > setter(void(*f)(const T &))
virtual model::RigidModelPtr getRigidModel()=0
Return the used rigid model pointer.
IRigidModelConsumer is a unit that has a ServiceProperty &#39;ModelProvider&#39; for an IRigidModelProvider s...
Definition: IRigidModelProvider.h:129
Buffer< uint8 > findAndLoadResourceFile(const std::string &filename, bool compress, uint32 maxFileSize)
boost::shared_ptr< RigidModel > RigidModelPtr
Definition: RigidModel.h:205
Channel< std::string > mModelProviderChannel
Definition: IRigidModelProvider.h:181
virtual ~IRigidModelConsumer()
Definition: IRigidModelProvider.h:136
virtual void setModelProviderInternal(ServiceProperty service)=0
Must be implemented in subclasses and must set mModelProvider.
virtual Buffer< uint8 > getResourceFile(const std::string &filename, bool compress)
Return the content of a resource file (may be required to display the model).
Definition: IRigidModelProvider.h:113
void setModelProvider(ServiceProperty service)
IRigidModelConsumer()
Definition: IRigidModelProvider.h:135
void reflect(Reflector &r)
Reflect method for serialization.
Definition: IRigidModelProvider.h:77
Interface for rigid model provider services.
Definition: IRigidModelProvider.h:69
virtual ~IRigidModelProvider()
The destructor.
Definition: IRigidModelProvider.h:102
virtual std::string getModelProviderChannel()
virtual std::string getModelProviderChannelInternal()
Can be implemented in subclasses to override the default channel name "<namespace/of/service>/ModelPr...