int tools::messageArrivedCallback(void *context, char *topicName, int, MQTTAsync_message *message) { if(context != nullptr) { EventCallback *callback = static_cast<EventCallback*>(context); QString topic; if(topicName != nullptr) { topic = topicName; } else { topic = "unknown"; } QByteArray payload; if(message != nullptr) { // using this overload of "append" because the payload can contain more then one \0 payload.append(static_cast<char*>(message->payload), message->payloadlen); } qDebug() << payload.length(); callback->onMessageArrived(topic, payload); } else { qDebug() << "context was empty."; } MQTTAsync_free(topicName); MQTTAsync_freeMessage(&message); return true; }
void tools::deliveryCompleteCallback(void *context, MQTTAsync_token token) { if(context != nullptr) { EventCallback *callback = static_cast<EventCallback*>(context); callback->onDeliveryComplete(token); } else { qDebug() << "context was empty."; } }
//--------------------------------------------------------------------------------------- std::list<EventCallback*>::iterator Observer::find_handler(int eventType) { std::list<EventCallback*>::iterator it; for (it = m_handlers.begin(); it != m_handlers.end(); ++it) { EventCallback* pCB = *it; if (pCB->get_event_type() == eventType) break; } return it; }
void tools::connectionLostCallback(void *context, char *cause) { if(context != nullptr) { EventCallback *callback = static_cast<EventCallback*>(context); QString causeMsg; if(cause != nullptr) { causeMsg = cause; } else { causeMsg = "unknown"; } callback->onConnectionLost(causeMsg); } else { qDebug() << "context was empty."; } }
/** ** Called each frame to handle keyboard timeouts. ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system */ void InputKeyTimeout(const EventCallback &callbacks, unsigned ticks) { if (LastIKey && ticks > LastKeyTicks + HoldKeyDelay) { LastKeyTicks = ticks - (HoldKeyDelay - HoldKeyAdditionalDelay); callbacks.KeyRepeated(LastIKey, LastIKeyChar); } }
/** ** Called if the mouse is moved ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** @param x X movement ** @param y Y movement */ void InputMouseMove(const EventCallback &callbacks, unsigned ticks, int x, int y) { // Don't reset the mouse state unless we really moved #ifdef USE_TOUCHSCREEN const int buff = 32; if (((x - buff) <= MouseX && MouseX <= (x + buff)) == 0 || ((y - buff) <= MouseY && MouseY <= (y + buff)) == 0) { MouseState = InitialMouseState; LastMouseTicks = ticks; } if (MouseX != x || MouseY != y) { MouseX = x; MouseY = y; } #else if (MouseX != x || MouseY != y) { MouseState = InitialMouseState; LastMouseTicks = ticks; MouseX = x; MouseY = y; } #endif const PixelPos pos(x, y); callbacks.MouseMoved(pos); }
/** ** Called if any mouse button is released up ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** @param button Mouse button released. */ void InputMouseButtonRelease(const EventCallback &callbacks, unsigned ticks, unsigned button) { // Same button before pressed. if (button == LastMouseButton && MouseState == InitialMouseState) { MouseState = ClickedMouseState; } else { LastMouseButton = 0; MouseState = InitialMouseState; } LastMouseTicks = ticks; unsigned mask = 0; if (MouseButtons & ((1 << button) << MouseDoubleShift)) { mask |= button << MouseDoubleShift; } if (MouseButtons & ((1 << button) << MouseDragShift)) { mask |= button << MouseDragShift; } if (MouseButtons & ((1 << button) << MouseHoldShift)) { mask |= button << MouseHoldShift; } MouseButtons &= ~(0x01010101 << button); callbacks.ButtonReleased(button | mask); }
/** ** Called if the mouse is moved ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** @param x X movement ** @param y Y movement */ void InputMouseMove(const EventCallback &callbacks, unsigned ticks, int x, int y) { PixelPos mousePos(x, y); // Don't reset the mouse state unless we really moved #ifdef USE_TOUCHSCREEN const int buff = 32; const PixelDiff diff = LastMousePos - mousePos; if (abs(diff.x) > buff || abs(diff.y) > buff) { MouseState = InitialMouseState; LastMouseTicks = ticks; // Reset rectangle select cursor state if we moved by a lot // - rectangle select should be a drag, not a tap if (CursorState == CursorStateRectangle && (abs(diff.x) > 2 * buff || abs(diff.y) > 2 * buff)) { CursorState = CursorStatePoint; } } LastMousePos = mousePos; #else if (LastMousePos != mousePos) { MouseState = InitialMouseState; LastMouseTicks = ticks; LastMousePos = mousePos; } #endif callbacks.MouseMoved(mousePos); }
/** ** Handle keyboard key release. ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** @param ikey Key scancode. ** @param ikeychar Character code. */ void InputKeyButtonRelease(const EventCallback &callbacks, unsigned ticks, unsigned ikey, unsigned ikeychar) { if (ikey == LastIKey) { LastIKey = 0; } LastKeyTicks = ticks; callbacks.KeyReleased(ikey, ikeychar); }
void EventCallbackGen::unregisterEventCallback(EventCallback& cb) { DEB_MEMBER_FUNCT(); if (m_cb != &cb) THROW_HW_ERROR(InvalidValue) << "Specified EventCallback is not registered"; m_cb = NULL; cb.setEventCallbackGen(NULL); }
void EventCallbackGen::registerEventCallback(EventCallback& cb) { DEB_MEMBER_FUNCT(); if (m_cb) THROW_HW_ERROR(InvalidValue) << "An EventCallback is already registered"; cb.setEventCallbackGen(this); m_cb = &cb; }
/** ** Handle keyboard key press. ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** @param ikey Key scancode. ** @param ikeychar Character code. */ void InputKeyButtonPress(const EventCallback &callbacks, unsigned ticks, unsigned ikey, unsigned ikeychar) { if (!LastIKey && DoubleKey == ikey && ticks < LastKeyTicks + DoubleClickDelay) { KeyModifiers |= ModifierDoublePress; } DoubleKey = ikey; LastIKey = ikey; LastIKeyChar = ikeychar; LastKeyTicks = ticks; callbacks.KeyPressed(ikey, ikeychar); KeyModifiers &= ~ModifierDoublePress; }
/** ** Called each frame to handle mouse timeouts. ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system */ void InputMouseTimeout(const EventCallback &callbacks, unsigned ticks) { if (MouseButtons & (1 << LastMouseButton)) { if (ticks > StartMouseTicks + DoubleClickDelay) { MouseState = InitialMouseState; } if (ticks > LastMouseTicks + HoldClickDelay) { LastMouseTicks = ticks; MouseButtons |= (1 << LastMouseButton) << MouseHoldShift; callbacks.ButtonPressed(LastMouseButton | (LastMouseButton << MouseHoldShift)); } } }
/** ** Called if any mouse button is pressed down ** ** Handles event conversion to double click, dragging, hold. ** ** FIXME: dragging is not supported. ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** @param button Mouse button pressed. */ void InputMouseButtonPress(const EventCallback &callbacks, unsigned ticks, unsigned button) { // Button new pressed. if (!(MouseButtons & (1 << button))) { MouseButtons |= (1 << button); // Detect double click if (MouseState == ClickedMouseState && button == LastMouseButton && ticks < StartMouseTicks + DoubleClickDelay) { MouseButtons |= (1 << button) << MouseDoubleShift; button |= button << MouseDoubleShift; } else { MouseState = InitialMouseState; StartMouseTicks = ticks; LastMouseButton = button; } } LastMouseTicks = ticks; callbacks.ButtonPressed(button); }
/** ** Called if the mouse exits the game window (when supported by videomode) ** ** @param callbacks Callback structure for events. ** @param ticks Denotes time-stamp of video-system ** */ void InputMouseExit(const EventCallback &callbacks, unsigned /* ticks */) { // FIXME: should we do anything here with ticks? don't know, but conform others // JOHNS: called by callback HandleMouseExit(); callbacks.MouseExit(); }
/** * Entry point routine. * * There's no argument needed for registration but to uninstall, specify the * "-uninstall" parameter. * * This routine connects to the Google Desktop event publisher and establishes * an event subscription. The subscription can by filtered to only deliver * events that belong to a certain schema. To specify a schema, use the * "-s" flag, immediately followed by the schema name. * Example: * console_events -sEmail * * Repeating the -s flag is supported. */ int _tmain(int argc, TCHAR* argv[]) { ArgumentCheck args; if (!args.Check(argc, argv)) { args.PrintUsage(); return -1; } long cookie = 0; HRESULT hr; if (args.IsUninstall()) { hr = UnregisterFromGDEventFramework(); if (SUCCEEDED(hr)) return 0; } else { hr = EnsureRegistered(&cookie); } if (FAILED(hr)) { _tprintf(_T("Unable to %s with the Google Desktop event framework - 0x%08X\n%s\n"), args.IsUninstall() ? _T("unregister") : _T("register"), hr, GDErrorToString(hr)); return hr; } ATLASSERT(cookie != 0); // // Create an instance of the Google Desktop Event Publisher // and set up a subscription // CComPtr<IGoogleDesktopEventPublisher> publisher; hr = publisher.CoCreateInstance(L"GoogleDesktop.EventPublisher.1"); // Our callback object that will receive notifications EventCallback callback; // Our subscription that controls how events are delivered to us CComPtr<IGoogleDesktopEventSubscription> subscription; if (SUCCEEDED(hr)) { CComPtr<IUnknown> callback_identity; // Use ATL's special QI method to get the identity IUnknown pointer // of our callback object. hr = callback._LocDEQueryInterface(IID_IUnknown, reinterpret_cast<void**>(&callback_identity)); ATLASSERT(SUCCEEDED(hr) && "_LocDEQueryInterface"); // // Now connect our callback object to the GD Event Framework // by subscribing to events, then configure the subscription // and eventually, turn on the event stream. // hr = publisher->Subscribe(cookie, callback_identity, &subscription); if (SUCCEEDED(hr)) { if (argc > 1) { hr = args.SetUserSpecifiedSchemaFilters(subscription); } if (SUCCEEDED(hr)) { // This turns on the event stream hr = subscription->put_active(VARIANT_TRUE); } } } if (FAILED(hr)) { _tprintf(_T("An error occured while connecting to the Google Desktop event framework - 0x%08X\n%s\n"), hr, GDErrorToString(hr)); return hr; } _tprintf(_T("Event information will show up here. Press Ctrl+C to stop.\n")); hr = ReceiveEvents(); // Now turn off the subscription and unsubscribe ATLVERIFY(SUCCEEDED(subscription->put_active(VARIANT_FALSE))); ATLVERIFY(SUCCEEDED(publisher->Unsubscribe(subscription))); // Print out some information on our exit status if (FAILED(hr)) { _tprintf(_T("An error occured during processing of events - 0x%08X\n%s\n"), hr, GDErrorToString(hr)); } else { _tprintf(_T("Have a nice day!\n")); } return hr; }