|
@@ -2,10 +2,6 @@
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
-#ifdef _MSC_VER
|
|
|
-#pragma warning(disable:4996) // warning C4996: 'UA_Client_Subscriptions_manuallySendPublishRequest': was declared deprecated
|
|
|
-#endif
|
|
|
-
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
#include "ua_types.h"
|
|
@@ -56,18 +52,21 @@ static void teardown(void) {
|
|
|
|
|
|
UA_Boolean notificationReceived = false;
|
|
|
UA_UInt32 countNotificationReceived = 0;
|
|
|
+UA_Double publishingInterval = 500.0;
|
|
|
|
|
|
static void
|
|
|
-monitoredItemHandler(UA_Client *client, UA_UInt32 monId, UA_DataValue *value, void *context) {
|
|
|
+dataChangeHandler(UA_Client *client, UA_UInt32 subId, void *subContext,
|
|
|
+ UA_UInt32 monId, void *monContext, UA_DataValue *value) {
|
|
|
notificationReceived = true;
|
|
|
countNotificationReceived++;
|
|
|
}
|
|
|
|
|
|
static void
|
|
|
-monitoredItemHandlerSubSleep(UA_Client *client, UA_UInt32 monId, UA_DataValue *value, void *context) {
|
|
|
+dataChangeHandlerSubSleep(UA_Client *client, UA_UInt32 subId, void *subContext,
|
|
|
+ UA_UInt32 monId, void *monContext, UA_DataValue *value) {
|
|
|
notificationReceived = true;
|
|
|
countNotificationReceived++;
|
|
|
- UA_fakeSleep((UA_UInt32)(UA_SubscriptionSettings_default.requestedPublishingInterval + 2));
|
|
|
+ UA_fakeSleep((UA_UInt32)(publishingInterval + 2));
|
|
|
}
|
|
|
|
|
|
START_TEST(Client_subscription) {
|
|
@@ -75,28 +74,38 @@ START_TEST(Client_subscription) {
|
|
|
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_UInt32 subId;
|
|
|
- retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_Client_recv = client->connection.recv;
|
|
|
+ client->connection.recv = UA_Client_recvTesting;
|
|
|
+
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 subId = response.subscriptionId;
|
|
|
|
|
|
/* monitor the server state */
|
|
|
- UA_UInt32 monId;
|
|
|
- retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259),
|
|
|
- UA_ATTRIBUTEID_VALUE, monitoredItemHandler,
|
|
|
- NULL, &monId, 250);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_MonitoredItemCreateRequest monRequest =
|
|
|
+ UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ UA_MonitoredItemCreateResult monResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
|
|
+ UA_TIMESTAMPSTORETURN_BOTH,
|
|
|
+ monRequest, NULL, dataChangeHandler, NULL);
|
|
|
+ ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 monId = monResponse.monitoredItemId;
|
|
|
+
|
|
|
+ UA_fakeSleep((UA_UInt32)publishingInterval + 1);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
+
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_removeMonitoredItem(client, subId, monId);
|
|
|
+ retval = UA_Client_MonitoredItems_deleteSingle(client, subId, monId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_remove(client, subId);
|
|
|
+ retval = UA_Client_Subscriptions_deleteSingle(client, subId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
UA_Client_disconnect(client);
|
|
@@ -104,87 +113,99 @@ START_TEST(Client_subscription) {
|
|
|
}
|
|
|
END_TEST
|
|
|
|
|
|
-START_TEST(Client_subscription_addMonitoredItems) {
|
|
|
+START_TEST(Client_subscription_createDataChanges) {
|
|
|
UA_Client *client = UA_Client_new(UA_ClientConfig_default);
|
|
|
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_UInt32 subId;
|
|
|
- retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_Client_recv = client->connection.recv;
|
|
|
+ client->connection.recv = UA_Client_recvTesting;
|
|
|
+
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 subId = response.subscriptionId;
|
|
|
|
|
|
UA_MonitoredItemCreateRequest items[3];
|
|
|
- UA_MonitoredItemHandlingFunction hfs[3];
|
|
|
- void *hfContexts[3];
|
|
|
- UA_StatusCode itemResults[3];
|
|
|
UA_UInt32 newMonitoredItemIds[3];
|
|
|
+ UA_Client_DataChangeNotificationCallback callbacks[3];
|
|
|
+ UA_Client_DeleteMonitoredItemCallback deleteCallbacks[3];
|
|
|
+ void *contexts[3];
|
|
|
|
|
|
/* monitor the server state */
|
|
|
- UA_MonitoredItemCreateRequest_init(&items[0]);
|
|
|
- items[0].itemToMonitor.nodeId = UA_NODEID_NUMERIC(0, 2259);
|
|
|
- items[0].itemToMonitor.attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
- items[0].monitoringMode = UA_MONITORINGMODE_REPORTING;
|
|
|
- items[0].requestedParameters.samplingInterval = 250;
|
|
|
- items[0].requestedParameters.discardOldest = true;
|
|
|
- items[0].requestedParameters.queueSize = 1;
|
|
|
- hfs[0] = (UA_MonitoredItemHandlingFunction)(uintptr_t)monitoredItemHandler;
|
|
|
- hfContexts[0] = NULL;
|
|
|
-
|
|
|
- /* monitor current time */
|
|
|
- UA_MonitoredItemCreateRequest_init(&items[1]);
|
|
|
- items[1].itemToMonitor.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
|
|
|
- items[1].itemToMonitor.attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
- items[1].monitoringMode = UA_MONITORINGMODE_REPORTING;
|
|
|
- items[1].requestedParameters.samplingInterval = 250;
|
|
|
- items[1].requestedParameters.discardOldest = true;
|
|
|
- items[1].requestedParameters.queueSize = 1;
|
|
|
- hfs[1] = (UA_MonitoredItemHandlingFunction)(uintptr_t)monitoredItemHandler;
|
|
|
- hfContexts[1] = NULL;
|
|
|
+ items[0] = UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
|
|
|
+ callbacks[0] = dataChangeHandler;
|
|
|
+ contexts[0] = NULL;
|
|
|
+ deleteCallbacks[0] = NULL;
|
|
|
|
|
|
/* monitor invalid node */
|
|
|
- UA_MonitoredItemCreateRequest_init(&items[2]);
|
|
|
- items[2].itemToMonitor.nodeId = UA_NODEID_NUMERIC(0, 99999999);
|
|
|
- items[2].itemToMonitor.attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
- items[2].monitoringMode = UA_MONITORINGMODE_REPORTING;
|
|
|
- items[2].requestedParameters.samplingInterval = 250;
|
|
|
- items[2].requestedParameters.discardOldest = true;
|
|
|
- items[2].requestedParameters.queueSize = 1;
|
|
|
- hfs[2] = (UA_MonitoredItemHandlingFunction)(uintptr_t)monitoredItemHandler;
|
|
|
- hfContexts[2] = NULL;
|
|
|
-
|
|
|
- retval = UA_Client_Subscriptions_addMonitoredItems(client, subId, items, 3,
|
|
|
- hfs, hfContexts, itemResults,
|
|
|
- newMonitoredItemIds);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[0], UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[1], UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[2], UA_STATUSCODE_BADNODEIDUNKNOWN);
|
|
|
+ items[1] = UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, 999999));
|
|
|
+ callbacks[1] = dataChangeHandler;
|
|
|
+ contexts[1] = NULL;
|
|
|
+ deleteCallbacks[1] = NULL;
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ /* monitor current time */
|
|
|
+ items[2] = UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME));
|
|
|
+ callbacks[2] = dataChangeHandler;
|
|
|
+ contexts[2] = NULL;
|
|
|
+ deleteCallbacks[2] = NULL;
|
|
|
+
|
|
|
+ UA_CreateMonitoredItemsRequest createRequest;
|
|
|
+ UA_CreateMonitoredItemsRequest_init(&createRequest);
|
|
|
+ createRequest.subscriptionId = subId;
|
|
|
+ createRequest.timestampsToReturn = UA_TIMESTAMPSTORETURN_BOTH;
|
|
|
+ createRequest.itemsToCreate = items;
|
|
|
+ createRequest.itemsToCreateSize = 3;
|
|
|
+ UA_CreateMonitoredItemsResponse createResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChanges(client, createRequest, contexts,
|
|
|
+ callbacks, deleteCallbacks);
|
|
|
+
|
|
|
+ ck_assert_uint_eq(createResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ ck_assert_uint_eq(createResponse.resultsSize, 3);
|
|
|
+ ck_assert_uint_eq(createResponse.results[0].statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ newMonitoredItemIds[0] = createResponse.results[0].monitoredItemId;
|
|
|
+ ck_assert_uint_eq(createResponse.results[1].statusCode, UA_STATUSCODE_BADNODEIDUNKNOWN);
|
|
|
+ newMonitoredItemIds[1] = createResponse.results[1].monitoredItemId;
|
|
|
+ ck_assert_uint_eq(newMonitoredItemIds[1], 0);
|
|
|
+ ck_assert_uint_eq(createResponse.results[2].statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ newMonitoredItemIds[2] = createResponse.results[2].monitoredItemId;
|
|
|
+ ck_assert_uint_eq(createResponse.results[2].statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ UA_CreateMonitoredItemsResponse_deleteMembers(&createResponse);
|
|
|
+
|
|
|
+ UA_fakeSleep((UA_UInt32)publishingInterval + 1);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
countNotificationReceived = 0;
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 2);
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
-
|
|
|
notificationReceived = false;
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 3);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_removeMonitoredItems(client, subId, newMonitoredItemIds,
|
|
|
- 3, itemResults);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[0], UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[1], UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[2], UA_STATUSCODE_BADMONITOREDITEMIDINVALID);
|
|
|
+ UA_DeleteMonitoredItemsRequest deleteRequest;
|
|
|
+ UA_DeleteMonitoredItemsRequest_init(&deleteRequest);
|
|
|
+ deleteRequest.subscriptionId = subId;
|
|
|
+ deleteRequest.monitoredItemIds = newMonitoredItemIds;
|
|
|
+ deleteRequest.monitoredItemIdsSize = 3;
|
|
|
+
|
|
|
+ UA_DeleteMonitoredItemsResponse deleteResponse =
|
|
|
+ UA_Client_MonitoredItems_delete(client, deleteRequest);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_remove(client, subId);
|
|
|
+ ck_assert_uint_eq(deleteResponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ ck_assert_uint_eq(deleteResponse.resultsSize, 3);
|
|
|
+ ck_assert_uint_eq(deleteResponse.results[0], UA_STATUSCODE_GOOD);
|
|
|
+ ck_assert_uint_eq(deleteResponse.results[1], UA_STATUSCODE_BADMONITOREDITEMIDINVALID);
|
|
|
+ ck_assert_uint_eq(deleteResponse.results[2], UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ UA_DeleteMonitoredItemsResponse_deleteMembers(&deleteResponse);
|
|
|
+
|
|
|
+ retval = UA_Client_Subscriptions_deleteSingle(client, subId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
UA_Client_disconnect(client);
|
|
@@ -197,61 +218,56 @@ START_TEST(Client_subscription_keepAlive) {
|
|
|
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_UInt32 subId;
|
|
|
- retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
-
|
|
|
- UA_MonitoredItemCreateRequest items[1];
|
|
|
- UA_MonitoredItemHandlingFunction hfs[1];
|
|
|
- void *hfContexts[1];
|
|
|
- UA_StatusCode itemResults[1];
|
|
|
- UA_UInt32 newMonitoredItemIds[1];
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ request.requestedMaxKeepAliveCount = 1;
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 subId = response.subscriptionId;
|
|
|
|
|
|
/* monitor the server state */
|
|
|
- UA_MonitoredItemCreateRequest_init(&items[0]);
|
|
|
- items[0].itemToMonitor.nodeId = UA_NODEID_NUMERIC(0, 2259);
|
|
|
- items[0].itemToMonitor.attributeId = UA_ATTRIBUTEID_VALUE;
|
|
|
- items[0].monitoringMode = UA_MONITORINGMODE_REPORTING;
|
|
|
- items[0].requestedParameters.samplingInterval = 250;
|
|
|
- items[0].requestedParameters.discardOldest = true;
|
|
|
- items[0].requestedParameters.queueSize = 1;
|
|
|
- hfs[0] = (UA_MonitoredItemHandlingFunction)(uintptr_t)monitoredItemHandler;
|
|
|
- hfContexts[0] = NULL;
|
|
|
-
|
|
|
- retval = UA_Client_Subscriptions_addMonitoredItems(client, subId, items, 1,
|
|
|
- hfs, hfContexts, itemResults,
|
|
|
- newMonitoredItemIds);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(itemResults[0], UA_STATUSCODE_GOOD);
|
|
|
+ UA_MonitoredItemCreateRequest monRequest =
|
|
|
+ UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ UA_MonitoredItemCreateResult monResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
|
|
+ UA_TIMESTAMPSTORETURN_BOTH,
|
|
|
+ monRequest, NULL, dataChangeHandler, NULL);
|
|
|
+ ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 monId = monResponse.monitoredItemId;
|
|
|
|
|
|
- UA_PublishRequest request;
|
|
|
- UA_PublishRequest_init(&request);
|
|
|
- request.subscriptionAcknowledgementsSize = 0;
|
|
|
+ UA_fakeSleep((UA_UInt32)(publishingInterval + 1));
|
|
|
|
|
|
- UA_PublishResponse response = UA_Client_Service_publish(client, request);
|
|
|
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(response.notificationMessage.notificationDataSize, 1);
|
|
|
- UA_PublishResponse_deleteMembers(&response);
|
|
|
- UA_PublishRequest_deleteMembers(&request);
|
|
|
+ /* Manually send a publish request */
|
|
|
+ UA_PublishRequest pr;
|
|
|
+ UA_PublishRequest_init(&pr);
|
|
|
+ pr.subscriptionAcknowledgementsSize = 0;
|
|
|
+ UA_PublishResponse presponse;
|
|
|
+ UA_PublishResponse_init(&presponse);
|
|
|
+ __UA_Client_Service(client, &pr, &UA_TYPES[UA_TYPES_PUBLISHREQUEST],
|
|
|
+ &presponse, &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
|
|
|
+ ck_assert_uint_eq(presponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ ck_assert_uint_eq(presponse.notificationMessage.notificationDataSize, 1);
|
|
|
+ UA_PublishResponse_deleteMembers(&presponse);
|
|
|
+ UA_PublishRequest_deleteMembers(&pr);
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ UA_fakeSleep((UA_UInt32)(publishingInterval + 1));
|
|
|
|
|
|
- /* by default maxKeepAlive is set to 1 we must receive a response without notification message */
|
|
|
- UA_PublishRequest_init(&request);
|
|
|
- request.subscriptionAcknowledgementsSize = 0;
|
|
|
+ UA_PublishRequest_init(&pr);
|
|
|
+ pr.subscriptionAcknowledgementsSize = 0;
|
|
|
+ UA_PublishResponse_init(&presponse);
|
|
|
+ __UA_Client_Service(client, &pr, &UA_TYPES[UA_TYPES_PUBLISHREQUEST],
|
|
|
+ &presponse, &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
|
|
|
|
|
|
- response = UA_Client_Service_publish(client, request);
|
|
|
- ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
- ck_assert_uint_eq(response.notificationMessage.notificationDataSize, 0);
|
|
|
- UA_PublishResponse_deleteMembers(&response);
|
|
|
- UA_PublishRequest_deleteMembers(&request);
|
|
|
+ ck_assert_uint_eq(presponse.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ ck_assert_uint_eq(presponse.notificationMessage.notificationDataSize, 0);
|
|
|
+ UA_PublishResponse_deleteMembers(&presponse);
|
|
|
+ UA_PublishRequest_deleteMembers(&pr);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_removeMonitoredItem(client, subId, newMonitoredItemIds[0]);
|
|
|
+ retval = UA_Client_MonitoredItems_deleteSingle(client, subId, monId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_remove(client, subId);
|
|
|
+ retval = UA_Client_Subscriptions_deleteSingle(client, subId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
UA_Client_disconnect(client);
|
|
@@ -264,30 +280,34 @@ START_TEST(Client_subscription_connectionClose) {
|
|
|
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_UInt32 subId;
|
|
|
- retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_Client_recv = client->connection.recv;
|
|
|
+ client->connection.recv = UA_Client_recvTesting;
|
|
|
+
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
/* monitor the server state */
|
|
|
- UA_UInt32 monId;
|
|
|
- retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259),
|
|
|
- UA_ATTRIBUTEID_VALUE, monitoredItemHandler,
|
|
|
- NULL, &monId, 250);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_MonitoredItemCreateRequest monRequest =
|
|
|
+ UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ UA_MonitoredItemCreateResult monResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
|
|
+ UA_TIMESTAMPSTORETURN_BOTH,
|
|
|
+ monRequest, NULL, dataChangeHandler, NULL);
|
|
|
+ ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_fakeSleep((UA_UInt32)publishingInterval + 1);
|
|
|
|
|
|
- UA_Client_recv = client->connection.recv;
|
|
|
- client->connection.recv = UA_Client_recvTesting;
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 60));
|
|
|
+ ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
/* Simulate BADCONNECTIONCLOSE */
|
|
|
UA_Client_recvTesting_result = UA_STATUSCODE_BADCONNECTIONCLOSED;
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_BADSERVERNOTCONNECTED);
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 60));
|
|
|
+ ck_assert_uint_eq(retval, UA_STATUSCODE_BADCONNECTIONCLOSED);
|
|
|
|
|
|
UA_Client_disconnect(client);
|
|
|
UA_Client_delete(client);
|
|
@@ -299,35 +319,44 @@ START_TEST(Client_subscription_without_notification) {
|
|
|
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_UInt32 subId;
|
|
|
- retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_Client_recv = client->connection.recv;
|
|
|
+ client->connection.recv = UA_Client_recvTesting;
|
|
|
+
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ request.requestedMaxKeepAliveCount = 1;
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 subId = response.subscriptionId;
|
|
|
|
|
|
/* monitor the server state */
|
|
|
- UA_UInt32 monId;
|
|
|
- retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259),
|
|
|
- UA_ATTRIBUTEID_VALUE, monitoredItemHandler,
|
|
|
- NULL, &monId, 9999999);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_MonitoredItemCreateRequest monRequest =
|
|
|
+ UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
|
|
|
+ monRequest.requestedParameters.samplingInterval = 99999999.0;
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ UA_MonitoredItemCreateResult monResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
|
|
+ UA_TIMESTAMPSTORETURN_BOTH,
|
|
|
+ monRequest, NULL, dataChangeHandler, NULL);
|
|
|
+ UA_UInt32 monId = monResponse.monitoredItemId;
|
|
|
+ ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ UA_fakeSleep((UA_UInt32)publishingInterval + 1);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
-
|
|
|
notificationReceived = false;
|
|
|
- retval = UA_Client_Subscriptions_manuallySendPublishRequest(client);
|
|
|
+ retval = UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
ck_assert_uint_eq(notificationReceived, false);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_removeMonitoredItem(client, subId, monId);
|
|
|
+ retval = UA_Client_MonitoredItems_deleteSingle(client, subId, monId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- retval = UA_Client_Subscriptions_remove(client, subId);
|
|
|
+ retval = UA_Client_Subscriptions_deleteSingle(client, subId);
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
UA_Client_disconnect(client);
|
|
@@ -343,16 +372,25 @@ stateCallback (UA_Client *client, UA_ClientState clientState){
|
|
|
|
|
|
if (clientState == UA_CLIENTSTATE_SESSION){
|
|
|
/* A new session was created. We need to create the subscription. */
|
|
|
- /* Create a subscription */
|
|
|
- UA_UInt32 subId = 0;
|
|
|
- UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ request.requestedMaxKeepAliveCount = 1;
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 subId = response.subscriptionId;
|
|
|
ck_assert_uint_ne(subId, 0);
|
|
|
|
|
|
/* Add a MonitoredItem */
|
|
|
- UA_UInt32 monId = 0;
|
|
|
- UA_NodeId monitorThis = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
|
|
|
- UA_Client_Subscriptions_addMonitoredItem(client, subId, monitorThis, UA_ATTRIBUTEID_VALUE,
|
|
|
- &monitoredItemHandlerSubSleep, NULL, &monId, 250);
|
|
|
+ UA_MonitoredItemCreateRequest monRequest =
|
|
|
+ UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME));
|
|
|
+
|
|
|
+ UA_MonitoredItemCreateResult monResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
|
|
+ UA_TIMESTAMPSTORETURN_BOTH,
|
|
|
+ monRequest, NULL, dataChangeHandlerSubSleep, NULL);
|
|
|
+ ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 monId = monResponse.monitoredItemId;
|
|
|
+
|
|
|
ck_assert_uint_ne(monId, 0);
|
|
|
}
|
|
|
}
|
|
@@ -372,50 +410,44 @@ START_TEST(Client_subscription_async_sub) {
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
ck_assert_uint_eq(callbackClientState, UA_CLIENTSTATE_SESSION);
|
|
|
|
|
|
- UA_fakeSleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1);
|
|
|
+ UA_Client_recv = client->connection.recv;
|
|
|
+ client->connection.recv = UA_Client_recvTesting;
|
|
|
+
|
|
|
+ UA_fakeSleep((UA_UInt32)publishingInterval + 1);
|
|
|
|
|
|
countNotificationReceived = 0;
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)(UA_SubscriptionSettings_default.requestedPublishingInterval + 1));
|
|
|
+ UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 1);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)(UA_SubscriptionSettings_default.requestedPublishingInterval + 1));
|
|
|
+ UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 2);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)(UA_SubscriptionSettings_default.requestedPublishingInterval + 1));
|
|
|
+ UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 3);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)(UA_SubscriptionSettings_default.requestedPublishingInterval + 1));
|
|
|
+ UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 4);
|
|
|
|
|
|
notificationReceived = false;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)(UA_SubscriptionSettings_default.requestedPublishingInterval + 1));
|
|
|
+ UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(notificationReceived, true);
|
|
|
ck_assert_uint_eq(countNotificationReceived, 5);
|
|
|
|
|
|
ck_assert_uint_lt(client->config.outStandingPublishRequests, 10);
|
|
|
|
|
|
- UA_Client_recv = client->connection.recv;
|
|
|
- client->connection.recv = UA_Client_recvTesting;
|
|
|
-
|
|
|
notificationReceived = false;
|
|
|
/* Simulate network cable unplugged (no response from server) */
|
|
|
UA_Client_recvTesting_result = UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)(UA_SubscriptionSettings_default.requestedPublishingInterval + 1));
|
|
|
- ck_assert_uint_eq(notificationReceived, false);
|
|
|
- ck_assert_uint_eq(callbackClientState, UA_CLIENTSTATE_SESSION);
|
|
|
-
|
|
|
- /* Simulate network cable unplugged (no response from server) */
|
|
|
- UA_Client_recvTesting_result = UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
|
|
|
- UA_Client_runAsync(client, (UA_UInt16)clientConfig.timeout);
|
|
|
+ UA_Client_runAsync(client, (UA_UInt16)(publishingInterval + 1));
|
|
|
ck_assert_uint_eq(notificationReceived, false);
|
|
|
ck_assert_uint_eq(callbackClientState, UA_CLIENTSTATE_SESSION);
|
|
|
|
|
@@ -434,15 +466,23 @@ START_TEST(Client_methodcall) {
|
|
|
UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
|
|
|
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
|
|
|
- UA_UInt32 subId;
|
|
|
- retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_CreateSubscriptionRequest request = UA_CreateSubscriptionRequest_default();
|
|
|
+ UA_CreateSubscriptionResponse response = UA_Client_Subscriptions_create(client, request,
|
|
|
+ NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(response.responseHeader.serviceResult, UA_STATUSCODE_GOOD);
|
|
|
+ UA_UInt32 subId = response.subscriptionId;
|
|
|
|
|
|
/* monitor the server state */
|
|
|
- UA_UInt32 monId;
|
|
|
- retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259),
|
|
|
- UA_ATTRIBUTEID_VALUE, NULL, NULL, &monId, 250);
|
|
|
- ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
|
|
|
+ UA_MonitoredItemCreateRequest monRequest =
|
|
|
+ UA_MonitoredItemCreateRequest_default(UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE));
|
|
|
+
|
|
|
+ UA_MonitoredItemCreateResult monResponse =
|
|
|
+ UA_Client_MonitoredItems_createDataChange(client, response.subscriptionId,
|
|
|
+ UA_TIMESTAMPSTORETURN_BOTH,
|
|
|
+ monRequest, NULL, NULL, NULL);
|
|
|
+ ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
|
|
+
|
|
|
+ UA_UInt32 monId = monResponse.monitoredItemId;
|
|
|
|
|
|
/* call a method to get monitored item id */
|
|
|
UA_Variant input;
|
|
@@ -487,7 +527,7 @@ static Suite* testSuite_Client(void) {
|
|
|
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
|
|
tcase_add_test(tc_client, Client_subscription);
|
|
|
tcase_add_test(tc_client, Client_subscription_connectionClose);
|
|
|
- tcase_add_test(tc_client, Client_subscription_addMonitoredItems);
|
|
|
+ tcase_add_test(tc_client, Client_subscription_createDataChanges);
|
|
|
tcase_add_test(tc_client, Client_subscription_keepAlive);
|
|
|
tcase_add_test(tc_client, Client_subscription_without_notification);
|
|
|
tcase_add_test(tc_client, Client_subscription_async_sub);
|