diff options
Diffstat (limited to 'libccnx-transport-rta/ccnx/api/notify')
10 files changed, 841 insertions, 0 deletions
diff --git a/libccnx-transport-rta/ccnx/api/notify/CMakeLists.txt b/libccnx-transport-rta/ccnx/api/notify/CMakeLists.txt new file mode 100644 index 00000000..d22e4db3 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/CMakeLists.txt @@ -0,0 +1,39 @@ +# Define a few configuration variables that we want accessible in the software + +set(CCNX_API_NOTIFY_HEADERS + ccnxNotifyAPI_About.h + notify_Status.h + notify_Timer.h +) + +set(CCNX_API_NOTIFY_SOURCE_FILES + ccnxNotifyAPI_About.c + notify_Status.c +) + + +add_library(ccnx_api_notify STATIC ${CCNX_API_NOTIFY_SOURCE_FILES} ${CCNX_API_NOTIFY_HEADERS}) +add_library(ccnx_api_notify.shared SHARED ${CCNX_API_NOTIFY_SOURCE_FILES}) + +source_group(Sources FILES ${CCNX_API_NOTIFY_SOURCE_FILES}) +source_group(Sources FILES ${CCNX_API_NOTIFY_HEADERS}) + +set_target_properties(ccnx_api_notify.shared PROPERTIES + C_STANDARD 99 + SOVERSION 1 + VERSION 1.0 + OUTPUT_NAME ccnx_api_notify ) + +set(libccnx_api_notify_libraries + ccnx_api_notify + ccnx_api_notify.shared + ) + +foreach(lib ${libccnx_api_notify_libraries}) + install(TARGETS ${lib} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + set_property(TARGET ${lib} PROPERTY C_STANDARD 99) +endforeach() + +install(FILES ${CCNX_API_NOTIFY_HEADERS} DESTINATION include/ccnx/api/notify ) + +#add_subdirectory(test) diff --git a/libccnx-transport-rta/ccnx/api/notify/README b/libccnx-transport-rta/ccnx/api/notify/README new file mode 100644 index 00000000..a2eb8879 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/README @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +API to handle notifications from the Transport. These notifications +are specific to the RTA Transport, in that they use the Component +model and Component names. + diff --git a/libccnx-transport-rta/ccnx/api/notify/ccnxNotifyAPI_About.c b/libccnx-transport-rta/ccnx/api/notify/ccnxNotifyAPI_About.c new file mode 100644 index 00000000..25772c22 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/ccnxNotifyAPI_About.c @@ -0,0 +1,44 @@ +// DO NOT EDIT THIS FILE. IT IS AUTOMATICALLY GENERATED. +// longbow-generate-about 1.0.20170215.54ef86fe 2017-02-15T09:29:05Z + +#include "ccnxNotifyAPI_About.h" + +const char *ccnxNotifyAPI_What = "@(#)" "ccnxNotifyAPI " RELEASE_VERSION " 2017-02-20T14:20:21.238467" + "@(#)" "\tCopyright (c) 2017 Cisco and/or its affiliates."; + +const char * +ccnxNotifyAPIAbout_Name(void) +{ + return "ccnxNotifyAPI"; +} + +const char * +ccnxNotifyAPIAbout_Version(void) +{ + return RELEASE_VERSION; +} + +const char * +ccnxNotifyAPIAbout_About(void) +{ + return "ccnxNotifyAPI "RELEASE_VERSION " 2017-02-20T14:20:21.238467" "\nCopyright (c) 2017 Cisco and/or its affiliates.\n"; +} + +const char * +ccnxNotifyAPIAbout_MiniNotice(void) +{ + return "Copyright (c) 2017 Cisco and/or its affiliates.\n"; +} + +const char * +ccnxNotifyAPIAbout_ShortNotice(void) +{ + return "Copyright (c) 2017 Cisco and/or its affiliates.\n"; +} + +const char * +ccnxNotifyAPIAbout_LongNotice(void) +{ + return "Copyright (c) 2017 Cisco and/or its affiliates.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at:\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n"; +} + diff --git a/libccnx-transport-rta/ccnx/api/notify/ccnxNotifyAPI_About.h b/libccnx-transport-rta/ccnx/api/notify/ccnxNotifyAPI_About.h new file mode 100644 index 00000000..07d9ff50 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/ccnxNotifyAPI_About.h @@ -0,0 +1,54 @@ +// DO NOT EDIT THIS FILE. IT IS AUTOMATICALLY GENERATED. +// longbow-generate-about 1.0.20170215.54ef86fe 2017-02-15T09:29:05Z + +#ifndef ccnxNotifyAPI_About_h +#define ccnxNotifyAPI_About_h +/** + * Embedded string containing information for the what(1) command. + * + */ +extern const char *ccnxNotifyAPI_What; + +/** + * Return the name as a C string. + * + * @return The name as a C string. + */ +const char *ccnxNotifyAPIAbout_Name(void); + +/** + * Return the version as a C string. + * + * @return The version as a C string. + */ +const char *ccnxNotifyAPIAbout_Version(void); + +/** + * Return the About text as a C string. + * + * @return The About text as a C string. + */ +const char *ccnxNotifyAPIAbout_About(void); + +/** + * Return the minimum copyright notice as a C string. + * + * @return The minimum copyright notice as a C string. + */ +const char *ccnxNotifyAPIAbout_MiniNotice(void); + +/** + * Return the short copyright notice as a C string. + * + * @return The short copyright notice as a C string. + */ +const char *ccnxNotifyAPIAbout_ShortNotice(void); + +/** + * Return the long copyright notice as a C string. + * + * @return The long copyright notice as a C string. + */ +const char *ccnxNotifyAPIAbout_LongNotice(void); + +#endif // ccnxNotifyAPI_About_h diff --git a/libccnx-transport-rta/ccnx/api/notify/notify_Status.c b/libccnx-transport-rta/ccnx/api/notify/notify_Status.c new file mode 100644 index 00000000..25ade9fb --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/notify_Status.c @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> + +#include <stdio.h> +#include <string.h> + +#include <parc/algol/parc_DisplayIndented.h> +#include <parc/algol/parc_Object.h> +#include <parc/algol/parc_Memory.h> +#include <parc/algol/parc_JSON.h> + +#include <ccnx/api/notify/notify_Status.h> + +// These string constants are used in the JSON configuration + +static const char jsonNotifyStatus[] = "notifyStatus"; +static const char param_CONNECTION[] = "connectionId"; +static const char param_CODE[] = "statusCode"; +static const char param_NAME[] = "name"; +static const char param_MESSAGE[] = "message"; + +struct notify_status { + int apiFd; + NotifyStatusCode code; + CCNxName *name; + char *message; +}; + +static void +_notifyStatus_Destroy(NotifyStatus **notifyStatusPtr) +{ + NotifyStatus *status = *notifyStatusPtr; + if (status->name) { + ccnxName_Release(&status->name); + } + if (status->message) { + parcMemory_Deallocate((void **) &status->message); + } +} + +parcObject_ExtendPARCObject(NotifyStatus, _notifyStatus_Destroy, NULL, NULL, notifyStatus_Equals, NULL, NULL, NULL); + +parcObject_ImplementAcquire(notifyStatus, NotifyStatus); + +parcObject_ImplementRelease(notifyStatus, NotifyStatus); + +NotifyStatus * +notifyStatus_Create(int apiFd, NotifyStatusCode code, CCNxName *name, const char *message) +{ + NotifyStatus *result = parcObject_CreateInstance(NotifyStatus); + result->apiFd = apiFd; + result->code = code; + result->name = name == NULL ? NULL : ccnxName_Acquire(name); + result->message = message == NULL ? NULL : parcMemory_StringDuplicate(message, strlen(message)); + + return result; +} + +static bool +_StringEquals(const char *x, const char *y) +{ + if (x == y) { + return true; + } + if (x == NULL || y == NULL) { + return false; + } + return strcmp(x, y) == 0; +} + +bool +notifyStatus_Equals(const NotifyStatus *x, const NotifyStatus *y) +{ + if (x == y) { + return true; + } + if (x == NULL || y == NULL) { + return false; + } + + if (x->apiFd == y->apiFd) { + if (x->code == y->code) { + if (_StringEquals(x->message, y->message)) { + if (ccnxName_Equals(x->name, y->name)) { + return true; + } + } + } + } + return false; +} + +int +notifyStatus_GetFiledes(const NotifyStatus *status) +{ + return status->apiFd; +} + +NotifyStatusCode +notifyStatus_GetStatusCode(const NotifyStatus *status) +{ + return status->code; +} + +CCNxName * +notifyStatus_GetName(const NotifyStatus *status) +{ + return status->name; +} + +char * +notifyStatus_GetMessage(const NotifyStatus *status) +{ + return status->message; +} + +void +notifyStatus_Display(const NotifyStatus *status, int indentation) +{ + parcDisplayIndented_PrintLine(indentation, "NotifyStatus%p { .apiFd=%d, .code=%d ", status, status->apiFd, status->code); + ccnxName_Display(status->name, indentation + 1); + parcDisplayIndented_PrintLine(indentation, ".message=\"%s\"\n", status->message); +} + +bool +notifyStatus_IsConnectionOpen(const NotifyStatus *status) +{ + return status->code == notifyStatusCode_CONNECTION_OPEN; +} + +bool +notifyStatus_IsFlowControlStarted(const NotifyStatus *status) +{ + return status->code == notifyStatusCode_FLOW_CONTROL_STARTED; +} + +NotifyStatus * +notifyStatus_ParseJSON(const PARCJSON *json) +{ + NotifyStatus *result = NULL; + + PARCJSONValue *status = parcJSON_GetValueByName(json, jsonNotifyStatus); + if (status != NULL) { + PARCJSON *status_json = parcJSONValue_GetJSON(status); + int apiFd = (int) parcJSONValue_GetInteger(parcJSON_GetValueByName(status_json, param_CONNECTION)); + NotifyStatusCode code = + (NotifyStatusCode) parcJSONValue_GetInteger(parcJSON_GetValueByName(status_json, param_CODE)); + + CCNxName *name = NULL; + + PARCJSONValue *nameValue = parcJSON_GetValueByName(status_json, param_NAME); + if (nameValue != NULL) { + PARCBuffer *sBuf = parcJSONValue_GetString(nameValue); + const char *p = parcBuffer_Overlay(sBuf, 0); + if (p != NULL) { + name = ccnxName_CreateFromCString(p); + } + } + + const char *message = NULL; + PARCJSONValue *messageValue = parcJSON_GetValueByName(status_json, param_MESSAGE); + if (messageValue != NULL) { + PARCBuffer *sBuf = parcJSONValue_GetString(messageValue); + message = parcBuffer_Overlay(sBuf, 0); + } + + result = notifyStatus_Create(apiFd, code, name, message); + if (name != NULL) { + ccnxName_Release(&name); + } + } + return result; +} + +PARCJSON * +notifyStatus_ToJSON(const NotifyStatus *status) +{ + PARCJSON *json = parcJSON_Create(); + + parcJSON_AddInteger(json, param_CONNECTION, notifyStatus_GetFiledes(status)); + parcJSON_AddInteger(json, param_CODE, notifyStatus_GetStatusCode(status)); + + if (notifyStatus_GetName(status) != NULL) { + char *nameAsString = ccnxName_ToString(notifyStatus_GetName(status)); + parcJSON_AddString(json, param_NAME, nameAsString); + parcMemory_Deallocate((void **) &nameAsString); + } + if (notifyStatus_GetMessage(status) != NULL) { + parcJSON_AddString(json, param_MESSAGE, notifyStatus_GetMessage(status)); + } + + PARCJSON *result = parcJSON_Create(); + parcJSON_AddObject(result, jsonNotifyStatus, json); + parcJSON_Release(&json); + + return result; +} diff --git a/libccnx-transport-rta/ccnx/api/notify/notify_Status.h b/libccnx-transport-rta/ccnx/api/notify/notify_Status.h new file mode 100644 index 00000000..3fcdcb1d --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/notify_Status.h @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file notify_Status.h + * + * @brief + * An API to handle notifications from the Transport. + * + * These notifications are specific to the RTA Transport, in that they use the Component model and Component names. + * + */ +#ifndef Libccnx_notifyStatus_h +#define Libccnx_notifyStatus_h + +#include <parc/algol/parc_JSON.h> +#include <ccnx/common/ccnx_Name.h> + +struct notify_status; +/** + * @typedef NotifyStatus + * @brief Notifications from Transport + */ +typedef struct notify_status NotifyStatus; + +// This needs to be replaced with a more sophisticated encoding scheme that individual stack components can use. Case 1035 +/** + * @typedef NotifyStatusCode + * @brief Codes for Notify Status + */ +typedef enum { + // TRANSPORT_READY = 1, // returned when Transport_Create finished + // TRANSPORT_DESTROYED = 2, // when Transport_Destroy is done + notifyStatusCode_OPEN_ERROR = 3, // error when opening a connection stack + notifyStatusCode_CONNECTION_OPEN = 4, // returned when a connection is opened + notifyStatusCode_CONNECTION_CLOSED = 5, // returned when close is finished + notifyStatusCode_FORWARDER_NOT_AVAILABLE = 6, // connection problem with forwarder + notifyStatusCode_FLOW_CONTROL_STARTED = 7, // when flow control starts on a name + notifyStatusCode_FLOW_CONTROL_FINISHED = 8, // after final block is passed up + notifyStatusCode_FLOW_CONTROL_ERROR = 9, // some hard error on the name + notifyStatusCode_ENCODING_ERROR = 10, // something bad in the codec + notifyStatusCode_SIGNING_ERROR = 11, // error signing + notifyStatusCode_SEND_ERROR = 12, // some other "down" stack error +} NotifyStatusCode; + +/** + * @typedef NotifyStatusDirection + * @brief The direction of the NotifyStatus + */ +typedef enum { + notifyStatusDirection_UPSTACK, + notifyStatusDirection_DOWNSTACK +} NotifyStatusDirection; + +/** + * Create an instance of `NotifyStatus`. + * + * @param [in] apiFd The corresponding api file descriptor. + * @param [in] code The NotifyStatusCode for this status. + * @param [in] name An associated CCNxName + * @param [in] message An (optional) string message + * + * @return NULL An error occurred + * @return non-NULL A pointer to a valid NotifyStatus instance that must be released via notifyStatus_Release(). + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *expected = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * } + * @endcode + * + * @see {@link notifyStatus_Release} + */ +NotifyStatus *notifyStatus_Create(int apiFd, NotifyStatusCode code, CCNxName *name, const char *message); + +/** + * Increase the number of references to a `NotifyStatus`. + * + * Note that new `NotifyStatus` is not created, + * only that the given `NotifyStatus` reference count is incremented. + * Discard the reference by invoking {@link notifyStatus_Release}. + * + * @param [in] status A pointer to a `NotifyStatus` instance. + * @return The input `NotifyStatus` pointer. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * NotifyStatus *x_2 = notifyStatus_Acquire(status); + * + * notifyStatus_Release(&status); + * notifyStatus_Release(&x_2); + * } + * @endcode + */ +NotifyStatus *notifyStatus_Acquire(const NotifyStatus *status); + +/** + * Release a previously acquired reference to the specified instance, + * decrementing the reference count for the instance. + * + * The pointer to the instance is set to NULL as a side-effect of this function. + * + * If the invocation causes the last reference to the instance to be released, + * the instance is deallocated and the instance's implementation will perform + * additional cleanup and release other privately held references. + * + * @param [in,out] statusPtr A pointer to a pointer to the instance to release. + * + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * notifyStatus_Release(&status); + * } + * @endcode + */ +void notifyStatus_Release(NotifyStatus **statusPtr); + +/** + * Returns true if contents of two NotifyStatus objects are the same. + * + * @param [in] x object 1 + * @param [in] y object 2 + * + * @return true X & Y are equal + * @return false X & Y are not equal + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status1 = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * NotifyStatus *status2 = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * if (notifyStatus_Equals(status1, status2)) { + * ... + * } + * } + * @endcode + */ +bool notifyStatus_Equals(const NotifyStatus *x, const NotifyStatus *y); + +/** + * Print a human readable representation of the given `NotifyStatus`. + * + * @param [in] status A pointer to the instance to display. + * @param [in] indentation The level of indentation to use to pretty-print the output. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * notifyStatus_Display(status, 0); + * + * notifyStatus_Release(&status); + * } + * @endcode + */ +void notifyStatus_Display(const NotifyStatus *status, int indentation); + +/** + * Get the associated file descriptor of the given `NotifyStatus` instance. + * + * @param [in] status A pointer to a valid instance of `NotifyStatus`. + * + * @return The associated file descriptor of this NotifyStatus instance. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * int fd = notifyStatus_GetFiledes(status); + * } + * @endcode + */ +int notifyStatus_GetFiledes(const NotifyStatus *status); + +/** + * Get the associated {@link NotifyStatusCode} of the given `NotifyStatus` instance. + * + * @param [in] status A pointer to a valid instance of `NotifyStatus`. + * + * @return The associated NotifyStatusCode of the given `NotifyStatus` instance. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * NotifyStatusCode code = notifyStatus_GetStatusCode(status); + * } + * @endcode + */ +NotifyStatusCode notifyStatus_GetStatusCode(const NotifyStatus *status); + +/** + * Get the associated {@link CCNxName} of the given `NotifyStatus` instance. + * + * @param [in] status A pointer to a valid instance of `NotifyStatus`. + * + * @return The `CCNxName` of this `NotifyStatus` instance. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * NotifyStatusCode code = notifyStatus_GetStatusCode(status); + * } + * @endcode + */ +CCNxName *notifyStatus_GetName(const NotifyStatus *status); + +/** + * Get the associated {@link CCNxName} of the given `NotifyStatus` instance. + * + * @param [in] status A pointer to a valid instance of `NotifyStatus`. + * + * @return The message of this NotifyStatus instance. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * NotifyStatusCode code = notifyStatus_GetStatusCode(status); + * } + * @endcode + */ +char *notifyStatus_GetMessage(const NotifyStatus *status); + +/** + * Return a {@link PARCJSON} representation of the given `NotifyStatus` instance. + * + * @param [in] status A pointer to a valid instance of `NotifyStatus`. + * + * @return NULL An error occurred + * @return non-NULL A pointer to a valid `PARCJSON` instance + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * PARCJSON *json = notifyStatus_ToJSON(status); + * } + * @endcode + */ +PARCJSON *notifyStatus_ToJSON(const NotifyStatus *status); + +/** + * Create a new `NotifyStatus` instance from a {@link PARCJSON} instance. + * + * @param [in] json A pointer to a `PARCJSON` instance. + * + * @return NULL An error occurred + * @return non-NULL A pointer to a valid `NotifyStatus` instance. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * PARCJSON *json = notifyStatus_ToJSON(status); + * + * NotifyStatus *status2 = notifyStatus_ParseJSON(json) + * } + * @endcode + */ +NotifyStatus *notifyStatus_ParseJSON(const PARCJSON *json); + +/** + * Evaluate to `true` if the given `NotifyStatus` indicates a Connection Open. + * + * @param [in] status A pointer to a `NotifyStatus` instance. + * + * @return `true` The given `NotifyStatus` indicates a Connection open. + * @return `false` The given ``NotifyStatus` indicates that the Connection is not open. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * if (notifyStatus_IsConnectionOpen(status)) { + * printf("Connection is open\n"); + * } + * } + * @endcode + */ +bool notifyStatus_IsConnectionOpen(const NotifyStatus *status); + +/** + * Return `true` if the given status indicates that the flow control has started. + * + * @param [in] status A pointer to a NotifyStatus instance. + * + * @return `true` The given `NotifyStatu`s indicates that flow controller has started + * @return `false` The given `NotifyStatus` indicates that the flow controller has not started. + * + * Example: + * @code + * { + * CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + * NotifyStatus *status = notifyStatus_Create(1, notifyStatus_CONNECTION_OPEN, name, "Good to go"); + * + * if (notifyStatus_IsFlowControlStarted(status)) { + * printf("Flow controller has started\n"); + * } + * } + * @endcode + */ +bool notifyStatus_IsFlowControlStarted(const NotifyStatus *status); +#endif // Libccnx_notifyStatus_h diff --git a/libccnx-transport-rta/ccnx/api/notify/notify_Timer.h b/libccnx-transport-rta/ccnx/api/notify/notify_Timer.h new file mode 100644 index 00000000..179d57ba --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/notify_Timer.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef Libccnx_notify_Timer_h +#define Libccnx_notify_Timer_h +#endif // Libccnx_notify_Timer_h diff --git a/libccnx-transport-rta/ccnx/api/notify/test/.gitignore b/libccnx-transport-rta/ccnx/api/notify/test/.gitignore new file mode 100644 index 00000000..64e67423 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/test/.gitignore @@ -0,0 +1 @@ +test_notify_Status diff --git a/libccnx-transport-rta/ccnx/api/notify/test/CMakeLists.txt b/libccnx-transport-rta/ccnx/api/notify/test/CMakeLists.txt new file mode 100644 index 00000000..97b14602 --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/test/CMakeLists.txt @@ -0,0 +1,13 @@ +# Enable gcov output for the tests +add_definitions(--coverage) +set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " --coverage") + +set(TestsExpectedToPass + test_notify_Status +) + + +foreach(test ${TestsExpectedToPass}) + AddTest(${test}) +endforeach() + diff --git a/libccnx-transport-rta/ccnx/api/notify/test/test_notify_Status.c b/libccnx-transport-rta/ccnx/api/notify/test/test_notify_Status.c new file mode 100644 index 00000000..04269b0a --- /dev/null +++ b/libccnx-transport-rta/ccnx/api/notify/test/test_notify_Status.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../notify_Status.c" + +#include <LongBow/unit-test.h> + +LONGBOW_TEST_RUNNER(notify_Status) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(notify_Status) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(notify_Status) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, notifyStatus_ToJSON); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, notifyStatus_ToJSON) +{ + CCNxName *name = ccnxName_CreateFromCString("lci:/a/b/c"); + NotifyStatus *expected = notifyStatus_Create(1, notifyStatusCode_CONNECTION_OPEN, name, "foo"); + + PARCJSON *json = notifyStatus_ToJSON(expected); + + NotifyStatus *actual = notifyStatus_ParseJSON(json); + + assertTrue(notifyStatus_Equals(expected, actual), "Failed to create and parse NotifyStatus") + { + notifyStatus_Display(expected, 0); + notifyStatus_Display(actual, 0); + } +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(notify_Status); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} |