void nspawn_array_setstring(struct PP_Var array, uint32_t index, const char* value) { struct PP_Var value_var = PSInterfaceVar()->VarFromUtf8(value, strlen(value)); PSInterfaceVarArray()->Set(array, index, value_var); PSInterfaceVar()->Release(value_var); }
void nspawn_dict_set(struct PP_Var dict, const char* key, struct PP_Var value_var) { struct PP_Var key_var = PSInterfaceVar()->VarFromUtf8(key, strlen(key)); PSInterfaceVarDictionary()->Set(dict, key_var, value_var); PSInterfaceVar()->Release(key_var); PSInterfaceVar()->Release(value_var); }
void network_error() { Json::Value writerRoot; writerRoot["result"] = 1; writerRoot["type"] = "network error"; Json::StyledWriter writer; std::string msg(writer.write(writerRoot)); struct PP_Var var = PSInterfaceVar()->VarFromUtf8(msg.data(), msg.length()); PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), var); PSInterfaceVar()->Release(var); }
bool nspawn_dict_has_key(struct PP_Var dict, const char* key, struct PP_Var* out_value) { assert(out_value); struct PP_Var key_var = PSInterfaceVar()->VarFromUtf8(key, strlen(key)); bool has_value = PSInterfaceVarDictionary()->HasKey(dict, key_var); if (has_value) { *out_value = PSInterfaceVarDictionary()->Get(dict, key_var); } PSInterfaceVar()->Release(key_var); return has_value; }
void nspawn_array_insert(struct PP_Var array, uint32_t index, struct PP_Var value_var) { uint32_t old_length = PSInterfaceVarArray()->GetLength(array); PSInterfaceVarArray()->SetLength(array, old_length + 1); for (uint32_t i = old_length; i > index; --i) { struct PP_Var from_var = PSInterfaceVarArray()->Get(array, i - 1); PSInterfaceVarArray()->Set(array, i, from_var); PSInterfaceVar()->Release(from_var); } PSInterfaceVarArray()->Set(array, index, value_var); PSInterfaceVar()->Release(value_var); }
void MessageHandlerInput(struct PP_Var key, struct PP_Var value, void* user_data) { uint32_t key_len; const char* key_str = PSInterfaceVar()->VarToUtf8(key, &key_len); const char* filename = NULL; if (strncmp(key_str, s_tty_prefix, key_len) == 0) { filename = "/dev/tty"; } else if (strncmp(key_str, "jspipe1", key_len) == 0) { filename = "/dev/jspipe1"; } else if (strncmp(key_str, "jspipe2", key_len) == 0) { filename = "/dev/jspipe2"; } else if (strncmp(key_str, "jspipe3", key_len) == 0) { filename = "/dev/jspipe3"; } else { PSInstanceError("unexpected input key: %s", key_str); return; } int fd = open(filename, O_RDONLY); if (fd < 0) { PSInstanceError("error opening file: %s (%s)", filename, strerror(errno)); return; } int ret = ioctl(fd, NACL_IOC_HANDLEMESSAGE, &value); if (ret != 0) { PSInstanceError("ioctl on %s failed: %d.\n", filename, ret); close(fd); return; } close(fd); }
/* * Handle reply from JavaScript. The key is the request string and the * value is Zero or positive on success or -errno on failure. The * user_data must be an instance of NaClSpawnReply. */ static void handle_reply(struct PP_Var key, struct PP_Var value, void* user_data) { if (key.type != PP_VARTYPE_STRING || value.type != PP_VARTYPE_DICTIONARY) { fprintf(stderr, "Invalid parameter for handle_reply\n"); fprintf(stderr, "key type=%d\n", key.type); fprintf(stderr, "value type=%d\n", value.type); } assert(key.type == PP_VARTYPE_STRING); assert(value.type == PP_VARTYPE_DICTIONARY); struct NaClSpawnReply* reply = (struct NaClSpawnReply*)user_data; pthread_mutex_lock(&reply->mu); PSInterfaceVar()->AddRef(value); reply->result_var = value; pthread_cond_signal(&reply->cond); pthread_mutex_unlock(&reply->mu); }
int NACL_VideoInit(_THIS) { SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata; SDL_DisplayMode mode; SDL_zero(mode); mode.format = driverdata->format; mode.w = driverdata->w; mode.h = driverdata->h; mode.refresh_rate = 0; mode.driverdata = NULL; if (SDL_AddBasicVideoDisplay(&mode) < 0) { return -1; } SDL_AddDisplayMode(&_this->displays[0], &mode); PSInterfaceInit(); driverdata->instance = PSGetInstanceId(); driverdata->ppb_graphics = PSInterfaceGraphics3D(); driverdata->ppb_message_loop = PSInterfaceMessageLoop(); driverdata->ppb_core = PSInterfaceCore(); driverdata->ppb_fullscreen = PSInterfaceFullscreen(); driverdata->ppb_instance = PSInterfaceInstance(); driverdata->ppb_image_data = PSInterfaceImageData(); driverdata->ppb_view = PSInterfaceView(); driverdata->ppb_var = PSInterfaceVar(); driverdata->ppb_input_event = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE); driverdata->ppb_keyboard_input_event = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE); driverdata->ppb_mouse_input_event = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE); driverdata->ppb_wheel_input_event = (PPB_WheelInputEvent*) PSGetInterface(PPB_WHEEL_INPUT_EVENT_INTERFACE); driverdata->ppb_touch_input_event = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE); driverdata->message_loop = driverdata->ppb_message_loop->Create(driverdata->instance); PSEventSetFilter(PSE_ALL); /* We're done! */ return 0; }
static void PostMessageString(const char* message) { struct PP_Var message_var = PSInterfaceVar()->VarFromUtf8(message, strlen(message)); PSInterfaceMessaging()->PostMessage(g_ps_instance, message_var); PSInterfaceVar()->Release(message_var); }
void nspawn_array_insertstring(struct PP_Var array, uint32_t index, const char* value) { struct PP_Var value_var = PSInterfaceVar()->VarFromUtf8(value, strlen(value)); nspawn_array_insert(array, index, value_var); }
void nspawn_dict_setstring(struct PP_Var dict, const char* key, const char* value) { struct PP_Var value_var = PSInterfaceVar()->VarFromUtf8(value, strlen(value)); nspawn_dict_set(dict, key, value_var); }
struct PP_Var nspawn_dict_get(struct PP_Var dict, const char* key) { struct PP_Var key_var = PSInterfaceVar()->VarFromUtf8(key, strlen(key)); struct PP_Var ret = PSInterfaceVarDictionary()->Get(dict, key_var); PSInterfaceVar()->Release(key_var); return ret; }
void nspawn_var_release(struct PP_Var var) { PSInterfaceVar()->Release(var); }