void PluginWidgetAndroid::exitFullScreen(bool pluginInitiated) { if (!m_isFullScreen || !m_embeddedView) { return; } // remove the full screen surface from the view hierarchy if (pluginInitiated) { m_core->hideFullScreenPlugin(); } // add the embedded view back if (m_drawingModel != kOpenGL_ANPDrawingModel) m_core->updateSurface(m_embeddedView, m_pluginWindow->x, m_pluginWindow->y, m_pluginWindow->width, m_pluginWindow->height); // send event to notify plugin of full screen change ANPEvent event; SkANP::InitEvent(&event, kLifecycle_ANPEventType); event.data.lifecycle.action = kExitFullScreen_ANPLifecycleAction; sendEvent(event); m_isFullScreen = false; }
bool COSXScreen::onDisplayChange() { // screen resolution may have changed. save old shape. SInt32 xOld = m_x, yOld = m_y, wOld = m_w, hOld = m_h; // update shape updateScreenShape(); // do nothing if resolution hasn't changed if (xOld != m_x || yOld != m_y || wOld != m_w || hOld != m_h) { if (m_isPrimary) { // warp mouse to center if off screen if (!m_isOnScreen) { warpCursor(m_xCenter, m_yCenter); } } // send new screen info sendEvent(m_events->forIPrimaryScreen().shapeChanged()); } return true; }
void GUIListGadget::updateItem(GUIListItem* Item, dim::point2di &Pos) { if (!Item || !Item->getVisible()) return; dim::rect2di Rect( Rect_.Left, Pos.Y, Rect_.Right, Pos.Y + Item->getItemSize() ); if (VertScroll_.getVisible()) Rect.Right -= SCROLLBAR_SIZE; if (HorzScroll_.getVisible() && Rect.Bottom > Rect_.Bottom - SCROLLBAR_SIZE) Rect.Bottom = Rect_.Bottom - SCROLLBAR_SIZE; Pos.Y += Item->getItemSize(); /* Update current item */ if (mouseOver(Rect)) { Item->isPicked_ = true; if (mouseLeft()) { SelectedItem_ = Item; SGUIEvent Event; { Event.Object = EVENT_GADGET; Event.Type = EVENT_ACTIVATE; Event.Gadget = this; Event.SubData = Item; } sendEvent(Event); } } }
//---------------------------------------------------------------- void GraphView::addNodesInternal(unsigned int nbAdded, const std::vector<node> *nodes) { _nodes.reserve(_nodes.size() + nbAdded); std::vector<node>::const_iterator it; if (nodes) it = nodes->begin(); else { nodes = &getSuperGraph()->nodes(); it = nodes->begin() + nodes->size() - nbAdded; } std::vector<node>::const_iterator ite = nodes->end(); for (; it != ite; ++it) { node n(*it); assert(getRootImpl()->isElement(n)); _nodeData.set(n.id, new SGraphNodeData()); _nodes.add(n); } if (hasOnlookers()) sendEvent(GraphEvent(*this, GraphEvent::TLP_ADD_NODES, nbAdded)); }
//************************************************************************* // // mTouch -- simulates the multi touch protocol A sequence (see the Linux // input protocol definition). Expects x,y coordinates // followed by the finger id and the pressure. Finger ID is // currently ignored. If pressure is > 0 then we assume this is // a touch down event otherwise it is a touch up event which is // signled by a empty MT and SYNC report. // //************************************************************************* void mTouch ( int conn, int dev) { int x,y,s,f; x = getInt (conn); y = getInt (conn); f = getInt (conn); s = getInt (conn); sendEvent (dev, EV_ABS, ABS_MT_POSITION_X, x); sendEvent (dev, EV_ABS, ABS_MT_POSITION_Y, y); sendEvent (dev, EV_KEY, BTN_TOUCH, (s>0)); sendEvent (dev, EV_SYN, SYN_MT_REPORT, 0); if (s == 0) { sendEvent (dev, EV_SYN, SYN_MT_REPORT, 0); sendEvent (dev, EV_SYN, SYN_REPORT, 0); } if (verbose) printf(" %d %d %d %d\n",x,y,f,s); }
/** * Load an object from the file system (SD card). * A file with the name of the object will be opened. * The object data can be saved using the UAVObjSave function. * @param[in] obj The object handle. * @param[in] instId The object instance * @return 0 if success or -1 if failure */ int32_t UAVObjLoad(UAVObjHandle obj, uint16_t instId) { #if defined(PIOS_INCLUDE_FLASH_SECTOR_SETTINGS) ObjectList *objEntry = (ObjectList *) obj; if (objEntry == NULL) return -1; ObjectInstList *instEntry = getInstance(objEntry, instId); if (instEntry == NULL) return -1; if (instEntry->data == NULL) return -1; // Fire event on success if (PIOS_FLASHFS_ObjLoad(obj, instId, instEntry->data) == 0) sendEvent(objEntry, instId, EV_UNPACKED); else return -1; #endif #if defined(PIOS_INCLUDE_SDCARD) FILEINFO file; ObjectList *objEntry; UAVObjHandle loadedObj; ObjectList *loadedObjEntry; uint8_t filename[14]; // Check for file system availability if (PIOS_SDCARD_IsMounted() == 0) { return -1; } // Lock xSemaphoreTakeRecursive(mutex, portMAX_DELAY); // Cast to object objEntry = (ObjectList *) obj; // Get filename objectFilename(objEntry, filename); // Open file if (PIOS_FOPEN_READ(filename, file)) { xSemaphoreGiveRecursive(mutex); return -1; } // Load object loadedObj = UAVObjLoadFromFile(&file); if (loadedObj == 0) { PIOS_FCLOSE(file); xSemaphoreGiveRecursive(mutex); return -1; } // Check that the IDs match loadedObjEntry = (ObjectList *) loadedObj; if (loadedObjEntry->id != objEntry->id) { PIOS_FCLOSE(file); xSemaphoreGiveRecursive(mutex); return -1; } // Done, close file and unlock PIOS_FCLOSE(file); xSemaphoreGiveRecursive(mutex); #endif /* PIOS_INCLUDE_SDCARD */ return 0; }
void NotificationPresenterClientQt::sendDisplayEvent(NotificationWrapper* wrapper) { Notification* notification = notificationForWrapper(wrapper); if (notification) sendEvent(notification, "show"); }
void MtpServer::sendObjectRemoved(MtpObjectHandle handle) { LOGV("sendObjectRemoved %d\n", handle); sendEvent(MTP_EVENT_OBJECT_REMOVED, handle); }
/** * Load an object from the file system (SD card). * @param[in] file File to read from * @return The handle of the object loaded or NULL if a failure */ UAVObjHandle UAVObjLoadFromFile(FILEINFO * file) { #if defined(PIOS_INCLUDE_SDCARD) uint32_t bytesRead; ObjectList *objEntry; ObjectInstList *instEntry; uint32_t objId; uint16_t instId; UAVObjHandle obj; // Check for file system availability if (PIOS_SDCARD_IsMounted() == 0) { return NULL; } // Lock xSemaphoreTakeRecursive(mutex, portMAX_DELAY); // Read the object ID if (PIOS_FREAD(file, &objId, sizeof(objId), &bytesRead)) { xSemaphoreGiveRecursive(mutex); return NULL; } // Get the object obj = UAVObjGetByID(objId); if (obj == 0) { xSemaphoreGiveRecursive(mutex); return NULL; } objEntry = (ObjectList *) obj; // Get the instance ID instId = 0; if (!objEntry->isSingleInstance) { if (PIOS_FREAD (file, &instId, sizeof(instId), &bytesRead)) { xSemaphoreGiveRecursive(mutex); return NULL; } } // Get the instance information instEntry = getInstance(objEntry, instId); // If the instance does not exist create it and any other instances before it if (instEntry == NULL) { instEntry = createInstance(objEntry, instId); if (instEntry == NULL) { // Error, unlock and return xSemaphoreGiveRecursive(mutex); return NULL; } } // Read the instance data if (PIOS_FREAD (file, instEntry->data, objEntry->numBytes, &bytesRead)) { xSemaphoreGiveRecursive(mutex); return NULL; } // Fire event sendEvent(objEntry, instId, EV_UNPACKED); // Unlock xSemaphoreGiveRecursive(mutex); return obj; #else /* PIOS_INCLUDE_SDCARD */ return NULL; #endif }
void eFilePushThread::thread() { ignore_but_report_signals(); hasStarted(); /* "start()" blocks until we get here */ setIoPrio(prio_class, prio); eDebug("FILEPUSH THREAD START"); do { int eofcount = 0; int buf_end = 0; size_t bytes_read = 0; off_t current_span_offset = 0; size_t current_span_remaining = 0; #if defined(__sh__) // opens video device for the reverse playback workaround // Changes in this file are cause e2 doesnt tell the player to play reverse int fd_video = open("/dev/dvb/adapter0/video0", O_RDONLY); // Fix to ensure that event evtEOF is called at end of playbackl part 1/3 bool already_empty = false; #endif while (!m_stop) { if (m_sg && !current_span_remaining) { #if defined (__sh__) // tells the player to play in reverse #define VIDEO_DISCONTINUITY _IO('o', 84) #define DVB_DISCONTINUITY_SKIP 0x01 #define DVB_DISCONTINUITY_CONTINUOUS_REVERSE 0x02 if ((m_sg->getSkipMode() != 0)) { // inform the player about the jump in the stream data // this only works if the video device allows the discontinuity ioctl in read-only mode (patched) int param = DVB_DISCONTINUITY_SKIP; // | DVB_DISCONTINUITY_CONTINUOUS_REVERSE; int rc = ioctl(fd_video, VIDEO_DISCONTINUITY, (void*)param); } #endif m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining); ASSERT(!(current_span_remaining % m_blocksize)); m_current_position = current_span_offset; bytes_read = 0; } size_t maxread = m_buffersize; /* if we have a source span, don't read past the end */ if (m_sg && maxread > current_span_remaining) maxread = current_span_remaining; /* align to blocksize */ maxread -= maxread % m_blocksize; if (maxread) { #ifdef SHOW_WRITE_TIME struct timeval starttime; struct timeval now; gettimeofday(&starttime, NULL); #endif buf_end = m_source->read(m_current_position, m_buffer, maxread); #ifdef SHOW_WRITE_TIME gettimeofday(&now, NULL); suseconds_t diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec; eDebug("[eFilePushThread] read %d bytes time: %9u us", buf_end, (unsigned int)diff); #endif } else buf_end = 0; if (buf_end < 0) { buf_end = 0; /* Check m_stop after interrupted syscall. */ if (m_stop) { break; } if (errno == EINTR || errno == EBUSY || errno == EAGAIN) continue; if (errno == EOVERFLOW) { eWarning("OVERFLOW while playback?"); continue; } eDebug("eFilePushThread *read error* (%m) - not yet handled"); } /* a read might be mis-aligned in case of a short read. */ int d = buf_end % m_blocksize; if (d) buf_end -= d; if (buf_end == 0) { /* on EOF, try COMMITting once. */ if (m_send_pvr_commit) { struct pollfd pfd; pfd.fd = m_fd_dest; pfd.events = POLLIN; switch (poll(&pfd, 1, 250)) // wait for 250ms { case 0: eDebug("wait for driver eof timeout"); #if defined(__sh__) // Fix to ensure that event evtEOF is called at end of playbackl part 2/3 if (already_empty) { break; } else { already_empty = true; continue; } #else continue; #endif case 1: eDebug("wait for driver eof ok"); break; default: eDebug("wait for driver eof aborted by signal"); /* Check m_stop after interrupted syscall. */ if (m_stop) break; continue; } } if (m_stop) break; /* in stream_mode, we are sending EOF events over and over until somebody responds. in stream_mode, think of evtEOF as "buffer underrun occurred". */ sendEvent(evtEOF); if (m_stream_mode) { eDebug("reached EOF, but we are in stream mode. delaying 1 second."); sleep(1); continue; } else if (++eofcount < 10) { eDebug("reached EOF, but the file may grow. delaying 1 second."); sleep(1); continue; } break; } else { /* Write data to mux */ int buf_start = 0; filterRecordData(m_buffer, buf_end); while ((buf_start != buf_end) && !m_stop) { int w = write(m_fd_dest, m_buffer + buf_start, buf_end - buf_start); if (w <= 0) { /* Check m_stop after interrupted syscall. */ if (m_stop) { w = 0; buf_start = 0; buf_end = 0; break; } if (w < 0 && (errno == EINTR || errno == EAGAIN || errno == EBUSY)) { #if HAVE_CPULOADFIX sleep(2); #endif continue; } eDebug("eFilePushThread WRITE ERROR"); sendEvent(evtWriteError); break; } buf_start += w; } eofcount = 0; #if defined(__sh__) // Fix to ensure that event evtEOF is called at end of playbackl part 3/3 already_empty = false; #endif m_current_position += buf_end; bytes_read += buf_end; if (m_sg) current_span_remaining -= buf_end; } } #if defined(__sh__) // closes video device for the reverse playback workaround close(fd_video); #endif sendEvent(evtStopped); { /* mutex lock scope */ eSingleLocker lock(m_run_mutex); m_run_state = 0; m_run_cond.signal(); /* Tell them we're here */ while (m_stop == 2) { eDebug("FILEPUSH THREAD PAUSED"); m_run_cond.wait(m_run_mutex); } if (m_stop == 0) m_run_state = 1; } } while (m_stop == 0); eDebug("FILEPUSH THREAD STOP"); }
void ResourceManager::loop() { iMustStopLoop = false; while( !iMustStopLoop ) { _updateElapsedTime(); UpdateEvent updateEvent(this, iElapsedTime); // The 'ResourceManager::loop()' function only updates the 'logical' objects. Renderers are updated // using the 'Renderer::launch()' function. To draw a RenderTarget, use 'Renderer::registerTarget()' to // enable it to drawing. // This loop only updates every Windows, and every RenderSceneManager. // First, we update every Windows objects. WindowHolderList whlist = iWindowManager->getWindows(); if(whlist.empty() && iCloseBehaviour == CloseBehaviour::AllWindowClosed) { iMustStopLoop = true; } else { if( !whlist.empty() ) { for(auto wholder : whlist) { if(wholder) { if(wholder->hasBeenClosed()) { // Window has been closed, we can destroy it. iWindowManager->remove(wholder->getName()); } else { // For now , we have to lock the mutex here to be sure any operations are made // within a valid mutex. wholder->lockGuard(); wholder->onEvent(updateEvent); wholder->unlockGuard(); iPerWindowBehaviours.call(); } } } } iLoopBehaviours.call(); } // Update also the RenderScene's objects. RenderSceneHolderList smhlist = iRenderSceneManager->getAll(); if( !smhlist.empty() ) { for(auto smholder : smhlist) { if( smholder ) { smholder->onEvent(updateEvent); } } } // Finally we send update event to every Listeners. sendEvent(updateEvent); } }
void eFilePushThread::thread() { int eofcount = 0; setIoPrio(prio_class, prio); int buf_end = 0; size_t bytes_read = 0; off_t current_span_offset = 0; size_t current_span_remaining = 0; eDebug("FILEPUSH THREAD START"); /* we set the signal to not restart syscalls, so we can detect our signal. */ struct sigaction act; act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR act.sa_flags = 0; sigaction(SIGUSR1, &act, 0); hasStarted(); while (!m_stop) { if (m_sg && !current_span_remaining) { m_sg->getNextSourceSpan(m_current_position, bytes_read, current_span_offset, current_span_remaining); ASSERT(!(current_span_remaining % m_blocksize)); m_current_position = current_span_offset; bytes_read = 0; } size_t maxread = m_buffersize; /* if we have a source span, don't read past the end */ if (m_sg && maxread > current_span_remaining) maxread = current_span_remaining; /* align to blocksize */ maxread -= maxread % m_blocksize; if (maxread) { #ifdef SHOW_WRITE_TIME struct timeval starttime; struct timeval now; gettimeofday(&starttime, NULL); #endif buf_end = m_source->read(m_current_position, m_buffer, maxread); #ifdef SHOW_WRITE_TIME gettimeofday(&now, NULL); suseconds_t diff = (1000000 * (now.tv_sec - starttime.tv_sec)) + now.tv_usec - starttime.tv_usec; eDebug("[eFilePushThread] read %d bytes time: %9u us", buf_end, (unsigned int)diff); #endif } else buf_end = 0; if (buf_end < 0) { buf_end = 0; /* Check m_stop after interrupted syscall. */ if (m_stop) { break; } if (errno == EINTR || errno == EBUSY || errno == EAGAIN) continue; if (errno == EOVERFLOW) { eWarning("OVERFLOW while playback?"); continue; } eDebug("eFilePushThread *read error* (%m) - not yet handled"); } /* a read might be mis-aligned in case of a short read. */ int d = buf_end % m_blocksize; if (d) buf_end -= d; if (buf_end == 0) { /* on EOF, try COMMITting once. */ if (m_send_pvr_commit) { struct pollfd pfd; pfd.fd = m_fd_dest; pfd.events = POLLIN; switch (poll(&pfd, 1, 250)) // wait for 250ms { case 0: eDebug("wait for driver eof timeout"); continue; case 1: eDebug("wait for driver eof ok"); break; default: eDebug("wait for driver eof aborted by signal"); /* Check m_stop after interrupted syscall. */ if (m_stop) break; continue; } } if (m_stop) break; /* in stream_mode, we are sending EOF events over and over until somebody responds. in stream_mode, think of evtEOF as "buffer underrun occurred". */ sendEvent(evtEOF); if (m_stream_mode) { eDebug("reached EOF, but we are in stream mode. delaying 1 second."); sleep(1); continue; } else if (++eofcount < 10) { eDebug("reached EOF, but the file may grow. delaying 1 second."); sleep(1); continue; } break; } else { /* Write data to mux */ int buf_start = 0; filterRecordData(m_buffer, buf_end); while ((buf_start != buf_end) && !m_stop) { int w = write(m_fd_dest, m_buffer + buf_start, buf_end - buf_start); if (w <= 0) { /* Check m_stop after interrupted syscall. */ if (m_stop) { w = 0; buf_start = 0; buf_end = 0; break; } if (w < 0 && (errno == EINTR || errno == EAGAIN || errno == EBUSY)) continue; eDebug("eFilePushThread WRITE ERROR"); sendEvent(evtWriteError); break; } buf_start += w; } eofcount = 0; m_current_position += buf_end; bytes_read += buf_end; if (m_sg) current_span_remaining -= buf_end; } } sendEvent(evtStopped); eDebug("FILEPUSH THREAD STOP"); }
void ComponentMovement::suicide() { EventCharacterHasDied m; sendEvent(&m); }
ISocketMultiplexerJob* CTCPSocket::serviceConnected(ISocketMultiplexerJob* job, bool read, bool write, bool error) { CLock lock(&m_mutex); if (error) { sendEvent(getDisconnectedEvent()); onDisconnected(); return newJob(); } bool needNewJob = false; if (write) { try { // write data UInt32 n = m_outputBuffer.getSize(); const void* buffer = m_outputBuffer.peek(n); n = (UInt32)ARCH->writeSocket(m_socket, buffer, n); // discard written data if (n > 0) { m_outputBuffer.pop(n); if (m_outputBuffer.getSize() == 0) { sendEvent(getOutputFlushedEvent()); m_flushed = true; m_flushed.broadcast(); needNewJob = true; } } } catch (XArchNetworkShutdown&) { // remote read end of stream hungup. our output side // has therefore shutdown. onOutputShutdown(); sendEvent(getOutputShutdownEvent()); if (!m_readable && m_inputBuffer.getSize() == 0) { sendEvent(getDisconnectedEvent()); m_connected = false; } needNewJob = true; } catch (XArchNetworkDisconnected&) { // stream hungup onDisconnected(); sendEvent(getDisconnectedEvent()); needNewJob = true; } catch (XArchNetwork& e) { // other write error LOG((CLOG_WARN "error writing socket: %s", e.what().c_str())); onDisconnected(); sendEvent(getOutputErrorEvent()); sendEvent(getDisconnectedEvent()); needNewJob = true; } } if (read && m_readable) { try { UInt8 buffer[4096]; size_t n = ARCH->readSocket(m_socket, buffer, sizeof(buffer)); if (n > 0) { bool wasEmpty = (m_inputBuffer.getSize() == 0); // slurp up as much as possible do { m_inputBuffer.write(buffer, n); n = ARCH->readSocket(m_socket, buffer, sizeof(buffer)); } while (n > 0); // send input ready if input buffer was empty if (wasEmpty) { sendEvent(getInputReadyEvent()); } } else { // remote write end of stream hungup. our input side // has therefore shutdown but don't flush our buffer // since there's still data to be read. sendEvent(getInputShutdownEvent()); if (!m_writable && m_inputBuffer.getSize() == 0) { sendEvent(getDisconnectedEvent()); m_connected = false; } m_readable = false; needNewJob = true; } } catch (XArchNetworkDisconnected&) { // stream hungup sendEvent(getDisconnectedEvent()); onDisconnected(); needNewJob = true; } catch (XArchNetwork& e) { // ignore other read error LOG((CLOG_WARN "error reading socket: %s", e.what().c_str())); } } return needNewJob ? newJob() : job; }
void CCombatNPC::update(s32 elapsedTime) { IAIEntity::update(elapsedTime); #ifdef NPC_DEBUG printf("NPC (%i) Update nodes\n", node->getID()); #endif if (FieldOfView) { FieldOfView->setPosition(Node->getAbsolutePosition()); FieldOfView->setRotation(Node->getRotation() + FOV_ROTATION); } if (DebugFOV) { DebugFOV->updateAbsolutePosition(); DebugFOV->setPosition(Node->getAbsolutePosition()); DebugFOV->setRotation(Node->getRotation() + FOV_ROTATION); } #ifdef NPC_DEBUG printf("NPC (%i) check FOV\n", Node->getID()); #endif checkFieldOfVision(); switch (State) { case ENST_WAITING: { #ifdef NPC_DEBUG printf("NPC (%i) waiting\n", node->getID()); #endif if (StayPut) {// If we want to stay put then keep waiting, whilst scanning the area return; } else { // If we've completed our path we return if (PathToDestination.size() == 0 && CurrentWaypoint == PathDestinationWaypoint) { sendEvent(ENET_AT_GOAL, NULL); changeState(ENST_WAITING); } else changeState(ENST_FOLLOWING_PATH); // Keep on going! } break; } case ENST_MOVING: { #ifdef NPC_DEBUG printf("NPC (%i) moving\n", node->getID()); #endif if (DestinationWaypoint && !(Node->getAbsolutePosition().getDistanceFrom(DestinationWaypoint->getPosition() + NodeOffset) <= AtDestinationThreshold) ) { // Not at our destination yet so move a bit closer core::vector3df dir = ((DestinationWaypoint->getPosition() + NodeOffset) - Node->getAbsolutePosition()).normalize(); f32 factor = elapsedTime * MoveSpeed; Node->setPosition(Node->getAbsolutePosition() + dir * factor); break; } else { // reached destination, wait for what to do next //currentWaypoint = destinationWaypoint; changeState(ENST_WAITING); } break; } case ENST_FOLLOWING_PATH: { #ifdef NPC_DEBUG printf("NPC (%i) following path\n", node->getID()); #endif // If we're not at the current waypoint then go there (this can happen when stopping mid-path) if (DestinationWaypoint && !(Node->getPosition().getDistanceFrom(DestinationWaypoint->getPosition() + NodeOffset) <= AtDestinationThreshold) ) { DestinationWaypoint = CurrentWaypoint; } else { if (PathToDestination.size() == 0) { changeState(ENST_WAITING); break; } // Take the next waypoint in the path (the path is in reverse so we take from the back) DestinationWaypoint = PathToDestination[PathToDestination.size()-1]; // remove the waypoint we've just taken PathToDestination.erase(PathToDestination.size()-1); } if (DestinationWaypoint) { // Rotate to face new destination and set running animation rotateToFace(DestinationWaypoint->getPosition() + NodeOffset); // Update current waypoint, that being the one we're aiming for. CurrentWaypoint = DestinationWaypoint; changeState(ENST_MOVING); } else changeState(ENST_WAITING); break; } } #ifdef NPC_DEBUG printf("NPC (%i) updated\n", Node->getID()); #endif }
void ComponentDestroySelfOnCollision::broadcastEventCharacterHasDied() { EventCharacterHasDied m; sendEvent(&m); }
void MtpServer::sendStoreRemoved(MtpStorageID id) { LOGV("sendStoreRemoved %08X\n", id); sendEvent(MTP_EVENT_STORE_REMOVED, id); }
void MtpServer::sendStoreAdded(MtpStorageID id) { LOGV("sendStoreAdded %08X\n", id); sendEvent(MTP_EVENT_STORE_ADDED, id); }
void *CVSCPBTDetectWrkTread::Entry() { BLUETOOTH_FIND_RADIO_PARAMS bt_find_radio = { sizeof( BLUETOOTH_FIND_RADIO_PARAMS ) }; BLUETOOTH_RADIO_INFO bt_info = { sizeof( BLUETOOTH_RADIO_INFO ), 0, }; BLUETOOTH_DEVICE_SEARCH_PARAMS search_params = { sizeof(BLUETOOTH_DEVICE_SEARCH_PARAMS), 1, 0, 1, 1, 1, 1, // Timeout NULL }; BLUETOOTH_DEVICE_INFO device_info = { sizeof( BLUETOOTH_DEVICE_INFO ), 0, }; HANDLE radio = NULL; HBLUETOOTH_RADIO_FIND bt = NULL; HBLUETOOTH_DEVICE_FIND bt_dev = NULL; // First log on to the host and get configuration // variables if ( VSCP_ERROR_SUCCESS != m_srv.doCmdOpen( m_pObj->m_host, m_pObj->m_username, m_pObj->m_password ) ) { return NULL; } // Find the channel id uint32_t ChannelID; m_srv.doCmdGetChannelID( &ChannelID ); // It is possible that there is configuration data the server holds // that we need to read in. // We look for // prefix_period Seconds between scans. // prefix_zone Zone to use for Token Activity // prefix_subzone Subzone to use for Token Activity // prefix_bsendtoken Send Token activity. Class=20 (Information, Type=37 // prefix_bsenddetect Send detect event. Class=20 (Information), Type=49 // prefix_detectzone // prefix_detectsubzone // // Future defines. // =============== // prefix_onaddresses - List with addresses that will generate on-event // prefix_offaddresses - List with addresses that will generate off-event bool bSendTokenActivity = true; // Sending Token Activity is default behaviour. bool bSendDetect = false; // Sending detect events must be enabled. uint16_t pausTime = 1; // default svan period is one seconds. uint8_t zone = 0; // Zone for token activity. uint8_t subzone = 0; // Subzone for token activity. uint8_t detectIndex = 0; // Index used for detect event. uint8_t detectZone = 0; // Zone used for detect event. uint8_t detectSubzone = 0; // Subzone used for detect events. bool bDisableRadiodetect= false; // Don't report radio discovery. wxString strAddress; _deviceHash deviceHashPrev; _deviceHash deviceHashNow; CDetectedDevice *pDevice; int intvalue; bool bvalue; if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_pausetime" ), &intvalue ) ) { if ( intvalue >= 0 ) pausTime = intvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_zone" ), &intvalue ) ) { zone = intvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_subzone" ), &intvalue ) ) { subzone = intvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_detectindex" ), &intvalue ) ) { detectIndex = intvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_detectzone" ), &intvalue ) ) { detectZone = intvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableInt( m_pObj->m_prefix + _( "_detectsubzone" ), &intvalue ) ) { detectSubzone = intvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableBool( m_pObj->m_prefix + _( "_send_token_activity" ), &bvalue ) ) { bSendTokenActivity = bvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableBool( m_pObj->m_prefix + _( "_send_detect" ), &bvalue ) ) { bSendDetect = bvalue; } if ( VSCP_ERROR_SUCCESS == m_srv.getVariableBool( m_pObj->m_prefix + _( "_disable_radio_detect" ), &bvalue ) ) { bDisableRadiodetect = bvalue; } // Close the channel m_srv.doCmdClose(); while ( !TestDestroy() && !m_pObj->m_bQuit ) { bt = BluetoothFindFirstRadio( &bt_find_radio, &radio ); int radio_id = 0; do { radio_id++; if ( ERROR_SUCCESS == BluetoothGetRadioInfo( radio, &bt_info ) ) { strAddress.Printf( _("%02x:%02x:%02x:%02x:%02x:%02x"), bt_info.address.rgBytes[ 0 ], bt_info.address.rgBytes[ 1 ], bt_info.address.rgBytes[ 2 ], bt_info.address.rgBytes[ 3 ], bt_info.address.rgBytes[ 4 ], bt_info.address.rgBytes[ 5 ] ); if ( deviceHashPrev.count( strAddress ) && ( NULL != ( pDevice = deviceHashPrev[ strAddress ] ) ) ) { // Address is known and in the table pDevice->m_bfound = true; } else { if ( !bDisableRadiodetect ) { // Add the new device pDevice = new CDetectedDevice(); if ( NULL != pDevice ) { pDevice->m_radio_id = radio_id; pDevice->m_device_id = 0; memcpy( pDevice->m_address, bt_info.address.rgBytes, 6 ); pDevice->m_name = bt_info.szName; pDevice->m_class = bt_info.ulClassofDevice; pDevice->m_manufacturer = bt_info.manufacturer; deviceHashNow[ strAddress ] = pDevice; } } } search_params.hRadio = radio; ::ZeroMemory( &device_info, sizeof( BLUETOOTH_DEVICE_INFO ) ); device_info.dwSize = sizeof( BLUETOOTH_DEVICE_INFO ); if ( NULL != ( bt_dev = BluetoothFindFirstDevice( &search_params, &device_info ) ) ) { int device_id = 0; do { device_id++; strAddress.Printf( _("%02x:%02x:%02x:%02x:%02x:%02x"), device_info.Address.rgBytes[ 0 ], device_info.Address.rgBytes[ 1 ], device_info.Address.rgBytes[ 2 ], device_info.Address.rgBytes[ 3 ], device_info.Address.rgBytes[ 4 ], device_info.Address.rgBytes[ 5 ]); if ( deviceHashPrev.count( strAddress ) && ( NULL != ( pDevice = deviceHashPrev[ strAddress ] ) ) ) { // Address is known and in the table pDevice->m_bfound = true; } else { // Add the new device pDevice = new CDetectedDevice(); if ( NULL != pDevice ) { pDevice->m_radio_id = radio_id; pDevice->m_device_id = device_id; memcpy( pDevice->m_address, device_info.Address.rgBytes, 6 ); pDevice->m_name = device_info.szName; pDevice->m_class = device_info.ulClassofDevice; memcpy( &pDevice->m_lastSeen, &device_info.stLastSeen, sizeof( SYSTEMTIME ) ); deviceHashNow[ strAddress ] = pDevice; } } } while ( BluetoothFindNextDevice( bt_dev, &device_info ) ); BluetoothFindDeviceClose( bt_dev ); } } } while ( BluetoothFindNextRadio( &bt_find_radio, &radio ) ); BluetoothFindRadioClose( bt ); // Go through devices that have been lost since last run _deviceHash::iterator itPrev; for ( itPrev = deviceHashPrev.begin(); itPrev != deviceHashPrev.end(); ++itPrev ) { wxString key = itPrev->first; CDetectedDevice *pDev = itPrev->second; if ( NULL == pDev ) { continue; } if ( false == pDev->m_bfound ) { if ( bSendTokenActivity ) { vscpEventEx evx; memset( evx.GUID, 0, 16 ); // Use interface GUID evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION; evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY; evx.timestamp = wxDateTime::Now().GetTicks(); evx.head = VSCP_PRIORITY_NORMAL; evx.sizeData = 8; evx.data[ 0 ] = ( 18 << 2 ) + 2; // Bluetooth device + "Released" evx.data[ 1 ] = zone; evx.data[ 2 ] = subzone; evx.data[ 3 ] = 0; // Frame 0 evx.data[ 4 ] = pDev->m_address[ 0 ]; evx.data[ 5 ] = pDev->m_address[ 1 ]; evx.data[ 6 ] = pDev->m_address[ 2 ]; evx.data[ 7 ] = pDev->m_address[ 3 ]; sendEvent( evx ); // Send the event memset( evx.GUID, 0, 16 ); // Use interface GUID evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION; evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY; evx.timestamp = wxDateTime::Now().GetMillisecond(); evx.head = VSCP_PRIORITY_NORMAL; evx.sizeData = 6; evx.data[ 0 ] = ( 18 << 2 ) + 2; // Bluetooth device + "Released" evx.data[ 1 ] = zone; evx.data[ 2 ] = subzone; evx.data[ 3 ] = 1; // Frame 1 evx.data[ 4 ] = pDev->m_address[ 4 ]; evx.data[ 5 ] = pDev->m_address[ 5 ]; sendEvent( evx ); } // Remove it delete pDev; deviceHashPrev[ key ] = NULL; } else { // Prepare for next detection loop pDev->m_bfound = false; } } // Go through devices that have been found since last run _deviceHash::iterator itNow; for ( itNow = deviceHashNow.begin(); itNow != deviceHashNow.end(); ++itNow ) { wxString key = itNow->first; CDetectedDevice *pDev = itNow->second; if ( NULL == pDev ) { continue; } // Save it in previously found devices deviceHashPrev[ key ] = pDev; deviceHashNow[ key ] = NULL; if ( bSendTokenActivity ) { // Tell the world we found it vscpEventEx evx; memset( evx.GUID, 0, 16 ); // Use interface GUID evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION; evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY; evx.timestamp = wxDateTime::Now().GetMillisecond(); evx.head = VSCP_PRIORITY_NORMAL; evx.sizeData = 8; evx.data[ 0 ] = ( 18 << 2 ) + 1; // Bluetooth device + "Touched" evx.data[ 1 ] = zone; evx.data[ 2 ] = subzone; evx.data[ 3 ] = 0; // Frame 0 evx.data[ 4 ] = pDev->m_address[ 0 ]; evx.data[ 5 ] = pDev->m_address[ 1 ]; evx.data[ 6 ] = pDev->m_address[ 2 ]; evx.data[ 7 ] = pDev->m_address[ 3 ]; sendEvent( evx ); // Send the event memset( evx.GUID, 0, 16 ); // Use interface GUID evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION; evx.vscp_type = VSCP_TYPE_INFORMATION_TOKEN_ACTIVITY; evx.timestamp = wxDateTime::Now().GetMillisecond(); evx.head = VSCP_PRIORITY_NORMAL; evx.sizeData = 6; evx.data[ 0 ] = ( 18 << 2 ) + 1; // Bluetooth device + "Touched" evx.data[ 1 ] = zone; evx.data[ 2 ] = subzone; evx.data[ 3 ] = 1; // Frame 1 evx.data[ 4 ] = pDev->m_address[ 4 ]; evx.data[ 5 ] = pDev->m_address[ 5 ]; sendEvent( evx ); // Send the event } if ( bSendDetect ) { // Tell the world we detected it vscpEventEx evx; memset( evx.GUID, 0, 16 ); // Use interface GUID evx.vscp_class = VSCP_CLASS2_LEVEL1_INFORMATION; evx.vscp_type = VSCP_TYPE_INFORMATION_DETECT; evx.timestamp = wxDateTime::Now().GetMillisecond(); evx.head = VSCP_PRIORITY_NORMAL; evx.sizeData = 3; evx.data[ 0 ] = detectIndex; evx.data[ 1 ] = detectZone; evx.data[ 2 ] = detectSubzone; sendEvent( evx ); // Send the event } } wxSleep( pausTime ); } // detect loop return NULL; }
void HttpInterface::evVariableOrEvent(HttpRequest* req, strings& args) { string nodeName(args[0]); size_t eventPos; if ( ! commonDefinitions.events.contains(UTF8ToWString(args[1]), &eventPos)) { // this is a variable if (req->method.find("POST") == 0 || args.size() >= 3) { // set variable value strings values; if (args.size() >= 3) values.assign(args.begin()+1, args.end()); else { // Parse POST form data values.push_back(args[1]); parse_json_form(req->content, values); } if (values.size() == 0) { finishResponse(req, 404, ""); if (verbose) cerr << req << " evVariableOrEevent 404 can't set variable " << args[0] << ", no values" << endl; return; } sendSetVariable(nodeName, values); finishResponse(req, 200, ""); if (verbose) cerr << req << " evVariableOrEevent 200 set variable " << values[0] << endl; } else { // get variable value strings values; values.assign(args.begin()+1, args.begin()+2); unsigned source, start; if ( ! getNodeAndVarPos(nodeName, values[0], source, start)) { finishResponse(req, 404, ""); if (verbose) cerr << req << " evVariableOrEevent 404 no such variable " << values[0] << endl; return; } sendGetVariables(nodeName, values); pendingVariables[std::make_pair(source,start)].insert(req); if (verbose) cerr << req << " evVariableOrEevent schedule var " << values[0] << "(" << source << "," << start << ") add " << req << " to subscribers" << endl; return; } } else { // this is an event // arguments are args 1..N strings data; data.push_back(args[1]); if (args.size() >= 3) for (size_t i=2; i<args.size(); ++i) data.push_back((args[i].c_str())); else if (req->method.find("POST") == 0) { // Parse POST form data parse_json_form(std::string(req->content, req->content.size()), data); } sendEvent(nodeName, data); finishResponse(req, 200, ""); // or perhaps {"return_value":null,"cmd":"sendEvent","name":nodeName}? return; } }
void eFilePushThread::thread() { setIoPrio(prio_class, prio); off_t dest_pos = 0, source_pos = 0; size_t bytes_read = 0; off_t current_span_offset = 0; size_t current_span_remaining = 0; size_t written_since_last_sync = 0; eDebug("FILEPUSH THREAD START"); /* we set the signal to not restart syscalls, so we can detect our signal. */ struct sigaction act; act.sa_handler = signal_handler; // no, SIG_IGN doesn't do it. we want to receive the -EINTR act.sa_flags = 0; sigaction(SIGUSR1, &act, 0); hasStarted(); source_pos = m_raw_source.lseek(0, SEEK_CUR); /* m_stop must be evaluated after each syscall. */ while (!m_stop) { /* first try flushing the bufptr */ if (m_buf_start != m_buf_end) { /* filterRecordData wants to work on multiples of blocksize. if it returns a negative result, it means that this many bytes should be skipped *in front* of the buffer. Then, it will be called again. with the newer, shorter buffer. if filterRecordData wants to skip more data then currently available, it must do that internally. Skipped bytes will also not be output. if it returns a positive result, that means that only these many bytes should be used in the buffer. In either case, current_span_remaining is given as a reference and can be modified. (Of course it doesn't make sense to decrement it to a non-zero value unless you return 0 because that would just skip some data). This is probably a very special application for fast-forward, where the current span is to be cancelled after a complete iframe has been output. we always call filterRecordData with our full buffer (otherwise we couldn't easily strip from the end) we filter data only once, of course, but it might not get immediately written. that's what m_filter_end is for - it points to the start of the unfiltered data. */ int filter_res; do { filter_res = filterRecordData(m_buffer + m_filter_end, m_buf_end - m_filter_end, current_span_remaining); if (filter_res < 0) { eDebug("[eFilePushThread] filterRecordData re-syncs and skips %d bytes", -filter_res); m_buf_start = m_filter_end + -filter_res; /* this will also drop unwritten data */ ASSERT(m_buf_start <= m_buf_end); /* otherwise filterRecordData skipped more data than available. */ continue; /* try again */ } /* adjust end of buffer to strip dropped tail bytes */ m_buf_end = m_filter_end + filter_res; /* mark data as filtered. */ m_filter_end = m_buf_end; } while (0); ASSERT(m_filter_end == m_buf_end); if (m_buf_start == m_buf_end) continue; /* now write out data. it will be 'aligned' (according to filterRecordData). absolutely forbidden is to return EINTR and consume a non-aligned number of bytes. */ int w = write(m_fd_dest, m_buffer + m_buf_start, m_buf_end - m_buf_start); // fwrite(m_buffer + m_buf_start, 1, m_buf_end - m_buf_start, f); // eDebug("wrote %d bytes", w); if (w <= 0) { if (errno == EINTR || errno == EAGAIN || errno == EBUSY) continue; eDebug("eFilePushThread WRITE ERROR"); sendEvent(evtWriteError); break; // ... we would stop the thread } written_since_last_sync += w; if (written_since_last_sync >= 512*1024) { int toflush = written_since_last_sync > 2*1024*1024 ? 2*1024*1024 : written_since_last_sync &~ 4095; // write max 2MB at once dest_pos = lseek(m_fd_dest, 0, SEEK_CUR); dest_pos -= toflush; posix_fadvise(m_fd_dest, dest_pos, toflush, POSIX_FADV_DONTNEED); written_since_last_sync -= toflush; } // printf("FILEPUSH: wrote %d bytes\n", w); m_buf_start += w; continue; } /* now fill our buffer. */ if (m_sg && !current_span_remaining) { m_sg->getNextSourceSpan(source_pos, bytes_read, current_span_offset, current_span_remaining); ASSERT(!(current_span_remaining % m_blocksize)); if (source_pos != current_span_offset) source_pos = m_raw_source.lseek(current_span_offset, SEEK_SET); bytes_read = 0; } size_t maxread = sizeof(m_buffer); /* if we have a source span, don't read past the end */ if (m_sg && maxread > current_span_remaining) maxread = current_span_remaining; /* align to blocksize */ maxread -= maxread % m_blocksize; m_buf_start = 0; m_filter_end = 0; m_buf_end = 0; if (maxread) m_buf_end = m_raw_source.read(m_buffer, maxread); if (m_buf_end < 0) { m_buf_end = 0; if (errno == EINTR || errno == EBUSY || errno == EAGAIN) continue; if (errno == EOVERFLOW) { eWarning("OVERFLOW while recording"); continue; } eDebug("eFilePushThread *read error* (%m) - not yet handled"); } /* a read might be mis-aligned in case of a short read. */ int d = m_buf_end % m_blocksize; if (d) { m_raw_source.lseek(-d, SEEK_CUR); m_buf_end -= d; } if (m_buf_end == 0) { /* on EOF, try COMMITting once. */ if (m_send_pvr_commit) { struct pollfd pfd; pfd.fd = m_fd_dest; pfd.events = POLLIN; switch (poll(&pfd, 1, 250)) // wait for 250ms { case 0: eDebug("wait for driver eof timeout"); continue; case 1: eDebug("wait for driver eof ok"); break; default: eDebug("wait for driver eof aborted by signal"); continue; } } /* in stream_mode, we are sending EOF events over and over until somebody responds. in stream_mode, think of evtEOF as "buffer underrun occured". */ sendEvent(evtEOF); if (m_stream_mode) { eDebug("reached EOF, but we are in stream mode. delaying 1 second."); sleep(1); continue; } #if 0 eDebug("FILEPUSH: end-of-file! (currently unhandled)"); if (!m_raw_source.lseek(0, SEEK_SET)) { eDebug("(looping)"); continue; } #endif break; } else { source_pos += m_buf_end; bytes_read += m_buf_end; if (m_sg) current_span_remaining -= m_buf_end; } // printf("FILEPUSH: read %d bytes\n", m_buf_end); } fdatasync(m_fd_dest); eDebug("FILEPUSH THREAD STOP"); }
status_t DashPlayerDriver::prepare() { sendEvent(MEDIA_SET_VIDEO_SIZE, 0, 0); return OK; }
void Controller::update(double delta_time) { symulation.update(delta_time* time_speed); if (symulation.isWindowOpen() != last_window_state) if (symulation.isWindowOpen()) sendEvent(EventType::WindowOpened); else sendEvent(EventType::WindowClosed); if (symulation.isRaining() != last_rain_state) if (symulation.isRaining()) sendEvent(EventType::RainStarted); else sendEvent(EventType::RainEnded); if (symulation.isDay() != last_day_state) if (symulation.isDay()) sendEvent(EventType::DayStarted); else sendEvent(EventType::NightStarted); if (symulation.isSun() != last_sun_state) if (symulation.isSun()) sendEvent(EventType::SunStarted); else sendEvent(EventType::SunEnded); bool new_summer_state = symulation.getOutsideTemerarure() > symulation.getInsideTemerature(); if (last_summer_state != new_summer_state) if (new_summer_state) sendEvent(EventType::SummerStarted); else sendEvent(EventType::WinterStarted); if (symulation.getInsideTemerature() > td + td_hist) sendEvent(EventType::TooHot); if (symulation.getInsideTemerature() < td - td_hist) sendEvent(EventType::TooCold); if (std::abs(symulation.getInsideTemerature() - td) < tconf_hist) sendEvent(EventType::Comfort); else sendEvent(EventType::OutOfComfort); last_window_state = symulation.isWindowOpen(); last_rain_state = symulation.isRaining(); last_summer_state = symulation.getOutsideTemerarure() > symulation.getInsideTemerature(); last_day_state = symulation.isDay(); last_sun_state = symulation.isSun(); if (!symulation.isCooling() && !symulation.isHeating()) { std::cout << "cookie!"; } }
void CrossfireServer::eventClosed() { CrossfireEvent eventObj; eventObj.setName(EVENT_CLOSED); sendEvent(&eventObj); }
static Iface_DEFUN incomingMsg(struct Message* msg, struct Pathfinder_pvt* pf) { struct Address addr; struct RouteHeader* hdr = (struct RouteHeader*) msg->bytes; Message_shift(msg, -(RouteHeader_SIZE + DataHeader_SIZE), NULL); Bits_memcpy(addr.ip6.bytes, hdr->ip6, 16); Bits_memcpy(addr.key, hdr->publicKey, 32); addr.protocolVersion = Endian_bigEndianToHost32(hdr->version_be); addr.padding = 0; addr.path = Endian_bigEndianToHost64(hdr->sh.label_be); //Log_debug(pf->log, "Incoming DHT"); struct DHTMessage dht = { .address = &addr, .binMessage = msg, .allocator = msg->alloc }; DHTModuleRegistry_handleIncoming(&dht, pf->registry); struct Message* nodeMsg = Message_new(0, 256, msg->alloc); Iface_CALL(sendNode, nodeMsg, &addr, 0xfffffff0u, pf); if (dht.pleaseRespond) { // what a beautiful hack, see incomingFromDHT return Iface_next(&pf->pub.eventIf, msg); } return NULL; } static Iface_DEFUN incomingFromEventIf(struct Message* msg, struct Iface* eventIf) { struct Pathfinder_pvt* pf = Identity_containerOf(eventIf, struct Pathfinder_pvt, pub.eventIf); enum PFChan_Core ev = Message_pop32(msg, NULL); if (Pathfinder_pvt_state_INITIALIZING == pf->state) { Assert_true(ev == PFChan_Core_CONNECT); return connected(pf, msg); } // Let the PF send another 128 path changes again because it's basically a new tick. pf->bestPathChanges = 0; switch (ev) { case PFChan_Core_SWITCH_ERR: return switchErr(msg, pf); case PFChan_Core_SEARCH_REQ: return searchReq(msg, pf); case PFChan_Core_PEER: return peer(msg, pf); case PFChan_Core_PEER_GONE: return peerGone(msg, pf); case PFChan_Core_SESSION: return session(msg, pf); case PFChan_Core_SESSION_ENDED: return sessionEnded(msg, pf); case PFChan_Core_DISCOVERED_PATH: return discoveredPath(msg, pf); case PFChan_Core_MSG: return incomingMsg(msg, pf); case PFChan_Core_PING: return handlePing(msg, pf); case PFChan_Core_PONG: return handlePong(msg, pf); case PFChan_Core_UNSETUP_SESSION: case PFChan_Core_LINK_STATE: case PFChan_Core_CTRL_MSG: return NULL; default:; } Assert_failure("unexpected event [%d]", ev); } static void sendEvent(struct Pathfinder_pvt* pf, enum PFChan_Pathfinder ev, void* data, int size) { struct Allocator* alloc = Allocator_child(pf->alloc); struct Message* msg = Message_new(0, 512+size, alloc); Message_push(msg, data, size, NULL); Message_push32(msg, ev, NULL); Iface_send(&pf->pub.eventIf, msg); Allocator_free(alloc); } static void init(void* vpf) { struct Pathfinder_pvt* pf = Identity_check((struct Pathfinder_pvt*) vpf); struct PFChan_Pathfinder_Connect conn = { .superiority_be = Endian_hostToBigEndian32(1), .version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL) }; CString_strncpy(conn.userAgent, "Cjdns internal pathfinder", 64); sendEvent(pf, PFChan_Pathfinder_CONNECT, &conn, PFChan_Pathfinder_Connect_SIZE); } struct Pathfinder* Pathfinder_register(struct Allocator* allocator, struct Log* log, struct EventBase* base, struct Random* rand, struct Admin* admin) { struct Allocator* alloc = Allocator_child(allocator); struct Pathfinder_pvt* pf = Allocator_calloc(alloc, sizeof(struct Pathfinder_pvt), 1); Identity_set(pf); pf->alloc = alloc; pf->log = log; pf->base = base; pf->rand = rand; pf->admin = admin; pf->pub.eventIf.send = incomingFromEventIf; pf->dhtModule.context = pf; pf->dhtModule.handleOutgoing = incomingFromDHT; // This needs to be done asynchronously so the pf can be plumbed to the core Timeout_setTimeout(init, pf, 0, base, alloc); return &pf->pub; }
/** * Send the object's data to the GCS (triggers a EV_UPDATED_MANUAL event on this object). * \param[in] obj The object handle * \param[in] instId The object instance ID */ void UAVObjInstanceUpdated(UAVObjHandle obj, uint16_t instId) { xSemaphoreTakeRecursive(mutex, portMAX_DELAY); sendEvent((ObjectList *) obj, instId, EV_UPDATED_MANUAL); xSemaphoreGiveRecursive(mutex); }
void EventSender::keyDown(const QString& string, const QStringList& modifiers, unsigned int location) { QString s = string; Qt::KeyboardModifiers modifs = getModifiers(modifiers); if (location == 3) modifs |= Qt::KeypadModifier; int code = 0; if (string.length() == 1) { code = string.unicode()->unicode(); //qDebug() << ">>>>>>>>> keyDown" << code << (char)code; // map special keycodes used by the tests to something that works for Qt/X11 if (code == '\r') { code = Qt::Key_Return; } else if (code == '\t') { code = Qt::Key_Tab; if (modifs == Qt::ShiftModifier) code = Qt::Key_Backtab; s = QString(); } else if (code == KEYCODE_DEL || code == KEYCODE_BACKSPACE) { code = Qt::Key_Backspace; if (modifs == Qt::AltModifier) modifs = Qt::ControlModifier; s = QString(); } else if (code == 'o' && modifs == Qt::ControlModifier) { // Mimic the emacs ctrl-o binding on Mac by inserting a paragraph // separator and then putting the cursor back to its original // position. Allows us to pass emacs-ctrl-o.html s = QLatin1String("\n"); code = '\n'; modifs = 0; QKeyEvent event(QEvent::KeyPress, code, modifs, s); sendEvent(m_page, &event); QKeyEvent event2(QEvent::KeyRelease, code, modifs, s); sendEvent(m_page, &event2); s = QString(); code = Qt::Key_Left; } else if (code == 'y' && modifs == Qt::ControlModifier) { s = QLatin1String("c"); code = 'c'; } else if (code == 'k' && modifs == Qt::ControlModifier) { s = QLatin1String("x"); code = 'x'; } else if (code == 'a' && modifs == Qt::ControlModifier) { s = QString(); code = Qt::Key_Home; modifs = 0; } else if (code == KEYCODE_LEFTARROW) { s = QString(); code = Qt::Key_Left; if (modifs & Qt::MetaModifier) { code = Qt::Key_Home; modifs &= ~Qt::MetaModifier; } } else if (code == KEYCODE_RIGHTARROW) { s = QString(); code = Qt::Key_Right; if (modifs & Qt::MetaModifier) { code = Qt::Key_End; modifs &= ~Qt::MetaModifier; } } else if (code == KEYCODE_UPARROW) { s = QString(); code = Qt::Key_Up; if (modifs & Qt::MetaModifier) { code = Qt::Key_PageUp; modifs &= ~Qt::MetaModifier; } } else if (code == KEYCODE_DOWNARROW) { s = QString(); code = Qt::Key_Down; if (modifs & Qt::MetaModifier) { code = Qt::Key_PageDown; modifs &= ~Qt::MetaModifier; } } else if (code == 'a' && modifs == Qt::ControlModifier) { s = QString(); code = Qt::Key_Home; modifs = 0; } else code = string.unicode()->toUpper().unicode(); } else { //qDebug() << ">>>>>>>>> keyDown" << string; if (string.startsWith(QLatin1Char('F')) && string.count() <= 3) { s = s.mid(1); int functionKey = s.toInt(); Q_ASSERT(functionKey >= 1 && functionKey <= 35); code = Qt::Key_F1 + (functionKey - 1); // map special keycode strings used by the tests to something that works for Qt/X11 } else if (string == QLatin1String("leftArrow")) { s = QString(); code = Qt::Key_Left; } else if (string == QLatin1String("rightArrow")) { s = QString(); code = Qt::Key_Right; } else if (string == QLatin1String("upArrow")) { s = QString(); code = Qt::Key_Up; } else if (string == QLatin1String("downArrow")) { s = QString(); code = Qt::Key_Down; } else if (string == QLatin1String("pageUp")) { s = QString(); code = Qt::Key_PageUp; } else if (string == QLatin1String("pageDown")) { s = QString(); code = Qt::Key_PageDown; } else if (string == QLatin1String("home")) { s = QString(); code = Qt::Key_Home; } else if (string == QLatin1String("end")) { s = QString(); code = Qt::Key_End; } else if (string == QLatin1String("insert")) { s = QString(); code = Qt::Key_Insert; } else if (string == QLatin1String("delete")) { s = QString(); code = Qt::Key_Delete; } else if (string == QLatin1String("printScreen")) { s = QString(); code = Qt::Key_Print; } else if (string == QLatin1String("menu")) { s = QString(); code = Qt::Key_Menu; } } QKeyEvent event(QEvent::KeyPress, code, modifs, s); sendEvent(m_page, &event); QKeyEvent event2(QEvent::KeyRelease, code, modifs, s); sendEvent(m_page, &event2); }
void MtpServer::sendObjectAdded(MtpObjectHandle handle) { LOGV("sendObjectAdded %d\n", handle); sendEvent(MTP_EVENT_OBJECT_ADDED, handle); }
int MidiFile::render() { EAS_RESULT result = EAS_FAILURE; EAS_I32 count; int temp; bool audioStarted = false; ALOGV("MidiFile::render"); // allocate render buffer mAudioBuffer = new EAS_PCM[pLibConfig->mixBufferSize * pLibConfig->numChannels * NUM_BUFFERS]; if (!mAudioBuffer) { ALOGE("mAudioBuffer allocate failed"); goto threadExit; } // signal main thread that we started { Mutex::Autolock l(mMutex); mTid = gettid(); ALOGV("render thread(%d) signal", mTid); mCondition.signal(); } while (1) { mMutex.lock(); // nothing to render, wait for client thread to wake us up while (!mRender && !mExit) { ALOGV("MidiFile::render - signal wait"); mCondition.wait(mMutex); ALOGV("MidiFile::render - signal rx'd"); } if (mExit) { mMutex.unlock(); break; } // render midi data into the input buffer //ALOGV("MidiFile::render - rendering audio"); int num_output = 0; EAS_PCM* p = mAudioBuffer; for (int i = 0; i < NUM_BUFFERS; i++) { result = EAS_Render(mEasData, p, pLibConfig->mixBufferSize, &count); if (result != EAS_SUCCESS) { ALOGE("EAS_Render returned %ld", result); } p += count * pLibConfig->numChannels; num_output += count * pLibConfig->numChannels * sizeof(EAS_PCM); } // update playback state and position // ALOGV("MidiFile::render - updating state"); EAS_GetLocation(mEasData, mEasHandle, &mPlayTime); EAS_State(mEasData, mEasHandle, &mState); mMutex.unlock(); // create audio output track if necessary if (!mAudioSink->ready()) { ALOGV("MidiFile::render - create output track"); if (createOutputTrack() != NO_ERROR) goto threadExit; } // Write data to the audio hardware // ALOGV("MidiFile::render - writing to audio output"); if ((temp = mAudioSink->write(mAudioBuffer, num_output)) < 0) { ALOGE("Error in writing:%d",temp); return temp; } // start audio output if necessary if (!audioStarted) { //ALOGV("MidiFile::render - starting audio"); mAudioSink->start(); audioStarted = true; } // still playing? if ((mState == EAS_STATE_STOPPED) || (mState == EAS_STATE_ERROR) || (mState == EAS_STATE_PAUSED)) { switch(mState) { case EAS_STATE_STOPPED: { ALOGV("MidiFile::render - stopped"); mPlayTime = mDuration; sendEvent(MEDIA_PLAYBACK_COMPLETE); break; } case EAS_STATE_ERROR: { ALOGE("MidiFile::render - error"); sendEvent(MEDIA_ERROR, MEDIA_ERROR_UNKNOWN); break; } case EAS_STATE_PAUSED: ALOGV("MidiFile::render - paused"); break; default: break; } mAudioSink->stop(); audioStarted = false; mRender = false; } } threadExit: mAudioSink.clear(); if (mAudioBuffer) { delete [] mAudioBuffer; mAudioBuffer = NULL; } mMutex.lock(); mTid = -1; mCondition.signal(); mMutex.unlock(); return result; }
int RunEdit::processEvent (const Event& event) { switch (event.key) { case KB_F1: case KB_ALT_B: insBaseFile (); break; case KB_F2: case KB_ALT_F: insFile (); break; case KB_F3: case KB_ALT_D: insDir (); break; case KB_F4: case KB_ALT_P: insPrompt (); break; case KB_F5: case KB_ALT_M: insAllFiles (); break; case KB_F6: case KB_ALT_Q: insAllFilesQuoted (); break; case KB_F7: case KB_ALT_I: insImmediateReturn (); break; case KB_F8: case KB_ALT_A: insAutoRefresh (); break; case KB_F9: case KB_ALT_V: insDrive (); break; case KB_F10: case KB_ALT_T: insPathOnly (); break; case KB_CTRL_ENTER: sendEvent (Event (KB_ENTER)); mExitKey = KB_CTRL_ENTER; break; default: return Edit::processEvent (event); } return 1; }