Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConsumerBase.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2006-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Anders Widén / stawi
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 
25 #ifndef _SAFIR_DOB_CONSUMER_BASE_H
26 #define _SAFIR_DOB_CONSUMER_BASE_H
27 
29 #include <Safir/Dob/Defs.h>
31 #include <Safir/Dob/EntityProxy.h>
38 
39 #ifdef _MSC_VER
40 //we need to disable the warning about inheriting by dominance, it is intended to be this way,
41 //and there is no way to produce code that does not give this warning, unfortunately.
42 //see also the comment on ConsumerBase
43 #pragma warning (disable: 4250)
44 #endif
45 
46 namespace Safir
47 {
48 namespace Dob
49 {
50  //Forward declarations:
51  class RevokedRegistrationBase;
52  class CompletedRegistrationBase;
53  class EntityRequestBase;
54  class EntityInjectionBase;
55  class ServiceRequestBase;
56  class StopHandler;
57  class Dispatcher;
58  class EntityHandler;
59  class EntityHandlerInjection;
60  class EntityHandlerPending;
61  class ServiceHandler;
62  class ServiceHandlerPending;
63  class Requestor;
64  class MessageSender;
65  class RegistrationSubscriber;
66  class MessageSubscriber;
67  class EntitySubscriber;
68 
69  namespace Internal
70  {
71  //forward declaration
72  class Callbacks;
73 
85  {
86  public:
87  virtual ~ConsumerBase() {}
88 
89  private:
90  friend class Safir::Dob::Internal::Callbacks;
91 
92  virtual RevokedRegistrationBase * ToRevokedRegistrationBase()
94  (L"Call to ConsumerBase::ToRevokedRegistrationBase is illegal. Method must be overridden!",
95  __WFILE__,__LINE__);}
96  virtual CompletedRegistrationBase * ToCompletedRegistrationBase()
98  (L"Call to ConsumerBase::ToCompletedRegistrationBase is illegal. Method must be overridden!",
99  __WFILE__,__LINE__);}
100  virtual EntityRequestBase * ToEntityRequestBase()
102  (L"Call to ConsumerBase::ToEntityRequestBase is illegal. Method must be overridden!",
103  __WFILE__,__LINE__);}
104  virtual EntityInjectionBase * ToEntityInjectionBase()
106  (L"Call to ConsumerBase::ToEntityInjectionBase is illegal. Method must be overridden!",
107  __WFILE__,__LINE__);}
108  virtual ServiceRequestBase * ToServiceRequestBase()
109  {throw Dob::Typesystem::SoftwareViolationException
110  (L"Call to ConsumerBase::ToServiceRequestBase is illegal. Method must be overridden!",
111  __WFILE__,__LINE__);}
112  virtual StopHandler * ToStopHandler()
113  {throw Dob::Typesystem::SoftwareViolationException
114  (L"Call to ConsumerBase::ToStopHandler is illegal. Method must be overridden!",
115  __WFILE__,__LINE__);}
116  virtual Dispatcher * ToDispatcher()
117  {throw Dob::Typesystem::SoftwareViolationException
118  (L"Call to ConsumerBase::ToDispatcher is illegal. Method must be overridden!",
119  __WFILE__,__LINE__);}
120  virtual EntityHandler * ToEntityHandler()
121  {throw Dob::Typesystem::SoftwareViolationException
122  (L"Call to ConsumerBase::ToEntityHandler is illegal. Method must be overridden!",
123  __WFILE__,__LINE__);}
124  virtual EntityHandlerInjection * ToEntityHandlerInjection()
125  {throw Dob::Typesystem::SoftwareViolationException
126  (L"Call to ConsumerBase::ToEntityHandlerInjection is illegal. Method must be overridden!",
127  __WFILE__,__LINE__);}
128  virtual EntityHandlerPending * ToEntityHandlerPending()
129  {throw Dob::Typesystem::SoftwareViolationException
130  (L"Call to ConsumerBase::ToEntityHandlerPending is illegal. Method must be overridden!",
131  __WFILE__,__LINE__);}
132  virtual ServiceHandler * ToServiceHandler()
133  {throw Dob::Typesystem::SoftwareViolationException
134  (L"Call to ConsumerBase::ToServiceHandler is illegal. Method must be overridden!",
135  __WFILE__,__LINE__);}
136  virtual ServiceHandlerPending * ToServiceHandlerPending()
137  {throw Dob::Typesystem::SoftwareViolationException
138  (L"Call to ConsumerBase::ToServiceHandlerPending is illegal. Method must be overridden!",
139  __WFILE__,__LINE__);}
140  virtual Requestor * ToRequestor()
141  {throw Dob::Typesystem::SoftwareViolationException
142  (L"Call to ConsumerBase::ToRequestor is illegal. Method must be overridden!",
143  __WFILE__,__LINE__);}
144  virtual MessageSender * ToMessageSender()
145  {throw Dob::Typesystem::SoftwareViolationException
146  (L"Call to ConsumerBase::ToMessageSender is illegal. Method must be overridden!",
147  __WFILE__,__LINE__);}
148  virtual RegistrationSubscriber * ToRegistrationSubscriber()
149  {throw Dob::Typesystem::SoftwareViolationException
150  (L"Call to ConsumerBase::ToRegistrationSubscriber is illegal. Method must be overridden!",
151  __WFILE__,__LINE__);}
152  virtual MessageSubscriber * ToMessageSubscriber()
153  {throw Dob::Typesystem::SoftwareViolationException
154  (L"Call to ConsumerBase::ToMessageSubscriber is illegal. Method must be overridden!",
155  __WFILE__,__LINE__);}
156  virtual EntitySubscriber * ToEntitySubscriber()
157  {throw Dob::Typesystem::SoftwareViolationException
158  (L"Call to ConsumerBase::ToEntitySubscriber is illegal. Method must be overridden!",
159  __WFILE__,__LINE__);}
160 
161 
162  //These functions take a void ptr and call the desired version of the above methods
163  static RevokedRegistrationBase * ToRevokedRegistrationBase(void * consumerBase)
164  {return static_cast<ConsumerBase*>(consumerBase)->ToRevokedRegistrationBase();}
165  static CompletedRegistrationBase * ToCompletedRegistrationBase(void * consumerBase)
166  {return static_cast<ConsumerBase*>(consumerBase)->ToCompletedRegistrationBase();}
167  static EntityRequestBase * ToEntityRequestBase(void * consumerBase)
168  {return static_cast<ConsumerBase*>(consumerBase)->ToEntityRequestBase();}
169  static EntityInjectionBase * ToEntityInjectionBase(void * consumerBase)
170  {return static_cast<ConsumerBase*>(consumerBase)->ToEntityInjectionBase();}
171  static ServiceRequestBase * ToServiceRequestBase(void * consumerBase)
172  {return static_cast<ConsumerBase*>(consumerBase)->ToServiceRequestBase();}
173  static StopHandler * ToStopHandler(void * consumerBase)
174  {return static_cast<ConsumerBase*>(consumerBase)->ToStopHandler();}
175  static Dispatcher * ToDispatcher(void * consumerBase)
176  {return static_cast<ConsumerBase*>(consumerBase)->ToDispatcher();}
177  static EntityHandler * ToEntityHandler(void * consumerBase)
178  {return static_cast<ConsumerBase*>(consumerBase)->ToEntityHandler();}
179  static EntityHandlerInjection * ToEntityHandlerInjection(void * consumerBase)
180  {return static_cast<ConsumerBase*>(consumerBase)->ToEntityHandlerInjection();}
181  static EntityHandlerPending * ToEntityHandlerPending(void * consumerBase)
182  {return static_cast<ConsumerBase*>(consumerBase)->ToEntityHandlerPending();}
183  static ServiceHandler * ToServiceHandler(void * consumerBase)
184  {return static_cast<ConsumerBase*>(consumerBase)->ToServiceHandler();}
185  static ServiceHandlerPending * ToServiceHandlerPending(void * consumerBase)
186  {return static_cast<ConsumerBase*>(consumerBase)->ToServiceHandlerPending();}
187  static Requestor * ToRequestor(void * consumerBase)
188  {return static_cast<ConsumerBase*>(consumerBase)->ToRequestor();}
189  static MessageSender * ToMessageSender(void * consumerBase)
190  {return static_cast<ConsumerBase*>(consumerBase)->ToMessageSender();}
191  static RegistrationSubscriber * ToRegistrationSubscriber(void * consumerBase)
192  {return static_cast<ConsumerBase*>(consumerBase)->ToRegistrationSubscriber();}
193  static MessageSubscriber * ToMessageSubscriber(void * consumerBase)
194  {return static_cast<ConsumerBase*>(consumerBase)->ToMessageSubscriber();}
195  static EntitySubscriber * ToEntitySubscriber(void * consumerBase)
196  {return static_cast<ConsumerBase*>(consumerBase)->ToEntitySubscriber();}
197  };
198  }
199 
206  public virtual Internal::ConsumerBase
207  {
208  public:
211 
218  virtual void OnRevokedRegistration(const Safir::Dob::Typesystem::TypeId typeId,
219  const Safir::Dob::Typesystem::HandlerId& handlerId) = 0;
220 
221  private:
222  virtual RevokedRegistrationBase * ToRevokedRegistrationBase() {return this;}
223  };
224 
231  {
232  public:
239  virtual void OnCompletedRegistration(const Safir::Dob::Typesystem::TypeId typeId,
240  const Safir::Dob::Typesystem::HandlerId& handlerId) = 0;
241 
242  private:
243  virtual CompletedRegistrationBase * ToCompletedRegistrationBase() {return this;}
244  };
245 
252  public virtual Internal::ConsumerBase
253  {
254  public:
256  virtual ~EntityRequestBase() {}
257 
279  virtual void OnCreateRequest(const Safir::Dob::EntityRequestProxy entityRequestProxy,
280  Safir::Dob::ResponseSenderPtr responseSender) = 0;
281 
293  virtual void OnUpdateRequest(const Safir::Dob::EntityRequestProxy entityRequestProxy,
294  Safir::Dob::ResponseSenderPtr responseSender) = 0;
295 
307  virtual void OnDeleteRequest(const Safir::Dob::EntityRequestProxy entityRequestProxy,
308  Safir::Dob::ResponseSenderPtr responseSender) = 0;
309 
310  private:
311  virtual EntityRequestBase * ToEntityRequestBase() {return this;}
312  };
313 
345  {
346  public:
353  virtual void OnInjectedNewEntity(const Safir::Dob::InjectedEntityProxy injectedEntityProxy) {}
354 
361  virtual void OnInjectedUpdatedEntity(const Safir::Dob::InjectedEntityProxy injectedEntityProxy) {}
362 
369  virtual void OnInjectedDeletedEntity(const Safir::Dob::InjectedEntityProxy injectedEntityProxy) {}
370 
388  const Dob::Typesystem::HandlerId& handlerId)
389  { //This is an empty implementation, but we have this little bit to avoid MSVC++ warnings
390 #ifdef _MSC_VER
391  typeId;handlerId;
392 #endif
393  }
394 
395 
396  private:
397  virtual EntityInjectionBase * ToEntityInjectionBase() {return this;}
398  };
399 
406  public virtual Internal::ConsumerBase
407  {
408  public:
410  virtual ~ServiceRequestBase() {}
411 
423  virtual void OnServiceRequest(const Safir::Dob::ServiceRequestProxy serviceRequestProxy,
424  Safir::Dob::ResponseSenderPtr responseSender ) = 0;
425 
426  private:
427  virtual ServiceRequestBase * ToServiceRequestBase() {return this;}
428  };
429 
430 }
431 }
432 
433 
434 #endif
435 
boost::shared_ptr< ResponseSender > ResponseSenderPtr
Definition: ResponseSender.h:107
Class containing the identity of a handler.
Definition: HandlerId.h:44
Proxy class for a service request.
Definition: ServiceRequestProxy.h:52
virtual ~ServiceRequestBase()
Virtual destructor is needed since we have virtual member functions.
Definition: ConsumerBase.h:410
Base class used when composing more elaborated interfaces.
Definition: ConsumerBase.h:230
virtual void OnInjectedUpdatedEntity(const Safir::Dob::InjectedEntityProxy injectedEntityProxy)
Called when an updated entity is about to be injected in the system.
Definition: ConsumerBase.h:361
Meant to be used when something goes very wrong.
Definition: Exceptions.h:360
virtual ~ConsumerBase()
Definition: ConsumerBase.h:87
DotsC_TypeId TypeId
A unique type identifier.
Definition: Defs.h:219
Proxy class for an entity request.
Definition: EntityRequestProxy.h:53
virtual void OnInitialInjectionsDone(const Safir::Dob::Typesystem::TypeId typeId, const Dob::Typesystem::HandlerId &handlerId)
Indicates that all initial injection data has been transfered to the handler.
Definition: ConsumerBase.h:387
Base class used when composing more elaborated interfaces.
Definition: ConsumerBase.h:84
#define __WFILE__
Definition: Exceptions.h:31
Proxy class for entity injections.
Definition: InjectedEntityProxy.h:52
virtual ~EntityRequestBase()
Virtual destructor is needed since we have virtual member functions.
Definition: ConsumerBase.h:256
virtual ~RevokedRegistrationBase()
Virtual destructor is needed since we have virtual member functions.
Definition: ConsumerBase.h:210
This Consumer Base class contains callback methods that can be overridden by an entity handler that r...
Definition: ConsumerBase.h:344
#define DOSE_CPP_API
Definition: DoseCppExportDefs.h:33
Interface to receive entity requests.
Definition: ConsumerBase.h:251
virtual void OnInjectedDeletedEntity(const Safir::Dob::InjectedEntityProxy injectedEntityProxy)
Called when an entity delete is about to be injected in the system.
Definition: ConsumerBase.h:369
virtual void OnInjectedNewEntity(const Safir::Dob::InjectedEntityProxy injectedEntityProxy)
Called when a new entity is about to be injected in the system.
Definition: ConsumerBase.h:353
Base class used when composing more elaborated interfaces.
Definition: ConsumerBase.h:205
Interface to receive service requests.
Definition: ConsumerBase.h:405