Difference between revisions of "WISE-Agent Sample Handler"

From ESS-WIKI
Jump to: navigation, search
Line 25: Line 25:
  
 
== Plugin (Handler) APIs ==
 
== Plugin (Handler) APIs ==
 +
 +
=== List ===
  
  
Line 37: Line 39:
 
''Return Values''
 
''Return Values''
  
*handler_success
+
*[-1|0] Error or Success.
*handler_fail
+
 
 +
----
  
  
Line 56: Line 59:
 
''Return Values''
 
''Return Values''
  
*handler_success
+
*[-1|0] Error or Success.
*handler_fail
+
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">void Handler_OnStatusChange( HANDLER_INFO *handler );</syntaxhighlight> ''Description''
 +
*This function will be called while&nbsp;CAgent connection status updated.
 +
 
 +
''Parameters''
 +
 
 +
*handler [POINTER]
 +
**the pointer of Handler Info structure.
 +
 
 +
''Return Values''
 +
 
 +
*None.
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">int Handler_Start( void );</syntaxhighlight> ''Description''
 +
*Start handler thread.
 +
 
 +
''Parameters''
 +
 
 +
*None.
 +
 
 +
''Return Values''
 +
 
 +
*[-1|0] Error or Success.
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">int Handler_Stop( void );</syntaxhighlight> ''Description''
 +
*Stop handler thread.
 +
 
 +
''Parameters''
 +
 
 +
*None.
 +
 
 +
''Return Values''
 +
 
 +
*[-1|0] Error or Success.
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">void Handler_Recv( char * const topic, void* const data, const size_t datalen, void *pRev1, void* pRev2  );</syntaxhighlight> ''Description''
 +
*Received Packet from Server.
 +
 
 +
''Parameters''
 +
 
 +
*topic[POINTER]
 +
**MQTT topic string
 +
*data[POINTER]
 +
**pointer of received payload.
 +
*datalen[NUMBER]
 +
**received payload size
 +
*pRev1[POINTER]
 +
**preserved pointer.
 +
*pRev2[POINTER]
 +
**preserved pointer.
 +
 
 +
''Return Values''
 +
 
 +
*None.
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">int Handler_Get_Capability( char ** pOutReply );</syntaxhighlight> ''Description''
 +
*Get Handler Information specification.&nbsp;
 +
*Release allocated mamory by calling&nbsp;Handler_MemoryFree.
 +
 
 +
''Parameters''
 +
 
 +
*pOutReply [POINTER]
 +
**double-pointer of capability string memory.
 +
 
 +
''Return Values''
 +
 
 +
*[-1|0] Error or Success.
 +
 
 +
 
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">void Handler_MemoryFree(char *pInData);</syntaxhighlight> ''Description''
 +
*Free the mamory allocated for Handler_Get_Capability
 +
 
 +
''Parameters''
 +
 
 +
*pInData[POINTER]
 +
**pointer of capability string memory.
 +
 
 +
''Return Values''
 +
 
 +
*None.
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">void Handler_AutoReportStart(char *pInQuery);</syntaxhighlight> ''Description''
 +
*Start Auto Report
 +
 
 +
''Parameters''
 +
 
 +
*pInQuery[POINTER]
 +
**pointer of &nbsp;request string.
 +
 
 +
''Return Values''
 +
 
 +
*None.
 +
 
 +
----
 +
 
 +
 
 +
<syntaxhighlight lang="c">void Handler_AutoReportStop(char *pInQuery);</syntaxhighlight> ''Description''
 +
*Stop Auto Report
 +
 
 +
''Parameters''
 +
 
 +
*pInQuery[POINTER]
 +
**pointer of &nbsp;request string.
 +
 
 +
''Return Values''
 +
 
 +
*None.
 +
 
 +
=== Tyep Define ===
  
 
== Easy Implement Libraries ==
 
== Easy Implement Libraries ==

Revision as of 09:36, 4 October 2016

In WISE Agent, we implement several Software Modules to access sensor data or control target device, we called Plugins (or Handlers we called before).

Each plugin is designed to handle specific jobs, such as:

  • Sensor Plugin: the plugin access sensor data through Sensor driver or 3rd party library, or
  • Remote Control Plugin:  the plugin execute remote command on target device.

To support customized plugins, we also defined a set of APIs, called Plugin (Handler) APIs. 

User can implement their own Handler with these Plugin (Handler) APIs to access their sensor data or control their devices and plugged by WISE Agent to communicate with RMM Server.

Architecture

RTENOTITLE

In Plugin (Handler) Architecture, the Plugin (Handler) APIs is the skin of Plugin. The WISE Agent Handler loader will link the pre-defined APIs dynamically.

The Handler Kernel Library is the bone of the Plugin. This library will handle most of the functions in a Plugin, Such as: Gat Capability, Auto Report Start/Stop, Get/Set Sensor Data and basic Threshold Rule support.

The Message Structure is the main structure to describe the sensor data and interact between Handler Kernel and Custom Data Access. In Handler Kernel, the library will generate the handshake message based on the Message Structure.

The Message Generator library provides several APIs to describe the custom sensor data in a Message Structure.

In the Custom Data Access block, user needs to implement the function to access data from 3rd party library or drivers in platform. And update the sensor data in Message Structure to report those data to the RMM Server through Handler Kernel.

Plugin (Handler) APIs

List

int Handler_Initialize( HANDLER_INFO *handler );
Description
  • This function initializes any objects or variables of this handler

Parameters

  • handler [POINTER]
    • the structure to exchange the handler information between WISE Agent and Handler.

Return Values

  • [-1|0] Error or Success.


int Handler_Get_Status( HANDLER_THREAD_STATUS * pOutStatus );
Description
  • This function will retrieve Handler Threads Status. Agent will restart current Handler or restart Agent self if busy.

Parameters

  • pOutStatus [POINTER]
    • the return status of handerl, the enumerate: 
      • handler_status_no_init = -1,
      • handler_status_init,
      • handler_status_start, 
      • handler_status_stop, 
      • handler_status_busy

Return Values

  • [-1|0] Error or Success.


void Handler_OnStatusChange( HANDLER_INFO *handler );
Description
  • This function will be called while CAgent connection status updated.

Parameters

  • handler [POINTER]
    • the pointer of Handler Info structure.

Return Values

  • None.


int Handler_Start( void );
Description
  • Start handler thread.

Parameters

  • None.

Return Values

  • [-1|0] Error or Success.


int Handler_Stop( void );
Description
  • Stop handler thread.

Parameters

  • None.

Return Values

  • [-1|0] Error or Success.


void Handler_Recv( char * const topic, void* const data, const size_t datalen, void *pRev1, void* pRev2  );
Description
  • Received Packet from Server.

Parameters

  • topic[POINTER]
    • MQTT topic string
  • data[POINTER]
    • pointer of received payload.
  • datalen[NUMBER]
    • received payload size
  • pRev1[POINTER]
    • preserved pointer.
  • pRev2[POINTER]
    • preserved pointer.

Return Values

  • None.


int Handler_Get_Capability( char ** pOutReply );
Description
  • Get Handler Information specification. 
  • Release allocated mamory by calling Handler_MemoryFree.

Parameters

  • pOutReply [POINTER]
    • double-pointer of capability string memory.

Return Values

  • [-1|0] Error or Success.




void Handler_MemoryFree(char *pInData);
Description
  • Free the mamory allocated for Handler_Get_Capability

Parameters

  • pInData[POINTER]
    • pointer of capability string memory.

Return Values

  • None.


void Handler_AutoReportStart(char *pInQuery);
Description
  • Start Auto Report

Parameters

  • pInQuery[POINTER]
    • pointer of  request string.

Return Values

  • None.


void Handler_AutoReportStop(char *pInQuery);
Description
  • Stop Auto Report

Parameters

  • pInQuery[POINTER]
    • pointer of  request string.

Return Values

  • None.

Tyep Define

Easy Implement Libraries

Mesage Generator APIs

Handler Kernel APIs

Handler Sample Code