4S Device Communication Module Collection  Version 0.6-SNAPSHOT
Full documentation of the modules in the 4SDC collection (aimed at 4SDC module developers)
moduledeclare.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2015 The 4S Foundation (www.4s-online.dk)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
157 #ifndef MODULEDECLARE_H
158 #define MODULEDECLARE_H
159 
160 #include "FSYS/basemsg.h"
161 #include "FSYS/log.h"
162 
163 #include <assert.h>
164 
165 namespace FSYS
166 {
174  class Module
175  {
176  public:
177  virtual void msgReady( void ) {}
178  virtual void msgGroupReady( void ) {}
179  virtual void msgSystemReady( void ) {}
180  virtual void msgGoingDown( void ) {}
181  virtual void msgDestroy( void ) {}
182  virtual ~Module( void ) {}
183  };
184 
193  class MsgSystemReady : public BaseMsg {};
194 
202  class MsgGoingDown : public BaseMsg {};
203 
210  class MsgGroupReady : public BaseMsg {};
211 
218  class MsgDestroy : public BaseMsg {};
219 
226  class MsgAllDestroyed : public BaseMsg {};
227 
228 namespace ModulePrivate
229 {
240  {
241  private:
245  void sendMsgReady( void );
246 
250  void sendMsgDestroy( void );
251 
255  bool isCreated = {false};
256 
257  protected:
258  Module *userObject{nullptr}; // The pointer to the real object
259 
267  virtual void create( void ) = 0;
268 
276  virtual void destroy( void ) = 0;
277 
278  public:
279  enum class ModuleType {
280  UNKNOWN,
281  STATIC,
282  DELAYED,
283  DYNAMIC,
284  DYNAMIC_THREAD
285  };
286 
295  virtual ModuleType getType( void ) = 0;
296 
303  void startup( void );
304 
311  void shutdown( void );
312 
318  inline bool isRunning( void );
319 
323  void sendMsgGroupReady( void );
324 
328  void sendMsgSystemReady( void );
329 
333  void sendMsgGoingDown( void );
334 
340  virtual ~LauncherBase( void ) {}
341  };
342 
348  template <class TypeToLaunch,
349  LauncherBase::ModuleType mt=LauncherBase::ModuleType::STATIC>
350  class Launcher : public LauncherBase
351  {
352 
353  private:
354  void create( void ) override
355  {
356  // Ensure the user object is null
357  assert(nullptr == userObject);
358 
359  // Instantiate the user object
360  userObject = new TypeToLaunch;
361  }
362 
363  void destroy( void ) override
364  {
365  // Delete the user object
366  delete userObject;
367 
368  // Make sure the user object is null
369  userObject = nullptr;
370  }
371 
372  ModuleType moduleType = {mt};
373  public:
382  ModuleType getType( void ) override
383  {
384  return moduleType;
385  }
386 
387  };
388 
394  class LauncherEnd : public LauncherBase
395  {
396 
397  private:
398  void create( void ) override {};
399 
400  void destroy( void ) override {};
401 
402  public:
403  ModuleType getType( void ) override
404  {
405  return LauncherBase::ModuleType::UNKNOWN;
406  }
407 
408  };
409 
410 }
411 
412 }
413 #endif
The LauncherBase class is the non-template class for other Launchers.
Definition: moduledeclare.h:239
Message broadcasted when all static modules in a group are ready.
Definition: moduledeclare.h:210
The Launcher class is used for dynamically launching the user clases.
Definition: moduledeclare.h:350
The BaseMsg class is the base class for all messages.
Definition: basemsg.h:54
Message broadcasted when the system is initialised.
Definition: moduledeclare.h:193
ModuleType getType(void) override
Function to retrieve info about the user object containd.
Definition: moduledeclare.h:382
Base class for all modules.
Definition: moduledeclare.h:174
Contains interface declaration for the FSYS::BaseMsg class.
Last message broadcasted to threads.
Definition: moduledeclare.h:218
void create(void) override
Virtual function, called when the user object should be created.
Definition: moduledeclare.h:398
ModuleType getType(void) override
Function to retrieve info about the user object containd.
Definition: moduledeclare.h:403
Definition: basemsg.h:38
void destroy(void) override
Virtual function, called when the user object should be destroyed.
Definition: moduledeclare.h:363
virtual ~LauncherBase(void)
LauncherBase destructor.
Definition: moduledeclare.h:340
Last message broadcasted in system.
Definition: moduledeclare.h:226
void destroy(void) override
Virtual function, called when the user object should be destroyed.
Definition: moduledeclare.h:400
void create(void) override
Virtual function, called when the user object should be created.
Definition: moduledeclare.h:354
Dummy launcher class to mark the end of the launcher list.
Definition: moduledeclare.h:394
Message broadcasted when the system is being terminated.
Definition: moduledeclare.h:202
Contains interface declaration for the FSYS::Log class.