struct NB_Response* nb_response_create(int id) { struct NB_Response* response = calloc(1, sizeof(struct NB_Response)); struct PP_Var values; response->var = nb_var_dict_create(); if (!nb_var_dict_set(response->var, "id", PP_MakeInt32(id))) { NB_VERROR("nb_response_create failed to set \"id\" to %d.", id); goto cleanup; } values = nb_var_array_create(); if (!nb_var_dict_set(response->var, "values", values)) { NB_ERROR("nb_response_create failed to create \"values\" array."); nb_var_release(values); goto cleanup; } nb_var_release(values); return response; cleanup: nb_var_release(response->var); free(response); return NULL; }
NB_Bool nb_response_set_cb_id(struct NB_Response* response, int cb_id) { if (!nb_var_dict_set(response->var, "cbId", PP_MakeInt32(cb_id))) { NB_VERROR("nb_response_set_cb_id failed to set \"cbId\" to %d.", cb_id); return NB_FALSE; } return NB_TRUE; }
NB_Bool nb_response_set_error(struct NB_Response* response, int failed_command_idx) { if (!nb_var_dict_set(response->var, "error", PP_MakeInt32(failed_command_idx))) { NB_VERROR("nb_response_set_error(%d) failed.", failed_command_idx); return NB_FALSE; } return NB_TRUE; }
/** * Post a "progress" message to JavaScript. It has the form * { * "category": "progress", * "current": <number>, * "total": <number> * } */ int pp_post_progress(int current_page, int page_count) { struct PP_Var dict_var = g_ppb_var_dictionary->Create(); struct PP_Var cat_key = CStrToVar("category"); struct PP_Var cat_value = CStrToVar("progress"); PP_Bool result = g_ppb_var_dictionary->Set(dict_var, cat_key, cat_value); g_ppb_var->Release(cat_key); g_ppb_var->Release(cat_value); if (!result) { g_ppb_var->Release(dict_var); return 1; } struct PP_Var cur_key = CStrToVar("current"); struct PP_Var cur_value = PP_MakeInt32(current_page); result = g_ppb_var_dictionary->Set(dict_var, cur_key, cur_value); g_ppb_var->Release(cur_key); g_ppb_var->Release(cur_value); if (!result) { g_ppb_var->Release(dict_var); return 2; } struct PP_Var total_key = CStrToVar("total"); struct PP_Var total_value = PP_MakeInt32(page_count); result = g_ppb_var_dictionary->Set(dict_var, total_key, total_value); g_ppb_var->Release(total_key); g_ppb_var->Release(total_value); if (!result) { g_ppb_var->Release(dict_var); return 3; } g_ppb_messaging->PostMessage(g_instance, dict_var); g_ppb_var->Release(dict_var); return 0; }
/** * Invoke the function associated with @a name. * @param[in] object unused * @param[in] name method name * @param[in] argc number of arguments * @param[in] argv array of arguments * @param[out] exception pointer to the exception object, unused * @return If the method does exist, return true. */ static struct PP_Var Squeak_Call(void* object, struct PP_Var name, uint32_t argc, struct PP_Var* argv, struct PP_Var* exception) { struct PP_Var v = PP_MakeInt32(0); const char* method_name = VarToCStr(name); if (NULL != method_name) { if (strcmp(method_name, kPaintMethodId) == 0) { Paint(); return v; } if (strcmp(method_name, kGetStatusMethodId) == 0) return StrToVar(status); } return v; }
void SendInteger(int val) { psNaCLContext->psMessagingInterface->PostMessage(psNaCLContext->hModule, PP_MakeInt32(val)); }
void nspawn_dict_setint(struct PP_Var dict_var, const char* key, int32_t v) { nspawn_dict_set(dict_var, key, PP_MakeInt32(v)); }
/** * Append an int to the response dictionary. * @param[in,out] response_var The response PP_var. * @param[in] value The value to add to the response args. * @param[out] out_error An error message, if this call failed. */ static void AppendResponseInt(struct PP_Var* response_var, int32_t value, const char** out_error) { AppendResponseVar(response_var, PP_MakeInt32(value), out_error); }