Browse Source

intermediate commit of basic structs and function prototypes for client subscription management

ichrispa 9 years ago
parent
commit
a7f481d9d4
3 changed files with 88 additions and 3 deletions
  1. 6 1
      examples/client.c
  2. 37 0
      include/ua_client.h
  3. 45 2
      src/client/ua_client.c

+ 6 - 1
examples/client.c

@@ -93,7 +93,12 @@ int main(int argc, char *argv[]) {
 
     UA_WriteRequest_deleteMembers(&wReq);
     UA_WriteResponse_deleteMembers(&wResp);
-
+    
+    // Create a subscription
+    UA_Int32 subId = UA_Client_newSubscription(client);
+    if (subId)
+        printf("Create subscription succeeded, id %u\n", subId);
+    
     UA_Client_disconnect(client);
     UA_Client_delete(client);
     return UA_STATUSCODE_GOOD;

+ 37 - 0
include/ua_client.h

@@ -61,4 +61,41 @@ UA_DeleteReferencesResponse UA_EXPORT
 } // extern "C"
 #endif
 
+
+#ifdef ENABLE_SUBSCRIPTIONS
+
+typedef struct UA_Client_MonitoredItem_s {
+    UA_UInt32          ItemId;
+    UA_UInt32          TimestampsToReturn;
+    UA_UInt32          MonitoringMode;
+    UA_NodeId          monitoredNodeId; 
+    UA_UInt32          AttributeID;
+    UA_UInt32          ClientHandle;
+    UA_UInt32          SamplingInterval;
+    UA_UInt32          QueueSize;
+    UA_Boolean         DiscardOldest;
+    LIST_ENTRY(UA_Client_MonitoredItem_s)  listEntry;
+} UA_Client_MonitoredItem;
+
+typedef struct UA_Client_Subscription_s {
+    UA_UInt32    LifeTime;
+    UA_Int32     KeepAliveCount;
+    UA_DateTime  PublishingInterval;
+    UA_Int32     SubscriptionID;
+    UA_Int32     NotificationsPerPublish;
+    UA_Boolean   PublishingMode;
+    UA_UInt32    Priority;
+    LIST_ENTRY(UA_Client_Subscription_s) listEntry; //?
+    LIST_HEAD(UA_ListOfUAMonitoredItems, UA_MonitoredItem_s) MonitoredItems;
+} UA_Client_Subscription;
+
+UA_CreateSubscriptionResponse UA_EXPORT UA_Client_createSubscription(UA_Client *client, UA_CreateSubscriptionRequest *request);
+
+UA_Int32 UA_EXPORT UA_Client_newSubscription(UA_Client *client);
+void UA_EXPORT UA_Client_modifySubscription(UA_Client *client);
+void UA_EXPORT UA_Client_addMonitoredItem(UA_Client *client);
+void UA_EXPORT UA_Client_publish(UA_Client *client);
+void UA_EXPORT UA_Client_removeMonitoredItem(UA_Client *client);
+void UA_EXPORT UA_Client_deleteSubscription(UA_Client *client);
+#endif
 #endif /* UA_CLIENT_H_ */

+ 45 - 2
src/client/ua_client.c

@@ -16,7 +16,11 @@ struct UA_Client {
     UA_UserTokenPolicy token;
     UA_NodeId sessionId;
     UA_NodeId authenticationToken;
-
+    
+#ifdef ENABLE_SUBSCRIPTIONS
+    LIST_HEAD(UA_ListOfClientSubscriptionItems, UA_Client_Subscription_s) subscriptions;
+#endif
+    
     /* Config */
     UA_Logger logger;
     UA_ClientConfig config;
@@ -44,7 +48,10 @@ UA_Client * UA_Client_new(UA_ClientConfig config, UA_Logger logger) {
     client->logger = logger;
     client->config = config;
     client->scExpiresAt = 0;
-    
+
+#ifdef ENABLE_SUBSCRIPTIONS
+    LIST_INIT(&client->subscriptions);
+#endif
     return client;
 }
 
@@ -545,3 +552,39 @@ UA_DeleteReferencesResponse UA_Client_deleteReferences(UA_Client *client, UA_Del
                        &response, &UA_TYPES[UA_TYPES_DELETEREFERENCESRESPONSE]);
     return response;
 }
+
+#ifdef ENABLE_SUBSCRIPTIONS
+UA_CreateSubscriptionResponse UA_Client_createSubscription(UA_Client *client, UA_CreateSubscriptionRequest *request) {
+    UA_CreateSubscriptionResponse response;
+    synchronousRequest(client, request, &UA_TYPES[UA_TYPES_CREATESUBSCRIPTIONREQUEST],
+                       &response, &UA_TYPES[UA_TYPES_CREATESUBSCRIPTIONRESPONSE]);
+    return response;
+}
+
+UA_Int32 UA_Client_newSubscription(UA_Client *client) {
+    UA_CreateSubscriptionRequest aReq;
+    UA_CreateSubscriptionResponse aRes;
+    UA_CreateSubscriptionRequest_init(&aReq);
+    UA_CreateSubscriptionResponse_init(&aRes);
+    
+    aReq.maxNotificationsPerPublish = 10;
+    aReq.priority = 0;
+    aReq.publishingEnabled = UA_TRUE;
+    aReq.requestedLifetimeCount = 100;
+    aReq.requestedMaxKeepAliveCount = 10;
+    aReq.requestedPublishingInterval = 100;
+    
+    UA_Client_createSubscription(client, &aReq);
+    
+    printf("Subscription ID: %u\n", aRes.subscriptionId);
+    UA_CreateSubscriptionResponse_deleteMembers(&aRes);
+    UA_CreateSubscriptionRequest_deleteMembers(&aReq);
+    return 0;
+}
+
+void UA_Client_modifySubscription(UA_Client *client) {}
+void UA_Client_addMonitoredItem(UA_Client *client) {}
+void UA_Client_publish(UA_Client *client) {}
+void UA_Client_removeMonitoredItem(UA_Client *client) {}
+void UA_Client_deleteSubscription(UA_Client *client) {}
+#endif