Monday, April 25, 2011

Exploratory Project C Language Use of Verify Callback

Exploratory Project C Language Use of Verify Callback


I have now added the Verify interface between the Ada framework and a C component.

The comC1 C component supplies its Verify method when it registers a topic consumer.  The Verify method for the topic is both for the comC1 component and the particular topic so the method was named comC1VerifymTTopicPeriodic.  The Install method (that is, comC1Install) was modified such that the register for the topic is as follows
  topicParams.verify = (Int32)(&comC1VerifymTTopicPeriodic); // callback address
for notify where the Verify callback address is no longer set to 0 for null.

The Verify method is for the mTTopicPeriodic topic so the interface to obtain the address of the data in the buffer containing the instance of the message topic has been added to that .h and .c file that were provided in the preceding post.  The added interface is
  dataReaderPtr mTTopicPeriodicVerify(messageKey accessKey)
  { // Topic Verify
    dataReaderPtr dataAddress; // address of instance of topic data

    verifyCTopic(topicPeriodicId, &accessKey, (dataAddr*)(&dataAddress));

    return dataAddress;
  } // end method mTTopicPeriodicVerify

The Verify method for the topic, that is the function invoked by the framework when the component attempts to read the topic, is named after the method as comC1VerifymTTopicPeriodic.c so that it sorts in its Windows folder along with the other files for the component. 

The sample verify function itself only displays the data values to illustrate that the data pointer does indeed point to the data in the buffer.  Since, unlike the Reader interface, the framework will not invoke the verify function if there is no topic to be verified, there is no need to check for a null pointer. 

The framework returns the topic key to the verify function via a pointer while the interface back to the framework to obtain the data pointer uses the value.  Therefore, memcpy is used to copy the value pointed to by topicAccessKey to a local value to supply to mTTopicPeriodicVerify.  (Note:  In Ada the .all construct can be used to do this.)

#include <infCtoAda.h>
#include <conversion.h>
#include <mTTopicPeriodic.h>
#include <comC1.h>

Boolean comC1VerifymTTopicPeriodic(messageKeyPtr topicAccessKey)
{ // Verify topic mTTopicPeriodic for use by component comC1

  messageKey key;
  memcpy(&key,topicAccessKey,sizeof(key));

  dataReaderPtr buffer = mTTopicPeriodicVerify(key);

  consoleLen = snprintf(consoleBuffer,CONSOLE_MAX,"verify publishing \
                 component %u %u %u\n", \
                 buffer->publishingComponent.value[0], \
                 buffer->publishingComponent.value[1], \
                 buffer->publishingComponent.value[2]);
  console(consoleBuffer,consoleLen);
  consoleLen = snprintf(consoleBuffer,CONSOLE_MAX,"reference number & \
                 time %u %u\n", buffer->referenceNumber,buffer->time);
  console(consoleBuffer,consoleLen);
//buffer->publishingComponent.value[0] = 55; // attempt to change value
  return TRUE;

} // end method comC1VerifymTTopicPeriodic
where Boolean is defined in the infCtoAda header file as
  typedef Int32 Boolean;
  #define FALSE 0;
  #define TRUE 1;

Nothing further need be done.

No comments: