int do_explode(string str) { message("emote", "Testmon EXPLODES!", environment(this_object())); return 1; }
void Samu::FamilyCaregiverShell ( void ) { std::string cmd_prefix = "___"; fd_set rfds; struct timeval tmo; int sleep {0}; if ( sleep_ ) sleep = sleep_after_ + 1; for ( ; run_ ; ) { try { disp.cg_read(); if ( ++sleep > sleep_after_ ) { if ( !sleep_ ) { std::cerr << "Isaac went to sleep." << std::endl; disp.log ( "Isaac went to sleep." ); } sleep_ = true; } else { std::cerr << sleep << " " << std::flush; disp.log ( "." ); } } catch ( std::string line ) { if ( sleep_ ) { std::cerr << "Isaac is awake now." << std::endl; disp.log ( "\nIsaac is awake now." ); } sleep_ = false; sleep = 0; if ( !line.compare ( 0, cmd_prefix.length(), cmd_prefix ) ) { if ( line == cmd_prefix ) NextCaregiver(); } else { try { message ( -1, line ); } catch ( const char* err ) { std::cerr << err << std::endl; disp.log(err); } } } usleep ( 50*1000 ); } run_ = false; }
LRESULT kWindow::WindowProc(UINT uMsg,WPARAM wParam,LPARAM lParam) { return message((int)uMsg,(int)wParam,(int)lParam); }
void WdaMotif::change_value( int set_focus) { int sts; Widget text_w; int multiline; char *value; Arg args[5]; int input_size; if ( input_open) { XtUnmanageChild( cmd_input); set_prompt( ""); input_open = 0; return; } sts = ((WdaNav *)wdanav)->check_attr( &multiline, &input_node, input_name, &value, &input_size); if ( EVEN(sts)) { if ( sts == WDA__NOATTRSEL) message( 'E', "No attribute is selected"); else message( 'E', wnav_get_message( sts)); return; } if ( multiline) { text_w = cmd_scrolledinput; XtManageChild( text_w); XtManageChild( cmd_scrolled_ok); XtManageChild( cmd_scrolled_ca); // XtSetArg(args[0], XmNpaneMaximum, 300); // XtSetValues( wdanav_form, args, 1); XtSetArg(args[0], XmNmaxLength, input_size-1); XtSetValues( text_w, args, 1); if ( value) { XmTextSetString( text_w, value); // XmTextSetInsertionPosition( text_w, strlen(value)); } else XmTextSetString( text_w, (char*) ""); input_multiline = 1; } else { text_w = cmd_input; XtManageChild( text_w); XtSetArg(args[0],XmNmaxLength, input_size-1); XtSetValues( text_w, args, 1); if ( value) { XmTextSetString( text_w, value); XmTextSetInsertionPosition( text_w, strlen(value)); } else XmTextSetString( text_w, (char*) ""); input_multiline = 0; } if ( value) free( value); message( ' ', ""); if ( set_focus) flow_SetInputFocus( text_w); set_prompt( "value >"); input_open = 1; }
static vfs_path_t * exec_extension (void *target, const vfs_path_t * filename_vpath, const char *lc_data, int start_line) { char *shell_string, *export_variables; vfs_path_t *script_vpath = NULL; int cmd_file_fd; FILE *cmd_file; char *cmd = NULL; g_return_val_if_fail (lc_data != NULL, NULL); pbuffer = NULL; localmtime = 0; quote_func = name_quote; run_view = FALSE; is_cd = FALSE; written_nonspace = FALSE; /* Avoid making a local copy if we are doing a cd */ do_local_copy = !vfs_file_is_local (filename_vpath); shell_string = exec_make_shell_string (lc_data, filename_vpath); if (shell_string == NULL) goto ret; if (is_cd) { exec_extension_cd (); g_free (shell_string); goto ret; } /* * All commands should be run in /bin/sh regardless of user shell. * To do that, create temporary shell script and run it. * Sometimes it's not needed (e.g. for %cd and %view commands), * but it's easier to create it anyway. */ cmd_file_fd = mc_mkstemps (&script_vpath, "mcext", SCRIPT_SUFFIX); if (cmd_file_fd == -1) { message (D_ERROR, MSG_ERROR, _("Cannot create temporary command file\n%s"), unix_error_string (errno)); goto ret; } cmd_file = fdopen (cmd_file_fd, "w"); fputs ("#! /bin/sh\n\n", cmd_file); export_variables = exec_get_export_variables (filename_vpath); if (export_variables != NULL) { fprintf (cmd_file, "%s\n", export_variables); g_free (export_variables); } fputs (shell_string, cmd_file); g_free (shell_string); /* * Make the script remove itself when it finishes. * Don't do it for the viewer - it may need to rerun the script, * so we clean up after calling view(). */ if (!run_view) fprintf (cmd_file, "\n/bin/rm -f %s\n", vfs_path_as_str (script_vpath)); fclose (cmd_file); if ((run_view && !written_nonspace) || is_cd) { exec_cleanup_script (script_vpath); script_vpath = NULL; } else { /* Set executable flag on the command file ... */ mc_chmod (script_vpath, S_IRWXU); /* ... but don't rely on it - run /bin/sh explicitly */ cmd = g_strconcat ("/bin/sh ", vfs_path_as_str (script_vpath), (char *) NULL); } if (run_view) { /* If we've written whitespace only, then just load filename into view */ if (!written_nonspace) exec_extension_view (target, NULL, filename_vpath, start_line); else exec_extension_view (target, cmd, filename_vpath, start_line); } else { shell_execute (cmd, EXECUTE_INTERNAL); if (mc_global.tty.console_flag != '\0') { handle_console (CONSOLE_SAVE); if (output_lines && mc_global.keybar_visible) show_console_contents (output_start_y, LINES - mc_global.keybar_visible - output_lines - 1, LINES - mc_global.keybar_visible - 1); } } g_free (cmd); exec_cleanup_file_name (filename_vpath, TRUE); ret: return script_vpath; }
/// Attempts to read message, returns true if successful, false otherwise bool SourceNode::processMessage() { String strMess; Message * mess; bool isNew; bool messageProcessed = false; unsigned long timeStamp; Serial.println("."); _xbee.readPacket(); if (_xbee.getResponse().isAvailable()) { Serial.println("\n<<<<<"); messageProcessed = true; strMess = receiveMessage(); if (!strMess.equals("")) { mess = MessageConverter::parse(strMess); isNew = _history.add(mess->getSender(), mess->getSequenceNumber()); char humanReadableSender[9]; sprintf(humanReadableSender, "%08lX", mess->getSender()); Serial.println("Message available from "+String(humanReadableSender)); if(isNew) { if(mess->getMessageType() == Message::ALERT) { //new alert received Lcd::getInstance()->display("[A:sender]: "+String(humanReadableSender)); Serial.println("New alert received from "+String(humanReadableSender)); if (_level > 0 && mess->getSenderLevel() > _level) { //TODO Check test : should relay all messages (whatever the level) ? //our level is set since _level != 0 //Message originates from sender with higher level // Alert alert(mess->getAlert().getAlertType(), mess->getAlert().getSensorValue()); // AlertMessage message( // mess->getSender(), // mess->getSequenceNumber(), // mess->getSenderLevel(), // alert // ); send(*mess); String sensorValue = Utility::Convert::floatToString(mess->getAlert().getSensorValue()); Lcd::getInstance()->display("[A:value]: " + sensorValue); Serial.println("Value: " + sensorValue); } else { //TODO //_level not set yet, no discovery received //store message for the moment //Just drop it! Lcd::getInstance()->display("[A:ignored]"); Serial.println("Alert ignored : no route to host yet or alert from lower level."); } } else { //Discovery message //Is it a new discovery sequence ? bool isNewDiscoverySequence = MessageHistory::isNewer(_lastDiscoverySequence, mess->getSequenceNumber()); //Were we part of a discovery newer than the incoming discovery bool isOldDiscoverySequence = MessageHistory::isNewer(mess->getSequenceNumber(), _lastDiscoverySequence); if (isNewDiscoverySequence || _level == 0) { //set level _level = mess->getSenderLevel() + 1; //record sequence nummber _lastDiscoverySequence = mess->getSequenceNumber(); //store gateway to sink _firstGatewayToSink = mess->getSender(); //Lcd and serial display Lcd::getInstance()->display("[D]: START"); Lcd::getInstance()->newLine(); Serial.println("New discovery sequence"); Lcd::getInstance()->display("[D:level]: "+String(_level)); Serial.println("Discovery received from level " + String(mess->getSenderLevel())); Serial.println("Setting level to "+String(_level)); //Prepare message and send message DiscoveryMessage message( _myAddress, mess->getSequenceNumber(), _level ); send(message); } else if (mess->getSequenceNumber() == _lastDiscoverySequence && (mess->getSenderLevel() + 1) == _level) { //Store as gateway only if level == own level - 1 //New route to gateway discovered _lastGatewayToSink = mess->getSender(); Lcd::getInstance()->display("[D:+gw]: " + String(humanReadableSender)); Serial.println("New level "+String(mess->getSenderLevel())+" gateway"); } } } else { Serial.println(String("Duplicate message : ")+strMess+String(" found in history.")); } delete mess; } Serial.println(">>>>>"); } return messageProcessed; }
static void parse_args(FAR struct wdog_example_s *wdog, int argc, FAR char **argv) { FAR char *ptr; long value; int index; int nargs; wdog->pingtime = CONFIG_EXAMPLES_WATCHDOG_PINGTIME; wdog->pingdelay = CONFIG_EXAMPLES_WATCHDOG_PINGDELAY; wdog->timeout = CONFIG_EXAMPLES_WATCHDOG_TIMEOUT; for (index = 1; index < argc; ) { ptr = argv[index]; if (ptr[0] != '-') { message("Invalid options format: %s\n", ptr); exit(EXIT_SUCCESS); } switch (ptr[1]) { case 'd': nargs = arg_decimal(&argv[index], &value); if (value < 1) { message("Ping delay out of range: %ld\n", value); exit(EXIT_FAILURE); } wdog->pingdelay = (uint32_t)value; index += nargs; break; case 'p': nargs = arg_decimal(&argv[index], &value); if (value < 1 || value > 99) { message("Ping time out of range: %ld\n", value); exit(EXIT_FAILURE); } wdog->pingtime = (uint8_t)value; index += nargs; break; case 't': nargs = arg_decimal(&argv[index], &value); if (value < 1 || value > INT_MAX) { message("Duration out of range: %ld\n", value); exit(EXIT_FAILURE); } wdog->timeout = (int)value; index += nargs; break; case 'h': wdog_help(); exit(EXIT_SUCCESS); default: message("Unsupported option: %s\n", ptr); wdog_help(); exit(EXIT_FAILURE); } } }
//////////////////////////////////////////////////////////////////////////////// // virtual void onWindowCloseRequested(const EventType& event) { LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "close_request"); message.setValue("uuid", event.getStringValue()); sendMessage(message); }
void MediaPluginWebKit::receiveMessage(const char *message_string) { // std::cerr << "MediaPluginWebKit::receiveMessage: received message: \"" << message_string << "\"" << std::endl; LLPluginMessage message_in; if(message_in.parse(message_string) >= 0) { std::string message_class = message_in.getClass(); std::string message_name = message_in.getName(); if(message_class == LLPLUGIN_MESSAGE_CLASS_BASE) { if(message_name == "init") { LLPluginMessage message("base", "init_response"); LLSD versions = LLSD::emptyMap(); versions[LLPLUGIN_MESSAGE_CLASS_BASE] = LLPLUGIN_MESSAGE_CLASS_BASE_VERSION; versions[LLPLUGIN_MESSAGE_CLASS_MEDIA] = LLPLUGIN_MESSAGE_CLASS_MEDIA_VERSION; versions[LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER] = LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER_VERSION; message.setValueLLSD("versions", versions); std::string plugin_version = "Webkit media plugin, Webkit version "; plugin_version += LLQtWebKit::getInstance()->getVersion(); message.setValue("plugin_version", plugin_version); sendMessage(message); } else if(message_name == "idle") { // no response is necessary here. F64 time = message_in.getValueReal("time"); // Convert time to milliseconds for update() update((int)(time * 1000.0f)); } else if(message_name == "cleanup") { // DTOR most likely won't be called but the recent change to the way this process // is (not) killed means we see this message and can do what we need to here. // Note: this cleanup is ultimately what writes cookies to the disk LLQtWebKit::getInstance()->remObserver( mBrowserWindowId, this ); LLQtWebKit::getInstance()->reset(); } else if(message_name == "shm_added") { SharedSegmentInfo info; info.mAddress = message_in.getValuePointer("address"); info.mSize = (size_t)message_in.getValueS32("size"); std::string name = message_in.getValue("name"); // std::cerr << "MediaPluginWebKit::receiveMessage: shared memory added, name: " << name // << ", size: " << info.mSize // << ", address: " << info.mAddress // << std::endl; mSharedSegments.insert(SharedSegmentMap::value_type(name, info)); } else if(message_name == "shm_remove") { std::string name = message_in.getValue("name"); // std::cerr << "MediaPluginWebKit::receiveMessage: shared memory remove, name = " << name << std::endl; SharedSegmentMap::iterator iter = mSharedSegments.find(name); if(iter != mSharedSegments.end()) { if(mPixels == iter->second.mAddress) { // This is the currently active pixel buffer. Make sure we stop drawing to it. mPixels = NULL; mTextureSegmentName.clear(); } mSharedSegments.erase(iter); } else { // std::cerr << "MediaPluginWebKit::receiveMessage: unknown shared memory region!" << std::endl; } // Send the response so it can be cleaned up. LLPluginMessage message("base", "shm_remove_response"); message.setValue("name", name); sendMessage(message); } else { // std::cerr << "MediaPluginWebKit::receiveMessage: unknown base message: " << message_name << std::endl; } } else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_TIME) { if(message_name == "set_volume") { F32 volume = message_in.getValueReal("volume"); setVolume(volume); } } else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA) { if(message_name == "init") { mTarget = message_in.getValue("target"); // This is the media init message -- all necessary data for initialization should have been received. if(initBrowser()) { // Plugin gets to decide the texture parameters to use. mDepth = 4; LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "texture_params"); message.setValueS32("default_width", 1024); message.setValueS32("default_height", 1024); message.setValueS32("depth", mDepth); message.setValueU32("internalformat", GL_RGBA); #if LL_QTWEBKIT_USES_PIXMAPS message.setValueU32("format", GL_BGRA_EXT); // I hope this isn't system-dependant... is it? If so, we'll have to check the root window's pixel layout or something... yuck. #else message.setValueU32("format", GL_RGBA); #endif // LL_QTWEBKIT_USES_PIXMAPS message.setValueU32("type", GL_UNSIGNED_BYTE); message.setValueBoolean("coords_opengl", true); sendMessage(message); } else { // if initialization failed, we're done. mDeleteMe = true; } } else if(message_name == "set_user_data_path") { std::string user_data_path = message_in.getValue("path"); // n.b. always has trailing platform-specific dir-delimiter mProfileDir = user_data_path + "browser_profile"; // FIXME: Should we do anything with this if it comes in after the browser has been initialized? } else if(message_name == "set_language_code") { mHostLanguage = message_in.getValue("language"); // FIXME: Should we do anything with this if it comes in after the browser has been initialized? } else if(message_name == "plugins_enabled") { mPluginsEnabled = message_in.getValueBoolean("enable"); } else if(message_name == "javascript_enabled") { mJavascriptEnabled = message_in.getValueBoolean("enable"); } else if(message_name == "size_change") { std::string name = message_in.getValue("name"); S32 width = message_in.getValueS32("width"); S32 height = message_in.getValueS32("height"); S32 texture_width = message_in.getValueS32("texture_width"); S32 texture_height = message_in.getValueS32("texture_height"); mBackgroundR = message_in.getValueReal("background_r"); mBackgroundG = message_in.getValueReal("background_g"); mBackgroundB = message_in.getValueReal("background_b"); // mBackgroundA = message_in.setValueReal("background_a"); // Ignore any alpha if(!name.empty()) { // Find the shared memory region with this name SharedSegmentMap::iterator iter = mSharedSegments.find(name); if(iter != mSharedSegments.end()) { mPixels = (unsigned char*)iter->second.mAddress; mWidth = width; mHeight = height; if(initBrowserWindow()) { // size changed so tell the browser LLQtWebKit::getInstance()->setSize( mBrowserWindowId, mWidth, mHeight ); // std::cerr << "webkit plugin: set size to " << mWidth << " x " << mHeight // << ", rowspan is " << LLQtWebKit::getInstance()->getBrowserRowSpan(mBrowserWindowId) << std::endl; S32 real_width = LLQtWebKit::getInstance()->getBrowserRowSpan(mBrowserWindowId) / LLQtWebKit::getInstance()->getBrowserDepth(mBrowserWindowId); // The actual width the browser will be drawing to is probably smaller... let the host know by modifying texture_width in the response. if(real_width <= texture_width) { texture_width = real_width; } else { // This won't work -- it'll be bigger than the allocated memory. This is a fatal error. // std::cerr << "Fatal error: browser rowbytes greater than texture width" << std::endl; mDeleteMe = true; return; } } else { // Setting up the browser window failed. This is a fatal error. mDeleteMe = true; } mTextureWidth = texture_width; mTextureHeight = texture_height; }; }; LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "size_change_response"); message.setValue("name", name); message.setValueS32("width", width); message.setValueS32("height", height); message.setValueS32("texture_width", texture_width); message.setValueS32("texture_height", texture_height); sendMessage(message); } else if(message_name == "load_uri") { std::string uri = message_in.getValue("uri"); // std::cout << "loading URI: " << uri << std::endl; if(!uri.empty()) { if(mInitState >= INIT_STATE_NAVIGATE_COMPLETE) { LLQtWebKit::getInstance()->navigateTo( mBrowserWindowId, uri ); } else { mInitialNavigateURL = uri; } } } else if(message_name == "mouse_event") { std::string event = message_in.getValue("event"); S32 button = message_in.getValueS32("button"); mLastMouseX = message_in.getValueS32("x"); mLastMouseY = message_in.getValueS32("y"); std::string modifiers = message_in.getValue("modifiers"); // Treat unknown mouse events as mouse-moves. LLQtWebKit::EMouseEvent mouse_event = LLQtWebKit::ME_MOUSE_MOVE; if(event == "down") { mouse_event = LLQtWebKit::ME_MOUSE_DOWN; } else if(event == "up") { mouse_event = LLQtWebKit::ME_MOUSE_UP; } else if(event == "double_click") { mouse_event = LLQtWebKit::ME_MOUSE_DOUBLE_CLICK; } LLQtWebKit::getInstance()->mouseEvent( mBrowserWindowId, mouse_event, button, mLastMouseX, mLastMouseY, decodeModifiers(modifiers)); checkEditState(); } else if(message_name == "scroll_event") { S32 x = message_in.getValueS32("x"); S32 y = message_in.getValueS32("y"); std::string modifiers = message_in.getValue("modifiers"); // Incoming scroll events are adjusted so that 1 detent is approximately 1 unit. // Qt expects 1 detent to be 120 units. // It also seems that our y scroll direction is inverted vs. what Qt expects. x *= 120; y *= -120; LLQtWebKit::getInstance()->scrollWheelEvent(mBrowserWindowId, mLastMouseX, mLastMouseY, x, y, decodeModifiers(modifiers)); } else if(message_name == "key_event") { std::string event = message_in.getValue("event"); S32 key = message_in.getValueS32("key"); std::string modifiers = message_in.getValue("modifiers"); LLSD native_key_data = message_in.getValueLLSD("native_key_data"); // Treat unknown events as key-up for safety. LLQtWebKit::EKeyEvent key_event = LLQtWebKit::KE_KEY_UP; if(event == "down") { key_event = LLQtWebKit::KE_KEY_DOWN; } else if(event == "repeat") { key_event = LLQtWebKit::KE_KEY_REPEAT; } keyEvent(key_event, key, decodeModifiers(modifiers), native_key_data); } else if(message_name == "text_event") { std::string text = message_in.getValue("text"); std::string modifiers = message_in.getValue("modifiers"); LLSD native_key_data = message_in.getValueLLSD("native_key_data"); unicodeInput(text, decodeModifiers(modifiers), native_key_data); } if(message_name == "edit_cut") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_CUT ); checkEditState(); } if(message_name == "edit_copy") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_COPY ); checkEditState(); } if(message_name == "edit_paste") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_PASTE ); checkEditState(); } if(message_name == "pick_file_response") { onPickFileResponse(message_in.getValue("file")); } else { // std::cerr << "MediaPluginWebKit::receiveMessage: unknown media message: " << message_string << std::endl; } } else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER) { if(message_name == "focus") { bool val = message_in.getValueBoolean("focused"); LLQtWebKit::getInstance()->focusBrowser( mBrowserWindowId, val ); if(mFirstFocus && val) { // On the first focus, post a tab key event. This fixes a problem with initial focus. std::string empty; keyEvent(LLQtWebKit::KE_KEY_DOWN, KEY_TAB, decodeModifiers(empty)); keyEvent(LLQtWebKit::KE_KEY_UP, KEY_TAB, decodeModifiers(empty)); mFirstFocus = false; } } else if(message_name == "clear_cache") { LLQtWebKit::getInstance()->clearCache(); } else if(message_name == "clear_cookies") { LLQtWebKit::getInstance()->clearAllCookies(); } else if(message_name == "enable_cookies") { mCookiesEnabled = message_in.getValueBoolean("enable"); LLQtWebKit::getInstance()->enableCookies( mCookiesEnabled ); } else if(message_name == "enable_plugins") { mPluginsEnabled = message_in.getValueBoolean("enable"); LLQtWebKit::getInstance()->enablePlugins( mPluginsEnabled ); } else if(message_name == "enable_javascript") { mJavascriptEnabled = message_in.getValueBoolean("enable"); //LLQtWebKit::getInstance()->enableJavascript( mJavascriptEnabled ); } else if(message_name == "set_cookies") { LLQtWebKit::getInstance()->setCookies(message_in.getValue("cookies")); } else if(message_name == "proxy_setup") { bool val = message_in.getValueBoolean("enable"); std::string host = message_in.getValue("host"); int port = message_in.getValueS32("port"); LLQtWebKit::getInstance()->enableProxy( val, host, port ); } else if(message_name == "browse_stop") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_STOP ); } else if(message_name == "browse_reload") { // foo = message_in.getValueBoolean("ignore_cache"); LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_RELOAD ); } else if(message_name == "browse_forward") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_FORWARD ); } else if(message_name == "browse_back") { LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_NAVIGATE_BACK ); } else if(message_name == "set_status_redirect") { int code = message_in.getValueS32("code"); std::string url = message_in.getValue("url"); if ( 404 == code ) // browser lib only supports 404 right now { LLQtWebKit::getInstance()->set404RedirectUrl( mBrowserWindowId, url ); }; } else if(message_name == "set_user_agent") { mUserAgent = message_in.getValue("user_agent"); LLQtWebKit::getInstance()->setBrowserAgentId( mUserAgent ); } else if(message_name == "init_history") { // Initialize browser history LLSD history = message_in.getValueLLSD("history"); // First, clear the URL history LLQtWebKit::getInstance()->clearHistory(mBrowserWindowId); // Then, add the history items in order LLSD::array_iterator iter_history = history.beginArray(); LLSD::array_iterator end_history = history.endArray(); for(; iter_history != end_history; ++iter_history) { std::string url = (*iter_history).asString(); if(! url.empty()) { LLQtWebKit::getInstance()->prependHistoryUrl(mBrowserWindowId, url); } } } else if(message_name == "proxy_window_opened") { std::string target = message_in.getValue("target"); std::string uuid = message_in.getValue("uuid"); LLQtWebKit::getInstance()->proxyWindowOpened(mBrowserWindowId, target, uuid); } else if(message_name == "proxy_window_closed") { std::string uuid = message_in.getValue("uuid"); LLQtWebKit::getInstance()->proxyWindowClosed(mBrowserWindowId, uuid); } else { // std::cerr << "MediaPluginWebKit::receiveMessage: unknown media_browser message: " << message_string << std::endl; }; } else { // std::cerr << "MediaPluginWebKit::receiveMessage: unknown message class: " << message_class << std::endl; }; } }
void LLPluginProcessChild::idle(void) { bool idle_again; do { if(APR_STATUS_IS_EOF(mSocketError)) { // Plugin socket was closed. This covers both normal plugin termination and host crashes. setState(STATE_ERROR); } else if(mSocketError != APR_SUCCESS) { LL_INFOS("Plugin") << "message pipe is in error state (" << mSocketError << "), moving to STATE_ERROR"<< LL_ENDL; setState(STATE_ERROR); } if((mState > STATE_INITIALIZED) && (mMessagePipe == NULL)) { // The pipe has been closed -- we're done. // TODO: This could be slightly more subtle, but I'm not sure it needs to be. LL_INFOS("Plugin") << "message pipe went away, moving to STATE_ERROR"<< LL_ENDL; setState(STATE_ERROR); } // If a state needs to go directly to another state (as a performance enhancement), it can set idle_again to true after calling setState(). // USE THIS CAREFULLY, since it can starve other code. Specifically make sure there's no way to get into a closed cycle and never return. // When in doubt, don't do it. idle_again = false; if(mInstance != NULL) { // Provide some time to the plugin mInstance->idle(); } switch(mState) { case STATE_UNINITIALIZED: break; case STATE_INITIALIZED: if(mSocket->blockingConnect(mLauncherHost)) { // This automatically sets mMessagePipe new LLPluginMessagePipe(this, mSocket); setState(STATE_CONNECTED); } else { // connect failed setState(STATE_ERROR); } break; case STATE_CONNECTED: sendMessageToParent(LLPluginMessage(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "hello")); setState(STATE_PLUGIN_LOADING); break; case STATE_PLUGIN_LOADING: if(!mPluginFile.empty()) { mInstance = new LLPluginInstance(this); if(mInstance->load(mPluginDir, mPluginFile) == 0) { mHeartbeat.start(); mHeartbeat.setTimerExpirySec(HEARTBEAT_SECONDS); mCPUElapsed = 0.0f; setState(STATE_PLUGIN_LOADED); } else { setState(STATE_ERROR); } } break; case STATE_PLUGIN_LOADED: { setState(STATE_PLUGIN_INITIALIZING); LLPluginMessage message("base", "init"); sendMessageToPlugin(message); } break; case STATE_PLUGIN_INITIALIZING: // waiting for init_response... break; case STATE_RUNNING: if(mInstance != NULL) { // Provide some time to the plugin LLPluginMessage message("base", "idle"); message.setValueReal("time", PLUGIN_IDLE_SECONDS); sendMessageToPlugin(message); mInstance->idle(); if(mHeartbeat.hasExpired()) { // This just proves that we're not stuck down inside the plugin code. LLPluginMessage heartbeat(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "heartbeat"); // Calculate the approximage CPU usage fraction (floating point value between 0 and 1) used by the plugin this heartbeat cycle. // Note that this will not take into account any threads or additional processes the plugin spawns, but it's a first approximation. // If we could write OS-specific functions to query the actual CPU usage of this process, that would be a better approximation. heartbeat.setValueReal("cpu_usage", mCPUElapsed / mHeartbeat.getElapsedTimeF64()); sendMessageToParent(heartbeat); mHeartbeat.reset(); mHeartbeat.setTimerExpirySec(HEARTBEAT_SECONDS); mCPUElapsed = 0.0f; } } // receivePluginMessage will transition to STATE_UNLOADING break; case STATE_UNLOADING: if(mInstance != NULL) { sendMessageToPlugin(LLPluginMessage("base", "cleanup")); delete mInstance; mInstance = NULL; } setState(STATE_UNLOADED); break; case STATE_UNLOADED: killSockets(); setState(STATE_DONE); break; case STATE_ERROR: // Close the socket to the launcher killSockets(); // TODO: Where do we go from here? Just exit()? setState(STATE_DONE); break; case STATE_DONE: // just sit here. break; } } while (idle_again); }
//////////////////////////////////////////////////////////////////////////////// // virtual void onClickLinkNoFollow(const EventType& event) { LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_nofollow"); message.setValue("uri", event.getEventUri()); sendMessage(message); }
__EXPORT int stm32_spi_bus_initialize(void) { /* Configure SPI-based devices */ /* Get the SPI port for the Sensors */ spi_sensors = stm32_spibus_initialize(PX4_SPI_BUS_SENSORS); if (!spi_sensors) { message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_SENSORS); return -ENODEV; } /* Default PX4_SPI_BUS_SENSORS to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi_sensors, 10000000); SPI_SETBITS(spi_sensors, 8); SPI_SETMODE(spi_sensors, SPIDEV_MODE3); for (int cs = PX4_SENSORS_BUS_FIRST_CS; cs <= PX4_SENSORS_BUS_LAST_CS; cs++) { SPI_SELECT(spi_sensors, cs, false); } /* Get the SPI port for the Memory */ spi_memory = stm32_spibus_initialize(PX4_SPI_BUS_MEMORY); if (!spi_memory) { message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_MEMORY); return -ENODEV; } /* Default PX4_SPI_BUS_MEMORY to 12MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi_memory, 12 * 1000 * 1000); SPI_SETBITS(spi_memory, 8); SPI_SETMODE(spi_memory, SPIDEV_MODE3); for (int cs = PX4_MEMORY_BUS_FIRST_CS; cs <= PX4_MEMORY_BUS_LAST_CS; cs++) { SPI_SELECT(spi_memory, cs, false); } /* Get the SPI port for the BARO */ spi_baro = stm32_spibus_initialize(PX4_SPI_BUS_BARO); if (!spi_baro) { message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_BARO); return -ENODEV; } /* MS5611 has max SPI clock speed of 20MHz */ SPI_SETFREQUENCY(spi_baro, 20 * 1000 * 1000); SPI_SETBITS(spi_baro, 8); SPI_SETMODE(spi_baro, SPIDEV_MODE3); for (int cs = PX4_BARO_BUS_FIRST_CS; cs <= PX4_BARO_BUS_LAST_CS; cs++) { SPI_SELECT(spi_baro, cs, false); } /* Get the SPI port for the PX4_SPI_EXTERNAL */ spi_ext = stm32_spibus_initialize(PX4_SPI_BUS_EXTERNAL); if (!spi_ext) { message("[boot] FAILED to initialize SPI port %d\n", PX4_SPI_BUS_EXTERNAL); return -ENODEV; } SPI_SETFREQUENCY(spi_ext, 8 * 1000 * 1000); SPI_SETBITS(spi_ext, 8); SPI_SETMODE(spi_ext, SPIDEV_MODE3); for (int cs = PX4_EXTERNAL_BUS_FIRST_CS; cs <= PX4_EXTERNAL_BUS_LAST_CS; cs++) { SPI_SELECT(spi_ext, cs, false); } return OK; }
__EXPORT int nsh_archinitialize(void) { int result; message("\n"); /* configure always-on ADC pins */ stm32_configgpio(GPIO_ADC1_IN10); stm32_configgpio(GPIO_ADC1_IN11); #if APM_BUILD_TYPE(APM_BUILD_ArduPlane) stm32_configgpio(GPIO_GPIO0_INPUT); stm32_configgpio(GPIO_ADC1_IN14); #endif stm32_configgpio(GPIO_SBUS_ENABLE); #if CONFIG_RC_INPUTS_TYPE(RC_INPUT_SBUS) stm32_gpiowrite(GPIO_SBUS_ENABLE, 0); #else stm32_gpiowrite(GPIO_SBUS_ENABLE, 1); #endif #if !CONFIG_RC_INPUTS_TYPE(RC_INPUT_PWM) stm32_configgpio(GPIO_GPIO5_OUTPUT); #endif /* configure the high-resolution time/callout interface */ hrt_init(); /* configure the DMA allocator */ dma_alloc_init(); /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); /* initial BUZZER state */ drv_buzzer_start(); buzzer_off(BUZZER_EXT); /* initial LED state */ drv_led_start(); led_off(LED_AMBER); led_off(LED_BLUE); led_off(LED_GREEN); led_off(LED_EXT1); led_off(LED_EXT2); /* Configure SPI-based devices */ message("[boot] Initializing SPI port 1\n"); spi1 = up_spiinitialize(1); if (!spi1) { message("[boot] FAILED to initialize SPI port 1\r\n"); led_on(LED_AMBER); return -ENODEV; } /* Default SPI1 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi1, 10000000); SPI_SETBITS(spi1, 8); SPI_SETMODE(spi1, SPIDEV_MODE3); SPI_SELECT(spi1, SPIDEV_WIRELESS, false); SPI_SELECT(spi1, SPIDEV_FLASH, false); SPI_SELECT(spi1, SPIDEV_MS5611, false); SPI_SELECT(spi1, SPIDEV_EXP_MS5611, false); SPI_SELECT(spi1, SPIDEV_EXP_MPU6000, false); SPI_SELECT(spi1, SPIDEV_EXP_HMC5983, false); up_udelay(20); message("[boot] Successfully initialized SPI port 1\r\n"); message("[boot] Initializing SPI port 2\n"); spi2 = up_spiinitialize(2); if (!spi2) { message("[boot] FAILED to initialize SPI port 2\r\n"); led_on(LED_AMBER); return -ENODEV; } /* Default SPI2 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi2, 10000000); SPI_SETBITS(spi2, 8); SPI_SETMODE(spi2, SPIDEV_MODE3); SPI_SELECT(spi2, SPIDEV_MPU6000, false); SPI_SELECT(spi2, SPIDEV_IMU_MS5611, false); SPI_SELECT(spi2, SPIDEV_IMU_MPU6000, false); SPI_SELECT(spi2, SPIDEV_IMU_HMC5983, false); SPI_SELECT(spi2, SPIDEV_FLASH, false); message("[boot] Successfully initialized SPI port 2\n"); /* Get the SPI port for the microSD slot */ message("[boot] Initializing SPI port 3\n"); spi3 = up_spiinitialize(3); if (!spi3) { message("[boot] FAILED to initialize SPI port 3\n"); led_on(LED_AMBER); return -ENODEV; } /* Default SPI3 to 1MHz and de-assert the known chip selects. */ SPI_SETFREQUENCY(spi3, 10000000); SPI_SETBITS(spi3, 8); SPI_SETMODE(spi3, SPIDEV_MODE3); SPI_SELECT(spi3, SPIDEV_MMCSD, false); SPI_SELECT(spi3, SPIDEV_FLASH, false); message("[boot] Successfully initialized SPI port 3\n"); /* Now bind the SPI interface to the MMCSD driver */ result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3); if (result != OK) { message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\n"); led_on(LED_AMBER); return -ENODEV; } message("[boot] Successfully bound SPI port 3 to the MMCSD driver\n"); return OK; }
int do_claim(string str) { set_owner(this_player()); message("info", "Claimed Testmon.", this_player() ); return 1; }
void help() { object tp=this_player(); message("help","\nSyntax: <flamewall>\n" "This spell causes flames to spring up around the caster. " "The flames burn anything that tries to harm the caster.",tp); }
int main(object me, string arg) { object where = environment(me); object ob; string zhao_name; mapping skill; int my_skill, cost; if (where->query("pigging")) return notify_fail("你还是专心拱猪吧!\n"); if (me->is_busy()) return notify_fail("你现在正忙着呢。\n"); if( me->is_fighting() ) return notify_fail("你无法在战斗中专心下来研读新知!\n"); if(!arg || !objectp(ob = present(arg, me)) ) return notify_fail("你要读什么?\n"); if( !mapp(skill = ob->query("skill")) ) return notify_fail("你无法从这样东西学到任何东西。\n"); if( !me->query_skill("literate", 1) ) return notify_fail("你是个文盲,先学点文化(literate)吧。\n"); message("vision", me->name() + "正专心地研读" + ob->name() + "。\n", environment(me), me); if( (int)me->query("combat_exp") < skill["exp_required"] ) { write("你的实战经验不足,再怎么读也没用。\n"); return 1; } if ( skill["difficulty"] - (int)me->query_int() > 0 ) return notify_fail("以你目前的能力,还没有办法学这个技能。\n"); if( !SKILL_D(skill["name"])->valid_learn(me) ) return 0; cost = skill["jing_cost"] + skill["jing_cost"] * (skill["difficulty"] - (int)me->query_int())/20; if (cost < 1) cost = 0; // minimum cost if( me->query_skill(skill["name"], 1) > skill["max_skill"] ) { write("你研读了一会儿,但是发现上面所说的对你而言都太浅了,没有学到任何东西。\n"); return 1; } if( !me->query_skill(skill["name"], 1) ) me->set_skill(skill["name"], 0); my_skill = me->query_skill(skill["name"], 1); if( (int)me->query("jing") > cost ) { if( (string)SKILL_D(skill["name"])->type()=="martial" && my_skill * my_skill * my_skill / 10 > (int)me->query("combat_exp") ) { printf("也许是缺乏实战经验,你对%s上面所说的东西总是无法领会。\n", ob->name()); } else { if(zhao_name = SKILL_D(skill["name"])->query_skill_name(my_skill)) printf("你研读有关%s的技巧,对「%s」这一招似乎有些心得。\n", to_chinese(skill["name"]), zhao_name); else printf("你研读有关%s的技巧,似乎有点心得。\n", to_chinese(skill["name"])); me->improve_skill(skill["name"], random((int)me->query_skill("literate", 1)/2)+1); } } else { cost = me->query("jing"); write("你现在过于疲倦,无法专心下来研读新知。\n"); } me->receive_damage("jing", cost ); return 1; }
int main(int argc, char * argv[]) { int rc; HFILE hfNew; HWND hwndNotify; char *text; HPIPE hpR, hpW; ULONG cbRead, cbWritten; CHAR achBuf[PIPESIZE]={0}; CHAR szFailName[CCHMAXPATH]; HFILE hfSave; RESULTCODES ChildRC= {0}; int a; int iBlocks; rc=-1; if(argc<4) { message(); exit(-1); } hwndNotify=atol(argv[1]); /* Print the parameters in VIO window */ printf("argc:%d\n",argc); for(a=0;a<argc;a++) { printf("%d: %s\n",a,argv[a]); } printf("\n"); memset(achBuf, 0, sizeof(achBuf)); /* sprintf(achBuf,"%s %s -toc -v",argv[2],argv[3]); */ sprintf(achBuf,"%s",argv[3]); text=strchr(achBuf,0); if(!text) { WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(4),MPFROMLONG(0)); } text++; sprintf(text,"%s", argv[4]); printf("Parameters for size query: %s\n",text); text=achBuf; printf("Path is: %s\n",text); /**** start ****/ /* Redirect stdout */ hfSave = -1;// Get new handle hfNew = HF_STDOUT; if(!DosDupHandle(HF_STDOUT, &hfSave)){ /* Saves standard handle */ if(!DosCreatePipe(&hpR, &hpW, PIPESIZE)){ /* Creates pipe */ /* If the pipe size is smaller than the output of the child the system() call blocks. So create the pipe big enough. */ if(!DosDupHandle(hpW, &hfNew)){ /* Duplicates standard output handle */ /* start CDRecord/2 */ rc=DosExecPgm(szFailName,sizeof(szFailName),EXEC_ASYNC, text,NULL,&ChildRC, text); fprintf(stderr,"DosExecPgm() for dvddao returned: %d\n",rc); /* rc=system(text); */ DosClose(hpW); /* Closes write handle to ensure */ /* Notification at child termination */ DosDupHandle(hfSave, &hfNew); /* Brings stdout back */ /* * Read from the pipe and write to the screen * as long as there are bytes to read. */ do { BOOL bNoMedia=FALSE; DosRead(hpR, achBuf, sizeof(achBuf), &cbRead); DosWrite(HF_STDERR, achBuf, cbRead, &cbWritten); /* Uppercase string */ strupr(achBuf); text=strstr(achBuf,"NO MEDIA"); if(text){ /* No DVD/CD inserted */ iBlocks=0; //WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(4),MPFROMLONG(0)); bNoMedia=TRUE; break; } text=strstr(achBuf,"MEDIA SIZE"); if(text){ char dummy[200]; /* We have the size */ sscanf(text, "%s %s %d", dummy, dummy, &iBlocks); break; } } while(cbRead); printf("Num blocks found %d \n",iBlocks); DosClose(hpR); } } }/* if(!DosDupHandle(HF_STDERR, &hfSave)) */ printf("Errorcode from dvddao is: %d\n",rc); /* Send msg. to the notification window */ WinPostMsg(hwndNotify,WM_APPTERMINATENOTIFY,MPFROMLONG(4),MPFROMLONG(iBlocks)); exit(0); }
real_T logpdf(const emxArray_real_T *x, const emxArray_real_T *A, real_T C) { real_T f; emxArray_real_T *a; int32_T i2; int32_T i; const mxArray *y; static const int32_T iv2[2] = { 1, 45 }; const mxArray *m0; char_T cv1[45]; static const char_T cv2[45] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o', 'l', 'b', 'o', 'x', ':', 'm', 't', 'i', 'm', 'e', 's', '_', 'n', 'o', 'D', 'y', 'n', 'a', 'm', 'i', 'c', 'S', 'c', 'a', 'l', 'a', 'r', 'E', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n' }; const mxArray *b_y; static const int32_T iv3[2] = { 1, 21 }; char_T cv3[21]; static const char_T cv4[21] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T', 'L', 'A', 'B', ':', 'i', 'n', 'n', 'e', 'r', 'd', 'i', 'm' }; emxArray_real_T *c_y; int32_T loop_ub; int32_T i3; uint32_T unnamed_idx_0; real_T alpha1; real_T beta1; char_T TRANSB; char_T TRANSA; ptrdiff_t m_t; ptrdiff_t n_t; ptrdiff_t k_t; ptrdiff_t lda_t; ptrdiff_t ldb_t; ptrdiff_t ldc_t; double * alpha1_t; double * Aia0_t; double * Bib0_t; double * beta1_t; double * Cic0_t; emxArray_real_T *b_x; boolean_T overflow; boolean_T p; int32_T exitg1; const mxArray *d_y; static const int32_T iv4[2] = { 1, 30 }; char_T cv5[30]; static const char_T cv6[30] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o', 'l', 'b', 'o', 'x', ':', 's', 'u', 'm', '_', 's', 'p', 'e', 'c', 'i', 'a', 'l', 'E', 'm', 'p', 't', 'y' }; const mxArray *e_y; static const int32_T iv5[2] = { 1, 36 }; char_T cv7[36]; static const char_T cv8[36] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o', 'l', 'b', 'o', 'x', ':', 'a', 'u', 't', 'o', 'D', 'i', 'm', 'I', 'n', 'c', 'o', 'm', 'p', 'a', 't', 'i', 'b', 'i', 'l', 'i', 't', 'y' }; emxArray_real_T *b_a; const mxArray *f_y; static const int32_T iv6[2] = { 1, 45 }; const mxArray *g_y; static const int32_T iv7[2] = { 1, 21 }; emlrtHeapReferenceStackEnterFcnR2012b(emlrtRootTLSGlobal); emxInit_real_T(&a, 2, &e_emlrtRTEI, TRUE); emlrtPushRtStackR2012b(&h_emlrtRSI, emlrtRootTLSGlobal); i2 = a->size[0] * a->size[1]; a->size[0] = A->size[0]; a->size[1] = A->size[1]; emxEnsureCapacity((emxArray__common *)a, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = A->size[0] * A->size[1]; for (i2 = 0; i2 < i; i2++) { a->data[i2] = -A->data[i2]; } emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); if (!(a->size[1] == x->size[0])) { if (((a->size[0] == 1) && (a->size[1] == 1)) || (x->size[0] == 1)) { emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); y = NULL; m0 = mxCreateCharArray(2, iv2); for (i = 0; i < 45; i++) { cv1[i] = cv2[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 45, m0, cv1); emlrtAssign(&y, m0); error(message(y, &b_emlrtMCI), &c_emlrtMCI); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); } else { emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); b_y = NULL; m0 = mxCreateCharArray(2, iv3); for (i = 0; i < 21; i++) { cv3[i] = cv4[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 21, m0, cv3); emlrtAssign(&b_y, m0); error(message(b_y, &d_emlrtMCI), &e_emlrtMCI); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); } } emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); b_emxInit_real_T(&c_y, 1, &e_emlrtRTEI, TRUE); if ((a->size[1] == 1) || (x->size[0] == 1)) { i2 = c_y->size[0]; c_y->size[0] = a->size[0]; emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = a->size[0]; for (i2 = 0; i2 < i; i2++) { c_y->data[i2] = 0.0; loop_ub = a->size[1]; for (i3 = 0; i3 < loop_ub; i3++) { c_y->data[i2] += a->data[i2 + a->size[0] * i3] * x->data[i3]; } } } else { unnamed_idx_0 = (uint32_T)a->size[0]; emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); i2 = c_y->size[0]; c_y->size[0] = (int32_T)unnamed_idx_0; emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = (int32_T)unnamed_idx_0; for (i2 = 0; i2 < i; i2++) { c_y->data[i2] = 0.0; } if ((a->size[0] < 1) || (a->size[1] < 1)) { } else { emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); alpha1 = 1.0; beta1 = 0.0; TRANSB = 'N'; TRANSA = 'N'; emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(a->size[0]); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(1); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(a->size[1]); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); lda_t = (ptrdiff_t)(a->size[0]); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); ldb_t = (ptrdiff_t)(a->size[1]); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&y_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&ab_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); ldc_t = (ptrdiff_t)(a->size[0]); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&ab_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&bb_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&alpha1); emlrtPopRtStackR2012b(&bb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&a->data[0]); emlrtPopRtStackR2012b(&cb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal); Bib0_t = (double *)(&x->data[0]); emlrtPopRtStackR2012b(&db_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal); beta1_t = (double *)(&beta1); emlrtPopRtStackR2012b(&eb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal); Cic0_t = (double *)(&c_y->data[0]); emlrtPopRtStackR2012b(&fb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal); dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t); emlrtPopRtStackR2012b(&gb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); } emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); } emxFree_real_T(&a); b_emxInit_real_T(&b_x, 1, &e_emlrtRTEI, TRUE); i2 = b_x->size[0]; b_x->size[0] = c_y->size[0]; emxEnsureCapacity((emxArray__common *)b_x, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = c_y->size[0]; for (i2 = 0; i2 < i; i2++) { b_x->data[i2] = c_y->data[i2]; } for (i = 0; i < c_y->size[0]; i++) { b_x->data[i] = muDoubleScalarExp(b_x->data[i]); } i2 = b_x->size[0]; emxEnsureCapacity((emxArray__common *)b_x, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = b_x->size[0]; for (i2 = 0; i2 < i; i2++) { b_x->data[i2]++; } i2 = c_y->size[0]; c_y->size[0] = b_x->size[0]; emxEnsureCapacity((emxArray__common *)c_y, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = b_x->size[0]; for (i2 = 0; i2 < i; i2++) { c_y->data[i2] = b_x->data[i2]; } for (i = 0; i < b_x->size[0]; i++) { if (b_x->data[i] < 0.0) { emlrtPushRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal); eml_error(); emlrtPopRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal); } } for (i = 0; i < b_x->size[0]; i++) { c_y->data[i] = muDoubleScalarLog(c_y->data[i]); } emxFree_real_T(&b_x); overflow = FALSE; p = FALSE; i = 0; do { exitg1 = 0; if (i < 2) { if (i + 1 <= 1) { i2 = c_y->size[0]; } else { i2 = 1; } if (i2 != 0) { exitg1 = 1; } else { i++; } } else { p = TRUE; exitg1 = 1; } } while (exitg1 == 0); if (!p) { } else { overflow = TRUE; } if (!overflow) { } else { emlrtPushRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal); d_y = NULL; m0 = mxCreateCharArray(2, iv4); for (i = 0; i < 30; i++) { cv5[i] = cv6[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 30, m0, cv5); emlrtAssign(&d_y, m0); error(message(d_y, &h_emlrtMCI), &i_emlrtMCI); emlrtPopRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal); } if ((c_y->size[0] == 1) || (c_y->size[0] != 1)) { overflow = TRUE; } else { overflow = FALSE; } if (overflow) { } else { emlrtPushRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal); e_y = NULL; m0 = mxCreateCharArray(2, iv5); for (i = 0; i < 36; i++) { cv7[i] = cv8[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 36, m0, cv7); emlrtAssign(&e_y, m0); error(message(e_y, &j_emlrtMCI), &k_emlrtMCI); emlrtPopRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal); } if (c_y->size[0] == 0) { alpha1 = 0.0; } else { alpha1 = c_y->data[0]; emlrtPushRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal); if (2 > c_y->size[0]) { overflow = FALSE; } else { overflow = (c_y->size[0] > 2147483646); } if (overflow) { emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); check_forloop_overflow_error(); emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); } emlrtPopRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal); for (i = 2; i <= c_y->size[0]; i++) { alpha1 += c_y->data[i - 1]; } } emxFree_real_T(&c_y); emxInit_real_T(&b_a, 2, &e_emlrtRTEI, TRUE); i2 = b_a->size[0] * b_a->size[1]; b_a->size[0] = 1; emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = x->size[0]; i2 = b_a->size[0] * b_a->size[1]; b_a->size[1] = i; emxEnsureCapacity((emxArray__common *)b_a, i2, (int32_T)sizeof(real_T), &e_emlrtRTEI); i = x->size[0]; for (i2 = 0; i2 < i; i2++) { b_a->data[i2] = x->data[i2]; } emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); if (!(b_a->size[1] == x->size[0])) { if ((b_a->size[1] == 1) || (x->size[0] == 1)) { emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); f_y = NULL; m0 = mxCreateCharArray(2, iv6); for (i = 0; i < 45; i++) { cv1[i] = cv2[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 45, m0, cv1); emlrtAssign(&f_y, m0); error(message(f_y, &b_emlrtMCI), &c_emlrtMCI); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); } else { emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); g_y = NULL; m0 = mxCreateCharArray(2, iv7); for (i = 0; i < 21; i++) { cv3[i] = cv4[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 21, m0, cv3); emlrtAssign(&g_y, m0); error(message(g_y, &d_emlrtMCI), &e_emlrtMCI); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); } } emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); if ((b_a->size[1] == 1) || (x->size[0] == 1)) { beta1 = 0.0; for (i2 = 0; i2 < b_a->size[1]; i2++) { beta1 += b_a->data[b_a->size[0] * i2] * x->data[i2]; } } else { emlrtPushRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal); if (b_a->size[1] < 1) { beta1 = 0.0; } else { emlrtPushRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&sb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(b_a->size[1]); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&sb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(1); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&tb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(1); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&ub_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&b_a->data[0]); emlrtPopRtStackR2012b(&vb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&x->data[0]); emlrtPopRtStackR2012b(&wb_emlrtRSI, emlrtRootTLSGlobal); beta1 = ddot(&n_t, alpha1_t, &m_t, Aia0_t, &k_t); emlrtPopRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal); } emlrtPopRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal); } emxFree_real_T(&b_a); f = -C * alpha1 - 0.5 * beta1; emlrtPopRtStackR2012b(&h_emlrtRSI, emlrtRootTLSGlobal); emlrtHeapReferenceStackLeaveFcnR2012b(emlrtRootTLSGlobal); return f; }
void compute_offsets_from_zernike(float *a, float *x, float *y) { int i,j,k; aperture_pixel **pixels; float **image; float dx, dy, flux; float test_a[NUM_ACTUATORS+1]; float cen_x, cen_y; #ifdef TEST_ZERNIKE_1 Window phaseWindow; Window imageWindow; phaseWindow = openWindow("Phase", 10, 10, 128, 128); imageWindow = openWindow("Image", 148, 10, 128, 128); #endif /* First we need to know where the "center" is */ test_a[0] = 1.0; for(i=1; i<=maxJ; i++) test_a[i] = 0.0; pixels = sub_aperture(15, maxJ, 0.0, 0.0, rho_size); #ifdef TEST_ZERNIKE_1 display_phase(phaseWindow, pixels, 2.0*M_PI, test_a, maxJ, 15, 8, LIN); display_image(imageWindow, pixels, 2.0*M_PI, test_a, maxJ, 15, 8, 5, LIN); #endif image = calculate_image(pixels, 15, 5, maxJ, 2.0*M_PI, test_a); cen_x = 0.0; cen_y = 0.0; flux = 0.0; for(j = 1; j<=15; j++) { for(k = 1; k<=15; k++) { flux += image[j][k]; cen_x += (image[j][k] * (float)j); cen_y += (image[j][k] * (float)k); } } cen_x /= flux; cen_y /= flux; #ifdef TEST_ZERNIKE_1 message(system_window,"Center %.2f %.2f", cen_x, cen_y); usleep(TEST_ZERNIKE_1_DELAY); #endif for(i=0; i<NUM_LENSLETS; i++) { /* Build a subaperture */ pixels = sub_aperture(16, maxJ, rho[i], theta[i], rho_size); #ifdef TEST_ZERNIKE_1 display_phase(phaseWindow, pixels, 2.0*M_PI, a, maxJ, 15, 8, LIN); display_image(imageWindow, pixels, 2.0*M_PI, a, maxJ, 15, 8, 5, LIN); #endif /* * Work out the image * This is predicated on the assumption that * the image size is about 1 pixel. The calculate_image * function makes the airy size 2^imbedp2/npix, so * we hope that this works... */ image = calculate_image(pixels, 15, 5, maxJ, 2.0*M_PI, a); /* Simmulate the WFS calculation */ dx = 0.0; dy = 0.0; flux = 0.0; for(j = 1; j<=15; j++) { for(k = 1; k<=15; k++) { flux += image[j][k]; dx += (image[j][k] * ((float)j - cen_x)); dy += (image[j][k] * ((float)k - cen_y)); } } dx /= flux; dy /= flux; /* That should be all */ x[i] = dx; y[i] = dy; /* Clear memory */ free_sub_aperture(pixels,CENTROID_WINDOW_WIDTH); free_matrix(image, 1, 9, 1, 9); #ifdef TEST_ZERNIKE_1 message(system_window,"Lenslet %d Pos %.2f %.2f Flux %.2f",i, dx, dy, flux); usleep(TEST_ZERNIKE_1_DELAY); #endif } #ifdef TEST_ZERNIKE_1 XDestroyWindow(theDisplay, phaseWindow); #endif } /* compute_centroid_offset_rho_theta() */
FReturnCode NativeCommand::SearchCommand(intrusive_ptr< ConnectionInstance >& con, string& payload) { //DLOG(INFO) << "Starting search with payload " << payload; static string FKSstring("FKS"); static double timeout = 5.0; double time = Server::getEventTime(); if (con->timers[FKSstring] > (time - timeout)) return FERR_THROTTLE_SEARCH; else con->timers[FKSstring] = time; typedef unordered_set<ConnectionPtr> clist_t; clist_t tosearch; const conptrmap_t cons = ServerState::getConnections(); for (conptrmap_t::const_iterator i = cons.begin(); i != cons.end(); ++i) { if ((i->second != con) && (i->second->kinkList.size() != 0) && (i->second->status == "online" || i->second->status == "looking")) tosearch.insert(i->second); } json_t* rootnode = json_loads(payload.c_str(), 0, 0); if (!rootnode) return FERR_BAD_SYNTAX; json_t* kinksnode = json_object_get(rootnode, "kinks"); if (!json_is_array(kinksnode)) return FERR_BAD_SYNTAX; if (json_array_size(kinksnode) > 5) return FERR_TOO_MANY_SEARCH_TERMS; json_t* gendersnode = json_object_get(rootnode, "genders"); if (json_is_array(gendersnode)) SearchFilterList(gendersnode, tosearch, "Gender"); json_t* orientationsnode = json_object_get(rootnode, "orientations"); if (json_is_array(orientationsnode)) SearchFilterList(orientationsnode, tosearch, "Orientation"); json_t* languagesnode = json_object_get(rootnode, "languages"); if (json_is_array(languagesnode)) SearchFilterList(languagesnode, tosearch, "Language preference"); json_t* furryprefsnode = json_object_get(rootnode, "furryprefs"); if (json_is_array(furryprefsnode)) SearchFilterList(furryprefsnode, tosearch, "Furry preference"); json_t* rolesnode = json_object_get(rootnode, "roles"); if (json_is_array(rolesnode)) SearchFilterList(rolesnode, tosearch, "Dom/Sub Role"); json_t* positionsnode = json_object_get(rootnode, "positions"); if (json_is_array(positionsnode)) SearchFilterList(positionsnode, tosearch, "Position"); if (json_array_size(kinksnode) > 0) SearchFilterListF(kinksnode, tosearch); int num_found = tosearch.size(); if (num_found == 0) return FERR_NO_SEARCH_RESULTS; else if (num_found > 350) return FERR_TOO_MANY_SEARCH_RESULTS; json_t* newroot = json_object(); json_t* chararray = json_array(); for (clist_t::const_iterator i = tosearch.begin(); i != tosearch.end(); ++i) { json_array_append_new(chararray, json_string_nocheck((*i)->characterName.c_str()) ); } json_object_set_new_nocheck(newroot, "characters", chararray); json_object_set_new_nocheck(newroot, "kinks", kinksnode); string message("FKS "); const char* fksstr = json_dumps(newroot, JSON_COMPACT); message += fksstr; free((void*) fksstr); json_decref(newroot); MessagePtr outMessage(MessageBuffer::fromString(message)); con->send(outMessage); json_decref(rootnode); //DLOG(INFO) << "Finished search."; return FERR_OK; }
int wdog_main(int argc, char *argv[]) { struct wdog_example_s wdog; #ifdef CONFIG_DEBUG_WATCHDOG struct watchdog_status_s status; #endif long elapsed; int fd; int ret; /* Parse the command line */ parse_args(&wdog, argc, argv); /* Initialization of the WATCHDOG hardware is performed by logic external to * this test. */ ret = up_wdginitialize(); if (ret != OK) { message("wdog_main: up_wdginitialize failed: %d\n", ret); goto errout; } /* Open the watchdog device for reading */ fd = open(CONFIG_EXAMPLES_WATCHDOG_DEVPATH, O_RDONLY); if (fd < 0) { message("wdog_main: open %s failed: %d\n", CONFIG_EXAMPLES_WATCHDOG_DEVPATH, errno); goto errout; } /* Set the watchdog timeout */ ret = ioctl(fd, WDIOC_SETTIMEOUT, (unsigned long)wdog.timeout); if (ret < 0) { message("wdog_main: ioctl(WDIOC_SETTIMEOUT) failed: %d\n", errno); goto errout_with_dev; } /* Then start the watchdog timer. */ ret = ioctl(fd, WDIOC_START, 0); if (ret < 0) { message("wdog_main: ioctl(WDIOC_START) failed: %d\n", errno); goto errout_with_dev; } /* Then ping */ for (elapsed = 0; elapsed < wdog.pingtime; elapsed += wdog.pingdelay) { /* Sleep for the requested amount of time */ usleep(wdog.pingdelay * 1000); /* Show watchdog status. Only if debug is enabled because this * could interfere with the timer. */ #ifdef CONFIG_DEBUG_WATCHDOG ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status); if (ret < 0) { message("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno); goto errout_with_dev; } message("wdog_main: flags=%08x timeout=%d timeleft=%d\n", status.flags, status.timeout, status.timeleft); #endif /* Then ping */ ret = ioctl(fd, WDIOC_KEEPALIVE, 0); if (ret < 0) { message("wdog_main: ioctl(WDIOC_KEEPALIVE) failed: %d\n", errno); goto errout_with_dev; } message(" ping elapsed=%ld\n", elapsed); msgflush(); } /* Then stop pinging */ for (; ; elapsed += wdog.pingdelay) { /* Sleep for the requested amount of time */ usleep(wdog.pingdelay * 1000); /* Show watchdog status. Only if debug is enabled because this * could interfere with the timer. */ #ifdef CONFIG_DEBUG_WATCHDOG ret = ioctl(fd, WDIOC_GETSTATUS, (unsigned long)&status); if (ret < 0) { message("wdog_main: ioctl(WDIOC_GETSTATUS) failed: %d\n", errno); goto errout_with_dev; } message("wdog_main: flags=%08x timeout=%d timeleft=%d\n", status.flags, status.timeout, status.timeleft); #endif message(" NO ping elapsed=%ld\n", elapsed); msgflush(); } /* We should not get here */ ret = ioctl(fd, WDIOC_STOP, 0); if (ret < 0) { message("wdog_main: ioctl(WDIOC_STOP) failed: %d\n", errno); goto errout_with_dev; } close(fd); msgflush(); return OK; errout_with_dev: close(fd); errout: msgflush(); return ERROR; }
void tinyG::onSerialBuffer(const ofx::IO::SerialBufferEventArgs& args) { SerialMessage message(args.getBuffer().toString(), "", 10000); statusReport = message; }
const JSClassDefinition NX::Classes::IO::ReadableStream::Class { 0, kJSClassAttributeNone, "ReadableStream", nullptr, NX::Classes::IO::ReadableStream::Properties, NX::Classes::IO::ReadableStream::Methods, nullptr, NX::Classes::IO::ReadableStream::Finalize }; const JSStaticValue NX::Classes::IO::ReadableStream::Properties[] { { nullptr, nullptr, nullptr, 0 } }; const JSStaticFunction NX::Classes::IO::ReadableStream::Methods[] { { "read", [](JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -> JSValueRef { NX::Context * context = Context::FromJsContext(ctx); NX::Classes::IO::ReadableStream * stream = NX::Classes::IO::ReadableStream::FromObject(thisObject); if (!stream) { NX::Value message(ctx, "read not implemented on ReadableStream instance"); JSValueRef args[] { message.value(), nullptr }; *exception = JSObjectMakeError(ctx, 1, args, nullptr); return JSValueMakeUndefined(ctx); } std::size_t length = (std::size_t)-1; if (argumentCount >= 1) { length = JSValueToNumber(ctx, arguments[0], exception); if (exception && *exception) { return JSValueMakeUndefined(ctx); } } try { return stream->read(ctx, thisObject, length); } catch(const std::exception & e) {
/*! \deprecated Direct the \i Email service to display the message identified by \a id. This slot corresponds to the QCop service message \c{Email::viewMail(QMailMessageId)}. */ void EmailService::viewMail( const QMailMessageId& id ) { qLog(Messaging) << "EmailService::viewMail(" << id << ")"; emit message(id); }
int regex_command_for (void *target, const vfs_path_t * filename_vpath, const char *action, vfs_path_t ** script_vpath) { char *p, *q, *r, c; size_t file_len; gboolean found = FALSE; gboolean error_flag = FALSE; int ret = 0; struct stat mystat; int view_at_line_number; char *include_target; int include_target_len; gboolean have_type = FALSE; /* Flag used by regex_check_type() */ if (filename_vpath == NULL) return 0; if (script_vpath != NULL) *script_vpath = NULL; /* Check for the special View:%d parameter */ if (strncmp (action, "View:", 5) == 0) { view_at_line_number = atoi (action + 5); action = "View"; } else { view_at_line_number = 0; } if (data == NULL) { char *extension_file; gboolean mc_user_ext = TRUE; gboolean home_error = FALSE; extension_file = mc_config_get_full_path (MC_FILEBIND_FILE); if (!exist_file (extension_file)) { g_free (extension_file); check_stock_mc_ext: extension_file = mc_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL); if (!exist_file (extension_file)) { g_free (extension_file); extension_file = mc_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL); } mc_user_ext = FALSE; } g_file_get_contents (extension_file, &data, NULL, NULL); g_free (extension_file); if (data == NULL) return 0; if (strstr (data, "default/") == NULL) { if (strstr (data, "regex/") == NULL && strstr (data, "shell/") == NULL && strstr (data, "type/") == NULL) { g_free (data); data = NULL; if (!mc_user_ext) { char *title; title = g_strdup_printf (_(" %s%s file error"), mc_global.sysconfig_dir, MC_LIB_EXT); message (D_ERROR, title, _("The format of the %smc.ext " "file has changed with version 3.0. It seems that " "the installation failed. Please fetch a fresh " "copy from the Midnight Commander package."), mc_global.sysconfig_dir); g_free (title); return 0; } home_error = TRUE; goto check_stock_mc_ext; } } if (home_error) { char *filebind_filename; char *title; filebind_filename = mc_config_get_full_path (MC_FILEBIND_FILE); title = g_strdup_printf (_("%s file error"), filebind_filename); message (D_ERROR, title, _("The format of the %s file has " "changed with version 3.0. You may either want to copy " "it from %smc.ext or use that file as an example of how to write it."), filebind_filename, mc_global.sysconfig_dir); g_free (filebind_filename); g_free (title); } } mc_stat (filename_vpath, &mystat); include_target = NULL; include_target_len = 0; file_len = vfs_path_len (filename_vpath); for (p = data; *p != '\0'; p++) { for (q = p; *q == ' ' || *q == '\t'; q++) ; if (*q == '\n' || *q == '\0') p = q; /* empty line */ if (*p == '#') /* comment */ while (*p != '\0' && *p != '\n') p++; if (*p == '\n') continue; if (*p == '\0') break; if (p == q) { /* i.e. starts in the first column, should be * keyword/descNL */ gboolean case_insense; found = FALSE; q = strchr (p, '\n'); if (q == NULL) q = strchr (p, '\0'); c = *q; *q = '\0'; if (include_target) { if ((strncmp (p, "include/", 8) == 0) && (strncmp (p + 8, include_target, include_target_len) == 0)) found = TRUE; } else if (strncmp (p, "regex/", 6) == 0) { mc_search_t *search; p += 6; case_insense = (strncmp (p, "i/", 2) == 0); if (case_insense) p += 2; search = mc_search_new (p, -1, DEFAULT_CHARSET); if (search != NULL) { search->search_type = MC_SEARCH_T_REGEX; search->is_case_sensitive = !case_insense; found = mc_search_run (search, vfs_path_as_str (filename_vpath), 0, file_len, NULL); mc_search_free (search); } } else if (strncmp (p, "directory/", 10) == 0) { if (S_ISDIR (mystat.st_mode) && mc_search (p + 10, DEFAULT_CHARSET, vfs_path_as_str (filename_vpath), MC_SEARCH_T_REGEX)) found = TRUE; } else if (strncmp (p, "shell/", 6) == 0) { int (*cmp_func) (const char *s1, const char *s2, size_t n) = strncmp; p += 6; case_insense = (strncmp (p, "i/", 2) == 0); if (case_insense) { p += 2; cmp_func = strncasecmp; } if (*p == '.' && file_len >= (size_t) (q - p)) { if (cmp_func (p, vfs_path_as_str (filename_vpath) + file_len - (q - p), q - p) == 0) found = TRUE; } else { if ((size_t) (q - p) == file_len && cmp_func (p, vfs_path_as_str (filename_vpath), q - p) == 0) found = TRUE; } } else if (strncmp (p, "type/", 5) == 0) { GError *error = NULL; p += 5; case_insense = (strncmp (p, "i/", 2) == 0); if (case_insense) p += 2; found = regex_check_type (filename_vpath, p, case_insense, &have_type, &error); if (error != NULL) { g_error_free (error); error_flag = TRUE; /* leave it if file cannot be opened */ } } else if (strncmp (p, "default/", 8) == 0) found = TRUE; *q = c; p = q; if (*p == '\0') break; } else { /* List of actions */ p = q; q = strchr (p, '\n'); if (q == NULL) q = strchr (p, '\0'); if (found && !error_flag) { r = strchr (p, '='); if (r != NULL) { c = *r; *r = '\0'; if (strcmp (p, "Include") == 0) { char *t; include_target = p + 8; t = strchr (include_target, '\n'); if (t != NULL) *t = '\0'; include_target_len = strlen (include_target); if (t != NULL) *t = '\n'; *r = c; p = q; found = FALSE; if (*p == '\0') break; continue; } if (strcmp (action, p) != 0) *r = c; else { *r = c; for (p = r + 1; *p == ' ' || *p == '\t'; p++) ; /* Empty commands just stop searching * through, they don't do anything */ if (p < q) { vfs_path_t *sv; sv = exec_extension (target, filename_vpath, r + 1, view_at_line_number); if (script_vpath != NULL) *script_vpath = sv; else exec_cleanup_script (sv); ret = 1; } break; } } } p = q; if (*p == '\0') break; } } if (error_flag) ret = -1; return ret; }
extern int reboot_main(int argc, char **argv) { int delay = 0; /* delay in seconds before rebooting */ int rc; while ((rc = getopt(argc, argv, "d:")) > 0) { switch (rc) { case 'd': delay = atoi(optarg); break; default: show_usage(); break; } } if(delay > 0) sleep(delay); #ifdef CONFIG_USER_INIT /* Don't kill ourself */ signal(SIGTERM,SIG_IGN); signal(SIGHUP,SIG_IGN); setpgrp(); /* Allow Ctrl-Alt-Del to reboot system. */ init_reboot(RB_ENABLE_CAD); message(CONSOLE|LOG, "\n\rThe system is going down NOW !!\n"); sync(); /* Send signals to every process _except_ pid 1 */ message(CONSOLE|LOG, "\rSending SIGTERM to all processes.\n"); kill(-1, SIGTERM); sleep(1); sync(); message(CONSOLE|LOG, "\rSending SIGKILL to all processes.\n"); kill(-1, SIGKILL); sleep(1); sync(); if (kernelVersion > 0 && kernelVersion <= KERNEL_VERSION(2,2,11)) { /* bdflush, kupdate not needed for kernels >2.2.11 */ bdflush(1, 0); sync(); } init_reboot(RB_AUTOBOOT); exit(0); /* Shrug */ #else #ifdef BB_FEATURE_LINUXRC { /* don't assume init's pid == 1 */ long *pid = find_pid_by_name("init"); if (!pid || *pid<=0) pid = find_pid_by_name("linuxrc"); if (!pid || *pid<=0) error_msg_and_die("no process killed"); fflush(stdout); return(kill(*pid, SIGTERM)); } #else return(kill(1, SIGTERM)); #endif #endif }
int main(int argc, char *argv[]) { struct sockaddr_un addr; char buf[100]; int fd,cl,rc; uint8_t payload[3] = {65,66,0}; message_t m = message(1, sizeof(payload), payload); printf("type: %d, lenght: %d, data: [%c, %c, %c]\n", m.type, m.length, m.data[0], m.data[1], m.data[2]); if (argc > 1) socket_path=argv[1]; char realp[4096]; //char *realp = malloc(sizeof(char) * (strlen(dir) + strlen(b))); realpath(socket_path, realp); printf("socket@ %s/%s\n", realp, basename(socket_path)); fflush(stdout); if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { perror("socket error"); exit(-1); } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path)-1); unlink(socket_path); if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { perror("bind error"); exit(-1); } if (listen(fd, 5) == -1) { perror("listen error"); exit(-1); } while (1) { if ( (cl = accept(fd, NULL, NULL)) == -1) { perror("accept error"); continue; } while ( (rc=read(cl,buf,sizeof(buf))) > 0) { printf("read %u bytes: %.*s\n", rc, rc, buf); } if (rc == -1) { perror("read"); exit(-1); } else if (rc == 0) { printf("EOF\n"); close(cl); } } return 0; }
bool Preferences::_loadOk() { TestMode::Mode testMode; quint8 pingsPerHost; quint8 pingThreads; quint8 pingTimeoutSecs; quint8 downloadTestSecs; QString hostlistUrl; sync(); if(!childGroups().contains("Preferences")) { return false; } beginGroup("Preferences"); testMode = (TestMode::Mode) value("TestMode", 0).toUInt(); if(!(testMode == TestMode::Info || testMode == TestMode::Ping || testMode == TestMode::Download || testMode == TestMode::All)) { return false; } pingsPerHost = value("PingsPerHost", 0).toUInt(); if(pingsPerHost < 1 || pingsPerHost > 10) { return false; } pingThreads = value("PingThreads", 0).toUInt(); if(pingThreads < 1 || pingThreads > 8) { return false; } pingTimeoutSecs = value("PingTimeoutSecs", 0).toUInt(); if(pingTimeoutSecs < 1 || pingTimeoutSecs > 4) { return false; } downloadTestSecs = value("DownloadTestSecs", 0).toUInt(); if(downloadTestSecs < 5 || downloadTestSecs > 30) { return false; } hostlistUrl = value("HostlistUrl", QString("")).toString(); if(hostlistUrl.isEmpty() || !QUrl(hostlistUrl).isValid()) { return false; } // At this point, preferences INI file was valid. Load its preferences TESTMODE = testMode; PINGSPERHOST = pingsPerHost; PINGTHREADS = pingThreads; PINGTIMEOUTSECS = pingTimeoutSecs; DOWNLOADTESTSECS = downloadTestSecs; HOSTLISTURL = hostlistUrl; emit message(trUtf8("Loaded preferences from") + ' ' + QDir::toNativeSeparators(fileName())); return true; }
// ----------------------------------------------------------------------- // handler for the Animate Dead spells // ----------------------------------------------------------------------- void t_animate_dead::cast_and_mirror( t_combat_creature_ptr target, int power ) { t_battlefield& battlefield = m_battlefield; t_combat_action_message message( *m_caster, get_action_text( false ) ); battlefield.start_animation( *target, m_spell, message ); int number = get_bodies_affected( target ); t_direction direction; int health = get_health_power( *target ); // find a suitably large open spot t_combat_creature& caster = *get_caster(); double scale = battlefield.get_model_scale(); bool defender = caster.get_controller(); t_combat_creature_ptr creature; creature = battlefield.find_summoned_creature( m_spell, get_creature_type( *target ), caster.get_controller() ); if (creature != 0) { creature->add_creatures( health ); if (target->get_number() == 0 && target->get_salvageable_bodies() <= number) target->fade_out( message ); } else { creature = create_creature( target, scale, defender ); creature->set_number( 0 ); if (!place_summoned_creature( caster, creature )) return; // check if there are no bodies left if (target->get_number() == 0 && target->get_salvageable_bodies() <= number) { // if the creature is not in the same cell... if (target->get_cell_position() != creature->get_cell_position() || target->get_creature_type() != creature->get_creature_type()) target->fade_out( message ); else { // if there are no bodies left, hide the target and replace it with the new creature target->set_alpha( m_battlefield, 0 ); // make the creature face the same direction as the target direction = target->get_current_direction(); creature->set_current_direction( direction ); creature->set_alpha( m_battlefield, 15 ); } target->set_normal_alpha( 0 ); } // play death animation in reverse creature->set_current_action( k_combat_actor_action_die ); creature->set_spell( m_spell, message ); battlefield.place_object( creature, t_map_point_2d( creature->get_position() )); creature->show_resurrection( message ); } // remove bodies from target target->remove_bodies( number ); creature->resurrect( health ); play_sound(); // if creature is invisible, fade it in. if (creature->get_alpha() < 15) creature->fade_in( message ); battlefield.set_spell( 0 ); }
int nx_servertask(int argc, char *argv[]) { FAR NX_DRIVERTYPE *dev; int ret; #if defined(CONFIG_EXAMPLES_NX_EXTERNINIT) /* Use external graphics driver initialization */ message("nxeg_initialize: Initializing external graphics device\n"); dev = up_nxdrvinit(CONFIG_EXAMPLES_NX_DEVNO); if (!dev) { message("nxeg_initialize: up_nxdrvinit failed, devno=%d\n", CONFIG_EXAMPLES_NX_DEVNO); g_exitcode = NXEXIT_EXTINITIALIZE; return ERROR; } #elif defined(CONFIG_NX_LCDDRIVER) /* Initialize the LCD device */ message("nx_servertask: Initializing LCD\n"); ret = up_lcdinitialize(); if (ret < 0) { message("nx_servertask: up_lcdinitialize failed: %d\n", -ret); return 1; } /* Get the device instance */ dev = up_lcdgetdev(CONFIG_EXAMPLES_NX_DEVNO); if (!dev) { message("nx_servertask: up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_NX_DEVNO); return 2; } /* Turn the LCD on at 75% power */ (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4)); #else /* Initialize the frame buffer device */ message("nx_servertask: Initializing framebuffer\n"); ret = up_fbinitialize(); if (ret < 0) { message("nx_servertask: up_fbinitialize failed: %d\n", -ret); return 1; } dev = up_fbgetvplane(CONFIG_EXAMPLES_NX_VPLANE); if (!dev) { message("nx_servertask: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NX_VPLANE); return 2; } #endif /* Then start the server */ ret = nx_run(dev); message("nx_servertask: nx_run returned: %d\n", errno); return 3; }