Пример #1
0
static unsigned int constructObject(char *parentName, char *object, jsonProperty *properties, char **next) {
    char *firstName;
    char *lastName;
    char *first;
    char *last;
    unsigned char type;
    unsigned int hash;
    int parentNameLength = (parentName ? strlen(parentName): 0);
    unsigned int result = readNextName(object, &firstName, &lastName, &hash);
    while (result == PARSE_OK) {
        readNextValue(lastName, &first, &last, &type);
        
        if (!parentName) {
            if (type == JSON_OBJECT) {
                int nameLength = lastName - firstName;
                char newParent[nameLength + 1];
                strncpy(newParent, firstName, nameLength);
                newParent[nameLength] = '\0';
                return constructObject(newParent, first, properties, next);
            }
        } else {
            int nameLength = lastName - firstName;
            int fullNameLength = nameLength + parentNameLength + 1; 
            char fullName[fullNameLength + 1];
            strncpy(fullName, firstName, nameLength);
            fullName[nameLength] = '.';
            strncpy(&fullName[nameLength + 1], parentName, parentNameLength);
            fullName[fullNameLength] = '\0';
            hash = djbHash(fullName, fullNameLength);
            if (type == JSON_OBJECT) {
                return constructObject(fullName, first, properties, next);
            }
        }

        int i = 0;
        jsonProperty *property = &properties[hash & HASH_MASK];
        while (property->hash != 0){
            ++i;
            if (i == MAX_CONFLICTS) {
                return ERR_EVENT_MAX_CONFLICTS;
            }

            property = &properties[(hash & HASH_MASK) + (i * MAX_BUCKET_LENGTH)];
        }
        
        property->hash = hash;
        property->firstValue = first;
        property->lastValue = last;
        property->type = type;
        *next = last;
        result = readNextName(last, &firstName, &lastName, &hash);
    }
 
    return (result == PARSE_END ? RULES_OK: result);
}
Пример #2
0
static unsigned int handleSession(ruleset *tree, char *state, void *rulesBinding, unsigned short actionType, unsigned short *commandCount, unsigned char store) {
    char *next;
    jsonProperty properties[MAX_BUCKET_LENGTH * MAX_CONFLICTS];
    memset(properties, 0, sizeof(properties));
    int result = constructObject(NULL, state, properties, &next);
    if (result != RULES_OK) {
        return result;
    }

    jsonProperty *sidProperty;
    int sidLength;
    result = getId(properties, ID_HASH, &sidProperty, &sidLength);
    if (result != RULES_OK) {
        return result;
    }
    char sid[sidLength + 1];
    strncpy(sid, sidProperty->firstValue, sidLength);
    sid[sidLength] = '\0';
    result = handleAlpha(tree, sid, NULL, state, &tree->nodePool[NODE_S_OFFSET].value.a, properties, &rulesBinding, actionType, commandCount); 
    if (result == ERR_EVENT_NOT_HANDLED && store) {
        *commandCount = *commandCount + 1;
        result = storeSession(rulesBinding, sid, state);
    }

    return result;
}
Пример #3
0
bool GAFObject::init(GAFAsset * anAnimationData, GAFTimeline* timeline)
{
    CCAssert(anAnimationData, "anAssetData data should not be nil");
    CCAssert(timeline, "Timeline data should not be nil");

    if (!anAnimationData || !timeline)
    {
        return false;
    }

    if (m_asset != anAnimationData)
    {
        CC_SAFE_RELEASE(m_asset);
        m_asset = anAnimationData;
        CC_SAFE_RETAIN(m_asset);
    }

    if (m_timeline != timeline)
    {
        CC_SAFE_RELEASE(m_timeline);
        m_timeline = timeline;
        CC_SAFE_RETAIN(m_timeline);
    }
    m_container = cocos2d::Node::create();
    addChild(m_container);
    m_container->setContentSize(getContentSize());

    m_currentSequenceStart = m_currentFrame = GAFFirstFrameIndex;

    m_currentSequenceEnd = m_totalFrameCount = m_timeline->getFramesCount();

    constructObject();

    return true;
}
void planning_environment::convertAllowedContactSpecificationMsgToAllowedContactVector(const std::vector<arm_navigation_msgs::AllowedContactSpecification>& acmv,
                                                                                       std::vector<collision_space::EnvironmentModel::AllowedContact>& acv)
{
  //assumes that poses are in the global frame
  acv.clear();
  for(unsigned int i = 0; i < acmv.size(); i++) {
    const arm_navigation_msgs::AllowedContactSpecification& acs = acmv[i];
    if(acs.link_names.size() != 2) {
      ROS_WARN_STREAM("Allowed collision specification has link_names size " << acs.link_names.size()
                      << " while the only supported size is 2");
      continue;
    }
    shapes::Shape* shape = constructObject(acs.shape);
    boost::shared_ptr<bodies::Body> bodysp(bodies::createBodyFromShape(shape));
    delete shape;
    tf::Transform trans;
    tf::poseMsgToTF(acs.pose_stamped.pose, trans);
    bodysp->setPose(trans);

    collision_space::EnvironmentModel::AllowedContact allc;
    allc.bound = bodysp;
    allc.body_name_1 = acs.link_names[0];
    allc.body_name_2 = acs.link_names[1];
    allc.depth = acs.penetration_depth;
    acv.push_back(allc);
  }
}
Пример #5
0
static unsigned int handleEvent(ruleset *tree, char *message, void **rulesBinding, unsigned short actionType, unsigned short *commandCount) {
    char *next;
    jsonProperty properties[MAX_BUCKET_LENGTH * MAX_CONFLICTS];
    memset(properties, 0, sizeof(properties));
    int result = constructObject(NULL, message, properties, &next);
    if (result != RULES_OK) {
        return result;
    }

    return handleEventCore(tree, message, properties, rulesBinding, actionType, commandCount);
}
bool planning_environment::createAndPoseShapes(tf::TransformListener& tf,
        const std::vector<arm_navigation_msgs::Shape>& orig_shapes,
        const std::vector<geometry_msgs::Pose>& orig_poses,
        const std_msgs::Header& header,
        const std::string& frame_to,
        std::vector<shapes::Shape*>& conv_shapes,
        std::vector<tf::Transform>& conv_poses)
{
    conv_shapes.clear();
    conv_poses.clear();
    bool shapes_ok = true;
    tf::Transform ident_trans;
    if(!getLatestIdentityTransform(frame_to, header.frame_id, tf, ident_trans)) {
        ROS_WARN_STREAM("Can't get identity pose to transform shapes");
        return false;
    }
    for(unsigned int i = 0; i < orig_shapes.size(); i++) {
        shapes::Shape *shape = constructObject(orig_shapes[i]);
        if(shape == NULL) {
            shapes_ok = false;
            break;
        }
        conv_shapes.push_back(shape);
        tf::Transform shape_pose;
        tf::poseMsgToTF(orig_poses[i], shape_pose);
        conv_poses.push_back(ident_trans*shape_pose);
    }
    if(!shapes_ok) {
        for(unsigned int i=0; i < conv_shapes.size(); i++) {
            delete conv_shapes[i];
        }
        conv_shapes.clear();
        conv_poses.clear();
        return false;
    }
    return true;
}
static EncodedJSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec)
{
    return JSValue::encode(constructObject(exec));
}
Пример #8
0
unsigned int assertEvents(void *handle, char *messages, unsigned int *resultsLength, unsigned int **results) {
    unsigned int messagesLength = 64;
    unsigned int *resultsArray = malloc(sizeof(unsigned int) * messagesLength);
    if (!resultsArray) {
        return ERR_OUT_OF_MEMORY;
    }

    *resultsLength = 0;
    unsigned short commandCount = 0;
    unsigned short actionType = ACTION_ASSERT_FIRST_MESSAGE;
    unsigned int result;
    void *rulesBinding = NULL;
    jsonProperty properties0[MAX_BUCKET_LENGTH * MAX_CONFLICTS];
    jsonProperty properties1[MAX_BUCKET_LENGTH * MAX_CONFLICTS];
    jsonProperty *currentProperties = NULL;
    jsonProperty *nextProperties = properties0;
    char *first = NULL;
    char *last = NULL;
    char *next = NULL;
    char *nextFirst = messages;
    char lastTemp;

    memset(nextProperties, 0, sizeof(properties0));
    while (nextFirst[0] != '{' && nextFirst[0] != '\0' ) {
        ++nextFirst;
    }
    while (constructObject(NULL, nextFirst, nextProperties, &next) == RULES_OK) {
        if (currentProperties) {
            result = handleEventCore(handle, first, currentProperties, &rulesBinding, actionType, &commandCount);
            last[0] = lastTemp;
            if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
                free(resultsArray);
                return result;
            }

            if (result == RULES_OK) {
                actionType = ACTION_ASSERT_MESSAGE;
            }

            if (*resultsLength >= messagesLength) {
                messagesLength = messagesLength * 2;
                resultsArray = realloc(resultsArray, sizeof(unsigned int) * messagesLength);
                if (!resultsArray) {
                    return ERR_OUT_OF_MEMORY;
                }
            }

            resultsArray[*resultsLength] = result;
            ++*resultsLength;
        }

        while (next[0] != ',' && next[0] != ']' ) {
            ++next;
        }
        last = next;
        lastTemp = next[0];
        next[0] = '\0';
        currentProperties = nextProperties;
        first = nextFirst;
        nextFirst = next + 1;
        if (nextProperties == properties0) {
            nextProperties = properties1;
        } else {
            nextProperties = properties0;
        }

        memset(nextProperties, 0, sizeof(properties0));    
    }

    if (actionType == ACTION_ASSERT_FIRST_MESSAGE) {
        actionType = ACTION_ASSERT_MESSAGE_IMMEDIATE;
    } else {
        actionType = ACTION_ASSERT_LAST_MESSAGE;
    }

    result = handleEventCore(handle, first, currentProperties, &rulesBinding, actionType, &commandCount);
    last[0] = lastTemp;
    if (result != RULES_OK && result != ERR_EVENT_NOT_HANDLED) {
        free(resultsArray);
        return result;
    }

    if (*resultsLength >= messagesLength) {
        ++messagesLength;
        resultsArray = realloc(resultsArray, sizeof(unsigned int) * messagesLength);
        if (!resultsArray) {
            return ERR_OUT_OF_MEMORY;
        }
    }

    resultsArray[*resultsLength] = result;
    ++*resultsLength;
    *results = resultsArray;
    return RULES_OK;
}
Пример #9
0
static JSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args)
{
    return constructObject(exec, args);
}
Пример #10
0
static JSObject* constructWithObjectConstructor(ExecState* exec, JSObject*, const ArgList& args)
{
    return constructObject(exec, args);
}
static JSValue* callObjectConstructor(ExecState* exec, JSObject*, JSValue*, const ArgList& args)
{
    return constructObject(exec, args);
}
Пример #12
0
static EncodedJSValue JSC_HOST_CALL callObjectConstructor(ExecState* exec)
{
    ArgList args(exec);
    return JSValue::encode(constructObject(exec, args));
}