Exemple #1
0
BOOL WINAPI Conf::ParseAction(JSONArray js) {

	UINT i = 0;
	ActionsManager *actionsManager = ActionsManager::self();

	for (i = 0; i < js.size(); i++) {
		JSONObject jo = js[i]->AsObject();
		JSONValue *c = jo[L"subactions"];

		if (c == NULL || c->IsArray() == FALSE) {
			// WARNING
			continue;
		}

#ifdef _DEBUG
		WCHAR msg[128];
		wstring moduleName = jo[L"desc"]->AsString();
		//wprintf(L"Parsing Action: \"%s\"\n", moduleName.c_str());
		swprintf_s(msg, L"Parsing Action: \"%s\"\n", moduleName.c_str());OutputDebugString(msg);
#endif

		actionsManager->add(i, c->AsArray());
	}

	return TRUE;
}
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);
}
		JNIEXPORT void JNICALL Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess(JNIEnv* env, jobject thiz, jstring jsonData)
		{
			LOGI("***********Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess***********");
		
			std::string strJsonData = env->GetStringUTFChars(jsonData, NULL);

			//char buffer[256];
			//sprintf(buffer, "Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess: Returned to C: %s", strJsonData.c_str());
			//LOGI(buffer);

			//LOGI("Parsing JSON Data");

			// Parse example data
			JSONValue* value = JSON::Parse(strJsonData.c_str());

			if (value == NULL)
			{
				LOGI("Parsing JSON Failed");
				return;
			}

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

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

			std::vector<Receipt> receipts;

			for (unsigned int i = 0; i < data.size(); i++)
			{
				OuyaSDK::Receipt newReceipt;
				newReceipt.ParseJSON(data[i]);

				receipts.push_back(newReceipt);
			}
		
			CallbacksRequestReceipts* callback = CallbackSingleton::GetInstance()->m_callbacksRequestReceipts;
			if (callback)
			{
				callback->OnSuccess(receipts);
			}
		}