Esempio n. 1
0
// Given an object, object instance or resource node, add a create tag. In the case only an object node is given,
// an object instance node without an ID will be created, marking that the new instance should have a generated ID.
InternalError ClientSetOperation_AddCreate(TreeNode node)
{
    InternalError result = InternalError_Unspecified;

    if ((node != NULL) && (ObjectsTree_IsObjectNode(node) || ObjectsTree_IsObjectInstanceNode(node) || ObjectsTree_IsResourceNode(node)))
    {
        if (ObjectsTree_IsObjectNode(node))
        {
            node = ObjectsTreeInternal_AddChildNode(node, "ObjectInstance");
        }

        if (TreeNode_AddChild(node, Xml_CreateNode(IPC_MESSAGE_TAG_CREATE)))
        {
            result = InternalError_Success;
        }
        else
        {
            LogError("Failed to add create tag to object instance node");
            result = InternalError_Tree;
        }
    }
    else
    {
        LogError("node is NULL");
        result = InternalError_ParameterInvalid;
    }

    return result;
}
Esempio n. 2
0
TreeNode Xml_CreateNodeWithValue(const char * name, const char * format, ...)
{
    va_list args;

    TreeNode node = Xml_CreateNode(name);
    if (node == NULL)
    {
        return NULL;
    }
    va_start(args, format);
    int requiredSize = vsnprintf(NULL, 0, format, args);
    va_end(args);

    char * value = malloc(requiredSize + 1);
    if (value == NULL)
    {
        Tree_Delete(node);
        return NULL;
    }

    memset(value, 0, requiredSize + 1);

    va_start(args, format);
    vsprintf(value, format, args);
    va_end(args);

    TreeNode_SetValue(node, (const uint8_t *)value, strlen(value));

    free(value);

    return node;
}
Esempio n. 3
0
static TreeNode AddIDRange(TreeNode resourceNode, AwaArrayIndex startIndex, AwaArrayIndex endIndexExclusive)
{
    TreeNode rangeNode = NULL;
    if (resourceNode != NULL)
    {
        // add an <IDRange> node to the supplied valuesNode
        rangeNode = Xml_CreateNode("IDRange");
        TreeNode rangeStartNode = Xml_CreateNodeWithValue("Start", "%d", startIndex);
        TreeNode rangeEndNode = Xml_CreateNodeWithValue("EndExclusive", "%d", endIndexExclusive);

        TreeNode_AddChild(rangeNode, rangeStartNode);
        TreeNode_AddChild(rangeNode, rangeEndNode);
        TreeNode_AddChild(resourceNode, rangeNode);
    }
    else
    {
        LogErrorWithEnum(AwaError_Internal, "resourceNode is NULL");
    }
    return rangeNode;
}
Esempio n. 4
0
InternalError ClientSubscribe_AddAwaSubscribeType(TreeNode leafNode, AwaClientSubscription * subscription)
{
    InternalError result = InternalError_Unspecified;
    const char * messageType = NULL;
    switch(subscription->Type)
    {
        case AwaSubscribeType_Change:
            messageType = subscription->Cancel? IPC_MESSAGE_TAG_CANCEL_SUBSCRIBE_TO_CHANGE : IPC_MESSAGE_TAG_SUBSCRIBE_TO_CHANGE;
            break;
        case AwaSubscribeType_Execute:
            messageType = subscription->Cancel? IPC_MESSAGE_TAG_CANCEL_SUBSCRIBE_TO_EXECUTE : IPC_MESSAGE_TAG_SUBSCRIBE_TO_EXECUTE;
            break;
        default:
            result = LogErrorWithEnum(InternalError_Unspecified, "node is NULL");
            goto error;
    }

    if (leafNode != NULL)
    {
        TreeNode subscribeTypeNode = Xml_CreateNode(messageType);
        if (TreeNode_AddChild(leafNode, subscribeTypeNode))
        {
            result = InternalError_Success;
        }
        else
        {
            result = LogErrorWithEnum(InternalError_Tree, "Failed to add AwaSubscribeType tag to leaf node");
        }
    }
    else
    {
        result = LogErrorWithEnum(InternalError_ParameterInvalid, "node is NULL");
    }
error:
    return result;
}