Exemple #1
0
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;
}
AwaError AwaClientSetOperation_Perform(AwaClientSetOperation * operation, AwaTimeout timeout)
{
    AwaError result = AwaError_Unspecified;

    if (timeout >= 0)
    {
        if (operation != NULL)
        {
            const AwaClientSession * session = OperationCommon_GetSession(operation->Common, NULL);
            if (session != NULL)
            {
                if (ClientSession_IsConnected(session))
                {
                    TreeNode objectsTree = OperationCommon_GetObjectsTree(operation->Common);
                    if (objectsTree != NULL)
                    {
                        if (TreeNode_GetChildCount(objectsTree) > 0)
                        {
                            IPCMessage * setRequest = IPCMessage_NewPlus(IPC_MESSAGE_TYPE_REQUEST, IPC_MESSAGE_SUB_TYPE_SET, OperationCommon_GetSessionID(operation->Common));
                            IPCMessage_AddContent(setRequest, objectsTree);

                            // Serialise message
                            char * requestBuffer = IPC_SerialiseMessageToXML(setRequest);
                            Awa_MemSafeFree(requestBuffer);

                            // Send via IPC
                            IPCMessage * setResponse = NULL;
                            result = IPC_SendAndReceive(ClientSession_GetChannel(session), setRequest, &setResponse, timeout);

                            // Process the response
                            if (result == AwaError_Success)
                            {
                                // Free an old Read response record if it exists
                                if (operation->Response != NULL)
                                {
                                    ResponseCommon_Free(&operation->Response);
                                }

                                TreeNode contentNode = IPCMessage_GetContentNode(setResponse);
                                TreeNode objectsNode = Xml_Find(contentNode, "Objects");
                                operation->Response = ResponseCommon_New(operation->Common, objectsNode);

                                result = ResponseCommon_CheckForErrors(operation->Response);

                                LogDebug("Perform Set Operation successful");
                            }
                            // Free allocated memory
                            IPCMessage_Free(&setRequest);
                            IPCMessage_Free(&setResponse);
                        }
                        else
                        {
                            result = LogErrorWithEnum(AwaError_OperationInvalid, "No paths specified");
                        }
                    }
                    else
                    {
                        result = LogErrorWithEnum(AwaError_Internal, "objectsTree is NULL");
                    }
                }
                else
                {
                    result = LogErrorWithEnum(AwaError_SessionNotConnected, "session is not connected");
                }
            }
            else
            {
                result = LogErrorWithEnum(AwaError_SessionInvalid, "session is NULL");
            }
        }
        else
        {
            result = LogErrorWithEnum(AwaError_OperationInvalid, "operation is NULL");
        }
    }
    else
    {
        result = LogErrorWithEnum(AwaError_OperationInvalid, "Invalid timeout specified");
    }
    return result;
}