Esempio n. 1
0
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;
}
Esempio n. 3
0
AwaError AwaServerExecuteOperation_Perform(AwaServerExecuteOperation * operation, AwaTimeout timeout)
{
    AwaError result = AwaError_Unspecified;

    if (timeout >= 0)
    {
        if (operation != NULL)
        {
            const AwaServerSession * session = ServerOperation_GetSession(operation->ServerOperation);
            if (session != NULL)
            {
                if (ServerSession_IsConnected(session))
                {
                    TreeNode clientsTree = ServerOperation_GetClientsTree(operation->ServerOperation);
                    if (clientsTree != NULL)
                    {
                        if (TreeNode_GetChildCount(clientsTree) > 0)
                        {
                            // build an IPC message and inject our content into it
                            IPCMessage * request = IPCMessage_NewPlus(IPC_MESSAGE_TYPE_REQUEST, IPC_MESSAGE_SUB_TYPE_EXECUTE, ServerOperation_GetSessionID(operation->ServerOperation));

                            // Add Content to message
                            IPCMessage_AddContent(request, clientsTree);

                            // Send via IPC
                            IPCMessage * response = NULL;
                            result = IPC_SendAndReceive(ServerSession_GetChannel(session), request, &response, timeout);

                            // Process the response
                            if (result == AwaError_Success)
                            {
                                IPCResponseCode responseCode = IPCMessage_GetResponseCode(response);
                                if (responseCode == IPCResponseCode_Success)
                                {
                                    // Free an old Execute response record if it exists
                                    if (operation->Response != NULL)
                                    {
                                        ServerResponse_Free(&operation->Response);
                                    }

                                    // Detach the response's content and add it to the Server Response
                                    TreeNode contentNode = IPCMessage_GetContentNode(response);
                                    TreeNode clientsNode = Xml_Find(contentNode, "Clients");
                                    operation->Response = ServerResponse_NewFromServerOperation(operation->ServerOperation, clientsNode);

                                    LogDebug("Perform Execute Operation successful");

                                    result = ServerResponse_CheckForErrors(operation->Response);
                                }
                                else if (responseCode == IPCResponseCode_FailureBadRequest)
                                {
                                    result = LogErrorWithEnum(AwaError_IPCError, "Unable to perform Execute operation: Bad Request");
                                }
                                else
                                {
                                    result = LogErrorWithEnum(AwaError_IPCError, "Unexpected IPC response code: %d", responseCode);
                                }
                            }

                            IPCMessage_Free(&request);
                            IPCMessage_Free(&response);
                        }
                        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;
}