Esempio n. 1
0
static inline Variant fromJSON(const cJSON *cjson)
{
    assert(cjson);
    switch (cjson->type) {
    case cJSON_False: return Variant(false);
    case cJSON_True: return Variant(true);
    case cJSON_NULL: return Variant();
    case cJSON_Number: return (cjson->valuedouble == cjson->valueint
                               ? Variant(cjson->valueint)
                               : Variant(cjson->valuedouble));
    case cJSON_String: return Variant(cjson->valuestring);
    case cJSON_Array: {
        VariantArray list;
        for (cjson=cjson->child; cjson; cjson = cjson->next)
            list.push_back(fromJSON(cjson));
        return list; }
    case cJSON_Object: {
        VariantMap map;
        for (cjson=cjson->child; cjson; cjson = cjson->next)
            map[cjson->string] = fromJSON(cjson);
        return map; }
    default:
        assert(0);
        break;
    }
    return VariantMap();
}
Esempio n. 2
0
void NativeBridge::sendReady(int errCode)
{
    // This is a special message that indicates the plugin is ready for
    // business. It has the following structure:
    // {
    //     method:          'ready'
    //     idx:             -1 (not used)
    //     success:         true if no errCode=CAD_ERR_OK, false otherwise
    //     errorMessage:    string, error message
    //     errorCode:       errCode
    //     payload:         {'compat': Array of API version numbers this class
    //                                 is compatible with}
    // }
    VariantMap msgVar;
    msgVar["method"] = "ready";
    msgVar["idx"] = -1;   // this message does not have use index
    msgVar["success"] = (errCode==CAD_ERR_OK);
    msgVar["errorMessage"] = CadErrStr[errCode];
    msgVar["errorCode"] = errCode;
    VariantArray compatList;
    compatList.push_back(Variant("1"));
    VariantMap varMap;
    varMap["compat"] = compatList;
    stringstream version;
    version << Plugin_VERSION_MAJOR << "." << Plugin_VERSION_MINOR;
    varMap["version"] = version.str();
    msgVar["payload"] = Variant(varMap);
    send(msgVar);
}