Преглед на файлове

Merge pull request #479 from Aleskey78/subscriptions_monitor_cb_context

Adding context to a monitored item handling function in the client
Julius Pfrommer преди 9 години
родител
ревизия
b3459d09d7
променени са 4 файла, в които са добавени 9 реда и са изтрити 5 реда
  1. 1 1
      examples/client.c
  2. 2 1
      include/ua_client_highlevel.h
  3. 4 2
      src/client/ua_client_highlevel_subscriptions.c
  4. 2 1
      src/client/ua_client_internal.h

+ 1 - 1
examples/client.c

@@ -72,7 +72,7 @@ int main(int argc, char *argv[]) {
     UA_NodeId monitorThis = UA_NODEID_STRING(1, "the.answer");
     UA_UInt32 monId;
     UA_Client_Subscriptions_addMonitoredItem(client, subId, monitorThis,
-                                             UA_ATTRIBUTEID_VALUE, &handler_TheAnswerChanged, &monId);
+                                             UA_ATTRIBUTEID_VALUE, &handler_TheAnswerChanged, NULL, &monId);
     if (monId)
         printf("Monitoring 'the.answer', id %u\n", subId);
     

+ 2 - 1
include/ua_client_highlevel.h

@@ -280,7 +280,8 @@ void UA_EXPORT UA_Client_Subscriptions_manuallySendPublishRequest(UA_Client *cli
 UA_StatusCode UA_EXPORT
 UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,
                                          UA_NodeId nodeId, UA_UInt32 attributeID,
-                                         void *handlingFunction, UA_UInt32 *newMonitoredItemId);
+                                         void *handlingFunction, void *handlingContext,
+                                         UA_UInt32 *newMonitoredItemId);
 
 UA_StatusCode UA_EXPORT
 UA_Client_Subscriptions_removeMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,

+ 4 - 2
src/client/ua_client_highlevel_subscriptions.c

@@ -91,7 +91,8 @@ UA_StatusCode UA_Client_Subscriptions_remove(UA_Client *client, UA_UInt32 subscr
 UA_StatusCode
 UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,
                                          UA_NodeId nodeId, UA_UInt32 attributeID,
-                                         void *handlingFunction, UA_UInt32 *newMonitoredItemId) {
+                                         void *handlingFunction, void *handlingContext,
+                                         UA_UInt32 *newMonitoredItemId) {
     UA_Client_Subscription *sub;
     LIST_FOREACH(sub, &client->subscriptions, listEntry) {
         if(sub->SubscriptionID == subscriptionId)
@@ -135,6 +136,7 @@ UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscripti
         newMon->QueueSize = 1;
         newMon->DiscardOldest = UA_TRUE;
         newMon->handler = handlingFunction;
+        newMon->handlerContext = handlingContext;
         newMon->MonitoredItemId = response.results[0].monitoredItemId;
         LIST_INSERT_HEAD(&sub->MonitoredItems, newMon, listEntry);
         *newMonitoredItemId = newMon->MonitoredItemId;
@@ -233,7 +235,7 @@ UA_Client_processPublishRx(UA_Client *client, UA_PublishResponse response) {
                 // find this client handle
                 LIST_FOREACH(mon, &sub->MonitoredItems, listEntry) {
                     if(mon->ClientHandle == mitemNot->clientHandle) {
-                        mon->handler(mitemNot->clientHandle, &mitemNot->value);
+                        mon->handler(mitemNot->clientHandle, &mitemNot->value, mon->handlerContext);
                         break;
                     }
                 }

+ 2 - 1
src/client/ua_client_internal.h

@@ -24,7 +24,8 @@ typedef struct UA_Client_MonitoredItem_s {
     UA_UInt32          SamplingInterval;
     UA_UInt32          QueueSize;
     UA_Boolean         DiscardOldest;
-    void               (*handler)(UA_UInt32 handle, UA_DataValue *value);
+    void               (*handler)(UA_UInt32 handle, UA_DataValue *value, void *context);
+    void               *handlerContext;
     LIST_ENTRY(UA_Client_MonitoredItem_s)  listEntry;
 } UA_Client_MonitoredItem;