Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

C modules basic implementation



The C code corresponding to basic C modules have no C dependencies to the framework, but some functions with specific signatures need to be declared in order for the module to work correctly.

Initialization function declaration

The mandatory C library init function is called during the module initialization to specify the pointers to the functions which will have to be called at the start and end of a Service invocation.

This function must have the following signature:
      __declspec(dllexport) void init(void (*startInvoke)(long), void (*endInvoke));
  • The first void (*startInvoke)(long) pointer points to the Java function which must be called at the start of a Service invocation
  • The second void (*endInvoke)() pointer points to the Java function which must be called at the end of a Service invocation

Example

For the C header:
      // the __declspec(dllexport) allows to export the signature of the init function
      __declspec(dllexport) void init(void (*startInvoke)(long), void (*endInvoke));

      // the two startInvokeInst and endInvokeInst declarations are the pointers to the two functions used when invoking a Service from the C code
      static void (*startInvokeInst)(long);
      static void (*endInvokeInst)();
For the C source:
      void init(void (*startInvoke)(long), void (*endInvoke)()) {
        startInvokeInst = startInvoke;
        endInvokeInst = endInvoke;
      }

Data set functions declarations

The optional setXXXInvoker functions are called during the module initialization to specify the pointers to Data sets, depending on the Data type.

These functions must have the following signatures:
      // for int datas
      __declspec(dllexport) void setIntInvoker(void (*intInvokerInst)(char*, int));

      // for boolean datas
      __declspec(dllexport) void setBooleanInvoker(void (*booleanInvokerInst)(char*, int));

      // for char datas
      __declspec(dllexport) void setCharInvoker(void (*charInvokerInst)(char*, char));

      // for byte datas
      __declspec(dllexport) void setByteInvoker(void (*byteInvokerInst)(char*, byte));

      // for short datas
      __declspec(dllexport) void setShortInvoker(void (*shortInvokerInst)(char*, short));

      // for long datas
      __declspec(dllexport) void setLongInvoker(void (*longInvokerInst)(char*, long));

      // for float datas
      __declspec(dllexport) void setFloatInvoker(void (*floatInvokerInst)(char*, float));

      // for double datas
      __declspec(dllexport) void setDoubleInvoker(void (*doubleInvokerInst)(char*, double));

      // for String datas
      __declspec(dllexport) void setStringInvoker(void (*stringInvokerInst)(char*, char*));

Example

For the C header:
      // the __declspec(dllexport) allows to export the signature of the function
      __declspec(dllexport) void setIntInvoker(void (*intInvokerInst)(char*, int));

      // the two intInvokerInst declaration is the pointer to the function used when setting the value of an int Data from the C code
      static void (*intInvokerInst)(char*, int);
For the C source:
      void setIntInvoker(void (*intInvoker)(char*, int)) {
        intInvokerInst = intInvoker;
      }

Start function declaration

This optional function is called when starting the module.

It must have the following signature:
      start()

Example

For the C header:
      // the __declspec(dllexport) allows to export the signature of the function
      __declspec(dllexport) void start();
For the C source:
      void start()() {
      // do something when the module starts
      }

End function declaration

This optional function is called when the framewoerk is shutdown.

It must have the following signature:
      end()

Example

For the C header:
      // the __declspec(dllexport) allows to export the signature of the function
      __declspec(dllexport) void end();
For the C source:
      void end()() {
        // do something when the framework shutdown
      }

Service notification functions

These optional functions are called for a notification.

  • The startNotify function will be called at the beginning of a Service invocation
  • The receiveXXX functions will be called for each data of the invoked Service
  • The endNotify function will be called at the end of a Service invocation
The startNotify must have the following signature:
      __declspec(dllexport) void startNotify(long service);
The endNotify must have the following signature:
      __declspec(dllexport) void endNotify(long service);
The receiveXXX must have the following signatures, depending on the Data type:
      __declspec(dllexport) void receiveInt(char* data, int value);

      __declspec(dllexport) void receiveChar(char* data, char value);

      __declspec(dllexport) void receiveShort(char* data, short value);

      __declspec(dllexport) void receiveByte(char* data, byte value);

      __declspec(dllexport) void receiveLong(char* data, long value);

      __declspec(dllexport) void receiveBoolean(char* data, int value);

      __declspec(dllexport) void receiveFloat(char* data, float value);

      __declspec(dllexport) void receiveDouble(char* data, double value);

      __declspec(dllexport) void receiveString(char* data, char* value);

Example

For the C header:
      __declspec(dllexport) void receiveBoolean(char* data, int value);
      static int step = 1;
For the C source:
      void receiveBoolean(char* data, int value) {
        if (value) {
          step = -1;
        } else {
          step = 1;
        }
      }

Service invocation functions

The pointers to the Service invocation functions are defined during the module initialization.

To invoke a Service, you must:
  • Call the *startInvoke function pointer with the Service ID as argument
  • Call the *xxxInvokerInst associated function pointer for each Service data you want to set the value
  • Call the *endInvoke function pointer

Example

For the C header:
      // the __declspec(dllexport) allows to export the signature of the init function
      __declspec(dllexport) void init(void (*startInvoke)(long), void (*endInvoke));
      // the __declspec(dllexport) allows to export the signature of the function
      __declspec(dllexport) void setIntInvoker(void (*intInvokerInst)(char*, int));

      static void (*startInvokeInst)(long);
      static void (*endInvokeInst)();
      static void (*intInvokerInst)(char*, int);
For the C source:
      void init(void (*startInvoke)(long), void (*endInvoke)()) {
        startInvokeInst = startInvoke;
        endInvokeInst = endInvoke;
      }

      void publish(long service) {
        // invoke the Service with ID 2
        startInvokeInst(2);
        // sets the value 10 for the "myData" Data
        intInvokerInst("myData", 10);
        // effectively invoke the Service
        endInvokeInst();
      }

See also


Categories: concepts | development

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence