OperationCommon * OperationCommon_NewWithExistingObjectsTree(const Session * session, SessionType sessionType, TreeNode objectsTree) { OperationCommon * operation = NULL; if (session != NULL) { operation = Awa_MemAlloc(sizeof(*operation)); if (operation != NULL) { memset(operation, 0, sizeof(*operation)); operation->Session = session; operation->SessionType = sessionType; operation->ObjectsTree = objectsTree; if (operation->ObjectsTree != NULL) { LogNew("OperationCommon", operation); } else { LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation"); Awa_MemSafeFree(operation); operation = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL"); } return operation; }
// FIXME Currently The client is using the old xml spec and therefore can't be used with the new objects tree. // This is a temporary workaround to prevent error messages when the response does not contain an 'Objects' node ResponseCommon * ResponseCommon_NewClient(const OperationCommon * operation, TreeNode objectsNode) { ResponseCommon * response = NULL; if (operation != NULL) { if (objectsNode != NULL) { response = Awa_MemAlloc(sizeof(*response)); if (response != NULL) { memset(response, 0, sizeof(*response)); response->OperationCommon = operation; response->ObjectsNode = Tree_Copy(objectsNode); LogNew("ResponseCommon", response); } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogError("Content Response is NULL"); } } else { LogError("Operation is NULL"); } return response; }
ResponseCommon * ResponseCommon_New(const OperationCommon * operation, TreeNode objectsNode) { ResponseCommon * response = NULL; if (operation != NULL) { if (objectsNode != NULL) { response = Awa_MemAlloc(sizeof(*response)); if (response != NULL) { memset(response, 0, sizeof(*response)); response->OperationCommon = operation; response->ObjectsNode = Tree_Copy(objectsNode); // build the Values data structure if (ResponseCommon_BuildValues(response) == AwaError_Success) { // not all responses have Values, so success includes no values } else { // there was an error building values LogDebug("Failed to build response values - continuing"); } if (ResponseCommon_BuildPathResults(response) == AwaError_Success) { // not all responses have path results } else { // there was an error building values LogErrorWithEnum(AwaError_ResponseInvalid, "Failed to build path results - continuing"); } response->NulledValues = Map_New(); LogNew("ResponseCommon", response); } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogError("Content Response is NULL"); } } else { LogError("Operation is NULL"); } return response; }
AwaClientSubscribeOperation * AwaClientSubscribeOperation_New(const AwaClientSession * session) { AwaClientSubscribeOperation * operation = NULL; if (session != NULL) { if (ClientSession_IsConnected(session) != false) { operation = Awa_MemAlloc(sizeof(*operation)); if (operation != NULL) { memset(operation, 0, sizeof(*operation)); operation->Common = OperationCommon_NewWithClientSession(session); if (operation->Common != NULL) { operation->Subscribers = Map_New(); if (operation->Subscribers != NULL) { LogNew("AwaClientSubscribeOperation", operation); } else { LogErrorWithEnum(AwaError_OutOfMemory, "Could not create subscriber list."); Awa_MemSafeFree(operation); operation = NULL; } } else { LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation."); Awa_MemSafeFree(operation); operation = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogError("Session is not connected"); } } else { LogError("Session is NULL"); } return operation; }
StringIterator * StringIterator_New(void) { StringIterator * iterator = Awa_MemAlloc(sizeof (*iterator)); if (iterator != NULL) { memset(iterator, 0, sizeof(*iterator)); iterator->Iterator = Iterator_New(); LogNew("StringIterator", iterator); } else { LogErrorWithEnum(AwaError_OutOfMemory); } return iterator; }
AwaChangeSet * ChangeSet_NewWithClientID(Session * session, SessionType sessionType, TreeNode objectsTree, const char * clientID) { AwaChangeSet * changeSet = NULL; if (objectsTree != NULL) { changeSet = Awa_MemAlloc(sizeof(*changeSet)); if (changeSet != NULL) { memset(changeSet, 0, sizeof(*changeSet)); changeSet->OperationCommon = OperationCommon_New(session, sessionType); if (changeSet->OperationCommon != NULL) { changeSet->ResponseCommon = ResponseCommon_New(changeSet->OperationCommon, objectsTree); if (changeSet->ResponseCommon != NULL) { changeSet->ClientID = clientID; LogNew("AwaChangeSet New", changeSet); } else { LogErrorWithEnum(AwaError_OutOfMemory); OperationCommon_Free(&changeSet->OperationCommon); Awa_MemSafeFree(changeSet); changeSet = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); Awa_MemSafeFree(changeSet); changeSet = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogErrorWithEnum(AwaError_OperationInvalid, "Objects tree is NULL"); } return changeSet; }
AwaArray * AwaArray_New(void) { AwaArray * array = Awa_MemAlloc(sizeof(*array)); if (array != NULL) { memset(array, 0, sizeof(*array)); ListInit(&array->ValueList); LogNew("AwaArray", array); } else { LogErrorWithEnum(AwaError_OutOfMemory); } return array; }
AwaServerExecuteOperation * AwaServerExecuteOperation_New(const AwaServerSession * session) { // AwaServerExecuteResponse is an alias for ResponseCommon AwaServerExecuteOperation * operation = NULL; if (session != NULL) { if (ServerSession_IsConnected(session) != false) { operation = Awa_MemAlloc(sizeof(*operation)); if (operation != NULL) { memset(operation, 0, sizeof(*operation)); operation->ServerOperation = ServerOperation_New(session); if (operation->ServerOperation != NULL) { LogNew("AwaServerExecuteOperation", operation); } else { LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation"); Awa_MemSafeFree(operation); operation = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogErrorWithEnum(AwaError_SessionInvalid); } } else { LogErrorWithEnum(AwaError_SessionInvalid, "Session is NULL"); } return operation; }
AwaServerListClientsOperation * AwaServerListClientsOperation_New(const AwaServerSession * session) { AwaServerListClientsOperation * operation = NULL; if (session != NULL) { if (ServerSession_IsConnected(session) != false) { operation = Awa_MemAlloc(sizeof(*operation)); if (operation != NULL) { memset(operation, 0, sizeof(*operation)); operation->ServerResponse = NULL; operation->ServerOperation = ServerOperation_New(session); if (operation->ServerOperation != NULL) { operation->ClientResponseMap = Map_New(); LogNew("AwaServerListClientsOperation", operation); } else { LogErrorWithEnum(AwaError_Internal, "Unable to initialise operation"); Awa_MemSafeFree(operation); operation = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory); } } else { LogErrorWithEnum(AwaError_SessionNotConnected); } } else { LogError("Session is NULL"); } return operation; }
AwaServerSession * AwaServerSession_New(void) { AwaServerSession * session = Awa_MemAlloc(sizeof(*session)); if (session != NULL) { memset(session, 0, sizeof(*session)); session->SessionCommon = SessionCommon_New(SessionType_Server); if (session->SessionCommon != NULL) { session->Observers = Map_New(); if (session->Observers != NULL) { session->NotificationQueue = Queue_New(); if (session->NotificationQueue != NULL) { session->ServerEventsCallbackInfo = ServerEventsCallbackInfo_New(); if (session->ServerEventsCallbackInfo != NULL) { LogNew("AwaServerSession", session); } else { LogErrorWithEnum(AwaError_OutOfMemory, "Could not create server events"); Queue_Free(&session->NotificationQueue); Map_Free(&session->Observers); SessionCommon_Free(&session->SessionCommon); Awa_MemSafeFree(session); session = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory, "Could not create notification queue"); Map_Free(&session->Observers); SessionCommon_Free(&session->SessionCommon); Awa_MemSafeFree(session); session = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory, "Could not create observer list"); SessionCommon_Free(&session->SessionCommon); Awa_MemSafeFree(session); session = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory, "Could not create common session"); SessionCommon_Free(&session->SessionCommon); Awa_MemSafeFree(session); session = NULL; } } else { LogErrorWithEnum(AwaError_OutOfMemory, "Could not create ServerSession"); } return session; }