示例#1
0
void OuyaPlugin_asyncOuyaRequestProducts(const char* productsJson, s3eCallback onSuccess, s3eCallback onFailure, s3eCallback onCancel)
{
	IwTrace(ODK, ("ODK_platform: OuyaPlugin_asyncOuyaRequestProducts"));

	std::string msg = "OuyaPlugin_asyncOuyaRequestProducts: productsJson=";
	msg.append(productsJson);
	IwTrace(ODK, (msg.c_str()));

	//convert JSON to product id array

	// Parse example data
	JSONValue* value = JSON::Parse(productsJson);

	if (value == NULL)
	{
		IwTrace(ODK, ("Parsing JSON Failed"));
		return;
	}

	if (!value->IsArray())
	{
		IwTrace(ODK, ("Parsing JSON Failed: Not an array"));
		return;
	}

	// Retrieve the main object
	JSONArray data = value->AsArray();

	std::vector<std::string> productIds;

	for (unsigned int i = 0; i < data.size(); i++)
	{
		if (data[i]->IsString())
		{
			const std::wstring wstr = data[i]->AsString();

			std::string productId( wstr.begin(), wstr.end() );

			productIds.push_back(productId);
		}
	}

	OuyaSDK::CallbackSingleton::GetInstance()->m_callbacksRequestProducts->RegisterCallbacks(onSuccess, onFailure, onCancel);

	g_pluginOuya.AsyncOuyaRequestProducts(productIds);
}
void OuyaPlugin_asyncOuyaRequestProducts(const char* productsJson, s3eCallback onSuccess, s3eCallback onFailure, s3eCallback onCancel)
{
    IwTrace(ODK, ("ODK_platform: OuyaPlugin_asyncOuyaRequestProducts"));

    std::string msg = "OuyaPlugin_asyncOuyaRequestProducts: productsJson=";
    msg.append(productsJson);
    IwTrace(ODK, (msg.c_str()));

    //convert JSON to product id array
    JSONArray jsonArray = JSONArray(productsJson);

    std::vector<std::string> productIds;

    for (int i = 0; i < jsonArray.length(); i++)
    {
        std::string productId = jsonArray.getString(i);
        productIds.push_back(productId);
    }

    OuyaSDK::CallbackSingleton::GetInstance()->m_callbacksRequestProducts->RegisterCallbacks(onSuccess, onFailure, onCancel);

    g_pluginOuya.AsyncOuyaRequestProducts(productIds);
}