static void FreeValues(MapType ** valuesMap) { if ((valuesMap != NULL) && (*valuesMap != NULL)) { Map_ForEach(*valuesMap, FreeValue, NULL); Map_Free(valuesMap); } }
AwaError AwaClientSubscribeOperation_Free(AwaClientSubscribeOperation ** operation) { AwaError result = AwaError_OperationInvalid; if (operation != NULL && *operation != NULL) { OperationCommon_Free(&(*operation)->Common); Map_ForEach((*operation)->Subscribers, RemoveSubscriptionLinkToOperation, *operation); Map_Free(&(*operation)->Subscribers); if ((*operation)->Response != NULL) { SubscribeResponse_Free(&(*operation)->Response); } LogFree("AwaClientSubscribeOperation", *operation); Awa_MemSafeFree(*operation); *operation = NULL; result = AwaError_Success; } return result; }
AwaError AwaServerSession_Free(AwaServerSession ** session) { AwaError result = AwaError_Success; if ((session != NULL) && (*session != NULL)) { SessionCommon_Free(&((*session)->SessionCommon)); (*session)->SessionCommon = NULL; Map_ForEach((*session)->Observers, RemoveObservationLinkToSession, NULL); Map_Free(&(*session)->Observers); Queue_Free(&((*session)->NotificationQueue)); // Free the session itself LogFree("AwaServerSession", *session); Awa_MemSafeFree(*session); *session = NULL; } else { result = LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL"); } return result; }
AwaError AwaClientSubscribeOperation_Perform(AwaClientSubscribeOperation * operation, AwaTimeout timeout) { AwaError result = AwaError_Unspecified; if (timeout >= 0) { if (operation != NULL) { PerformAddPathCallbackContext addPathContext; addPathContext.OperationCommon = operation->Common; addPathContext.Result = AwaError_Success; Map_ForEach(operation->Subscribers, ClientSubscribe_PerformAddPathCallback, (void *)&addPathContext); result = addPathContext.Result; if (result != AwaError_Success) { goto error; } const AwaClientSession * session = OperationCommon_GetSession(operation->Common, NULL); if (ClientSession_IsConnected(session)) { TreeNode objectsTree = OperationCommon_GetObjectsTree(operation->Common); if (objectsTree != NULL) { if (TreeNode_GetChildCount(objectsTree) > 0) { // build an IPC message and inject our content (object paths) into it IPCMessage * subscribeRequest = IPCMessage_NewPlus(IPC_MESSAGE_TYPE_REQUEST, IPC_MESSAGE_SUB_TYPE_SUBSCRIBE, OperationCommon_GetSessionID(operation->Common)); IPCMessage_AddContent(subscribeRequest, objectsTree); IPCMessage * subscribeResponse = NULL; result = IPC_SendAndReceive(ClientSession_GetChannel(session), subscribeRequest, &subscribeResponse, timeout); if (result == AwaError_Success) { IPCResponseCode responseCode = IPCMessage_GetResponseCode(subscribeResponse); if (responseCode == IPCResponseCode_Success) { // Free an old response if it exists if (operation->Response != NULL) { result = SubscribeResponse_Free(&operation->Response); } if (result == AwaError_Success) { // Detach the response content and store it in the operation's ClientGetResponse TreeNode contentNode = IPCMessage_GetContentNode(subscribeResponse); TreeNode objectsNode = Xml_Find(contentNode, "Objects"); operation->Response = SubscribeResponse_New(operation, objectsNode); if (operation->Response) { PerformSuccessfulCallbackContext successContext; successContext.Session = OperationCommon_GetSession(operation->Common, SessionType_Client); successContext.Response = operation->Response; successContext.Result = AwaError_Success; Map_ForEach(operation->Subscribers, ClientSubscribe_PerformSuccessfulCallback, (void *)&successContext); result = successContext.Result; LogDebug("Perform Subscribe Operation finished %s\n", (result == AwaError_Success? "successfully" : "with errors")); } else { result = LogErrorWithEnum(AwaError_Internal, "An internal error occurred when parsing Get Response"); } } } else { result = LogErrorWithEnum(AwaError_IPCError, "Unexpected IPC response code: %d", responseCode); } } IPCMessage_Free(&subscribeRequest); IPCMessage_Free(&subscribeResponse); } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "No paths specified"); } } else { result = LogErrorWithEnum(AwaError_Internal, "ObjectsTree is NULL"); } } else { LogError("Session is not connected"); } } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "Operation is NULL"); } } else { result = LogErrorWithEnum(AwaError_OperationInvalid, "Invalid timeout"); } error: return result; }