Differences between revisions 6 and 10 (spanning 4 versions)
Revision 6 as of 2014-07-01 07:27:00
Size: 2269
Editor: HungTa
Comment:
Revision 10 as of 2014-07-01 08:56:53
Size: 2278
Editor: HungTa
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
=== Header === ==== Header ====
Line 15: Line 15:
=== APIs === ==== APIs ====
Line 49: Line 49:
The idea is based on SAFplus 6. An app can be configured with options named svcs as 'log', 'utils', 'ioc'... or 'all' and pass it to an environment variable. Then, following its value, the preface.mk will define accordingly:
==== preface.mk ====
Somehow, an app can be configured with options named svcs as 'log', 'utils', 'ioc'... or 'all' and pass it to an environment variable. Then, following its values, the preface.mk will define services accordingly:
==== Makefile ====
include preface.mk

SAFplus initialization

SAFplus provides library initialization infrastructure: log, utils, osal, timer... They're the basic libraries that most applications should use. However, not all of them would be used. Furthermore, it's necessary to be able to explicitly link individual libraries for highly embedded users.

Implementation

SAFplus initialization can be implemented in 2 methods:

According to GNU weak attribute declaration, we can declare initialization functions as the weak linked functions. Therefore, their definitions can be omitted (in case they're not used), or replaced by different libraries (in case they're used). The linker will fill in NULL for undefined weak symbols.

#include <clGlobals.hxx>

APIs

   1 namespace SAFplus
   2 {
   3   extern void utilsInitialize() __attribute__((weak));
   4   extern void logInitialize() __attribute__((weak));
   5   // TODO: other initialization functions declaration here
   6 
   7   enum
   8   {
   9     RPC=1,
  10     CKPT=2,
  11     IOC=4,
  12     UTILS=8,
  13     OSAL=16,
  14     LOG=32
  15   };
  16 
  17   void safplusInitialize(uint16_t svc)
  18   {
  19     if(svc&LOG)
  20       if(logInitialize) logInitialize();
  21     if(svc&UTILS)
  22       if(utilsInitialize) utilsInitialize();
  23     // TODO: other ones here
  24   }
  25     
  26 }

Method 2: configuring the app with options

Somehow, an app can be configured with options named svcs as 'log', 'utils', 'ioc'... or 'all' and pass it to an environment variable. Then, following its values, the preface.mk will define services accordingly:

Makefile

include preface.mk

   1 $DSVCS:=
   2 ifeq ($(SVCS),log)
   3        $DSVCS += -DLOG
   4 ifeq ($(SVCS),utils)
   5        $DSVCS += -DUTILS
   6 #...
   7 LINK_EXE    = g++ $DSVCS -g -O0 -fPIC $(LINK_FLAGS) -o

Header

#include <clGlobals.hxx>

APIs

   1 namespace SAFplus
   2 {
   3 
   4   enum
   5   {
   6     RPC=1,
   7     CKPT=2,
   8     IOC=4,
   9     UTILS=8,
  10     OSAL=16,
  11     LOG=32
  12   };
  13 
  14   void safplusInitialize(uint16_t svc)
  15   {
  16     if(svc&LOG)
  17 #ifdef LOG
  18       logInitialize();
  19 #endif
  20     if(svc&UTILS)
  21 #ifdef UTILS
  22       utilsInitialize();
  23 #endif
  24     // TODO: other ones here
  25   }
  26     
  27 }

SAFplus: SAFplus-initialization (last edited 2014-07-22 14:00:44 by AndrewStone)