void BPSEventListener::event(bps_event_t *event) {
    if (event != NULL) {
        if (bps_event_get_domain(event) == virtualkeyboard_get_domain()) {
            uint16_t code = bps_event_get_code(event);
            if (code == VIRTUALKEYBOARD_EVENT_VISIBLE) {
                int pixelsHeight = 0;
                virtualkeyboard_get_height(&pixelsHeight);
                if (pixelsHeight > _mPixelsHeightToConsiderKeyboardVisible) {
                    _isKeyboardVisible = true;
                    emit keyboardVisibilityUpdated();
                }
            } else if (code == VIRTUALKEYBOARD_EVENT_HIDDEN && _isKeyboardVisible) {
                _isKeyboardVisible = false;
                emit keyboardVisibilityUpdated();
            } else if (code == VIRTUALKEYBOARD_EVENT_INFO) {
                int pixelsHeight = 0;
                virtualkeyboard_get_height(&pixelsHeight);
                _isKeyboardVisible = pixelsHeight > _mPixelsHeightToConsiderKeyboardVisible;
                emit keyboardVisibilityUpdated();
            }
        } else if (bps_event_get_domain(event) == netstatus_get_domain()) {
            if (NETSTATUS_INFO == bps_event_get_code(event)) {
                netstatus_info_t *info = netstatus_event_get_info(event);
                if (info) {
                    bool networkReachable = netstatus_info_get_availability(info);
                    ms_message("[BB10] Network status event: network reachable: %i", networkReachable);

                    LinphoneManager *manager = LinphoneManager::getInstance();
                    linphone_core_set_network_reachable(manager->getLc(), networkReachable);
                }
            }
        }
    }
}
//! runs the device. Returns false if device wants to be deleted
bool CIrrDeviceBB10::run()
{
	os::Timer::tick();
	
	//TODO: translate native event
	SEvent irrevent;
	bps_event_t *event = NULL;
	while ( !Close &&(bps_get_event(&event, 0) ==BPS_SUCCESS))
	{

		if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
			&& (NAVIGATOR_EXIT == bps_event_get_code(event)))
		{
			Close =true;
			break;
		}

                if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                        && (NAVIGATOR_WINDOW_INACTIVE == bps_event_get_code(event)))
                {
			WindowHasFocus =false;
                        break;
                }
                if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                        && (NAVIGATOR_WINDOW_ACTIVE == bps_event_get_code(event)))
                {
			WindowHasFocus =true;
                        break;
                }

                if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                        && (NAVIGATOR_WINDOW_STATE == bps_event_get_code(event)))
                {
			if(navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_INVISIBLE)
				WindowHasFocus =false;
			else
				WindowHasFocus =true;
                        break;
                }
		
		//TODO: transfer bps event to irr event
		//postEventFromUser(irrevent);
		break;

	} // end while

	return !Close;
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: PamC/VSPlugin
static void handle_events() {
	int screen_domain = screen_get_domain();
	int navigator_domain = navigator_get_domain();
	int sensor_domain = sensor_get_domain();

	int rc;

	//Request and process available BPS events
	for(;;) {
		bps_event_t *event = NULL;
		rc = bps_get_event(&event, 0);
		assert(rc == BPS_SUCCESS);

		if (event) {
			int domain = bps_event_get_domain(event);

			if (domain == screen_domain) {
				handleScreenEvent(event);
			} else if (domain == navigator_domain) {
				handleNavigatorEvent(event);
			} else if (domain == sensor_domain) {
				handleSensorEvent(event);
			}
		} else {
			//No more events in the queue
			break;
		}
	}
}
Ejemplo n.º 4
0
static void qnx_input_poll(void *data)
{
   (void)data;
   //Request and process all available BPS events

   int rc, domain;

   g_extern.lifecycle_state &= ~(1ULL << RARCH_MENU_TOGGLE);

   while(true)
   {
      bps_event_t *event = NULL;
      rc = bps_get_event(&event, 0);
      if(rc == BPS_SUCCESS)
      {
         if (event)
         {
            domain = bps_event_get_domain(event);
            if (domain == navigator_get_domain())
               handle_navigator_event(event);
            else if (domain == screen_get_domain())
               handle_screen_event(event);
         }
         else
            break;
      }
   }
}
Ejemplo n.º 5
0
bool QQnxBpsEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(result);
    bps_event_t *event = static_cast<bps_event_t *>(message);
    const int eventDomain = bps_event_get_domain(event);
    qBpsEventFilterDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain;

    if (eventDomain == screen_get_domain()) {
        if (!m_screenEventHandler) {
            qWarning("QQNX: registered for screen events, but no handler provided.");
            return false;
        }

        screen_event_t screenEvent = screen_event_get_event(event);
        return m_screenEventHandler->handleEvent(screenEvent);
    }

    if (eventDomain == dialog_get_domain()) {
        dialog_instance_t nativeDialog = dialog_event_get_dialog_instance(event);
        QQnxFileDialogHelper *dialog = m_dialogMapper.value(nativeDialog, 0);
        if (dialog)
            return dialog->handleEvent(event);
    }

    if (eventDomain == navigator_get_domain())
        return handleNavigatorEvent(event);

    if (m_virtualKeyboard->handleEvent(event))
        return true;

    return false;
}
Ejemplo n.º 6
0
static void handleNavigatorEvent(bps_event_t *event) {
    switch (bps_event_get_code(event)) {
    case NAVIGATOR_ORIENTATION_CHECK:
        //Signal navigator that we intend to resize
        navigator_orientation_check_response(event, true);
        break;
    case NAVIGATOR_ORIENTATION:
        if (EXIT_FAILURE == resize(event)) {
            shutdown = true;
        }
        break;
    case NAVIGATOR_EXIT:
        shutdown = true;
        break;
    case NAVIGATOR_WINDOW_INACTIVE:
        //Wait for NAVIGATOR_WINDOW_ACTIVE event
        for (;;) {
            if (BPS_SUCCESS != bps_get_event(&event, -1)) {
                fprintf(stderr, "bps_get_event failed\n");
                break;
            }

            if (event && (bps_event_get_domain(event) == navigator_get_domain())) {
                int code = bps_event_get_code(event);
                if (code == NAVIGATOR_EXIT) {
                    shutdown = true;
                    break;
                } else if (code == NAVIGATOR_WINDOW_ACTIVE) {
                    break;
                }
            }
        }
        break;
    }
}
Ejemplo n.º 7
0
void handleEvent() {
	//Request and process BPS next available event
	int rc, domain;

	for (;;) {
		bps_event_t *event = NULL;
		rc = bps_get_event(&event, 0);
		assert(rc == BPS_SUCCESS);

		if (event) {

			int domain = bps_event_get_domain(event);

			if (domain == screen_get_domain()) {
				handleScreenEvent(event);

			} else if(domain == navigator_get_domain()) {
                handleNavigatorEvent(event);

			} else if (domain == dialog_get_domain()) {
                handle_dialog_response(event);
            }
		} else {
			break;
		}
	}

}
Ejemplo n.º 8
0
bool ScreenWindow::pollEvent(WinEvent *event)
{
	bps_event_t *bpsEvent;
	bps_get_event(&bpsEvent, 0);
	if (bpsEvent) {
		int domain = bps_event_get_domain(bpsEvent);
		if (domain == navigator_get_domain()) {
			if (bps_event_get_code(bpsEvent) == NAVIGATOR_EXIT) {
				event->type = QUIT;
				return true;
			}
		} else if (domain == screen_get_domain()) {
			screen_event_t se = screen_event_get_event(bpsEvent);
			int type;
			screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &type);
			if (type == SCREEN_EVENT_CLOSE) {
				event->type = QUIT;
				return true;
			} else if (type == SCREEN_EVENT_MTOUCH_TOUCH) {
				event->type = MOUSEBUTTONDOWN;
				return true;
			}
		}
	}
	return false;
}
Ejemplo n.º 9
0
static void handleEvents()
{
    int domain;

    // Get the first event in the queue.
    bps_event_t *event = NULL;
    if (BPS_SUCCESS != bps_get_event(&event, 0)) {
        fprintf(stderr, "bps_get_event() failed\n");
        return;
    }

    // Handle all events in the queue.
    // If we don't do this in a loop, we'll only handle one event per frame.
    // If many events are triggered quickly, e.g. by spinning the analog sticks,
    // the queue will grow and the user will see the analog sticks lag.
    while (event) {
        if (event) {
            domain = bps_event_get_domain(event);
            if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            } else if (domain == screen_get_domain()) {
                handleScreenEvent(event);
            }
        }

        if (BPS_SUCCESS != bps_get_event(&event, 0)) {
            fprintf(stderr, "bps_get_event() failed\n");
            return;
        }
    }
}
Ejemplo n.º 10
0
static void qnx_input_poll(void *data)
{
   global_t *global = global_get_ptr();
   qnx_input_t *qnx = (qnx_input_t*)data;

   global->lifecycle_state &= ~(1ULL << RARCH_MENU_TOGGLE);

   /* Request and process all available BPS events. */

   while(true)
   {
      bps_event_t *event = NULL;
      int rc = bps_get_event(&event, 0);

      if(rc == BPS_SUCCESS)
      {
         int domain;

         if (!event)
            break;

         domain = bps_event_get_domain(event);
         if (domain == navigator_get_domain())
            qnx_handle_navigator_event(qnx, event);
         else if (domain == screen_get_domain())
            qnx_handle_screen_event(qnx, event);
      }
   }
}
Ejemplo n.º 11
0
void Keyboard_NDK::event(bps_event_t *event) {
    Json::FastWriter writer;
    Json::Value root;
    root["threadCount"] = "10";
    int domain = bps_event_get_domain(event);
      if (domain == virtualkeyboard_get_domain()) {
          int code = bps_event_get_code(event);
          int a;
          std::string str;
          std::string eventString;
          std::ostringstream strs;
          switch(code) {
              case VIRTUALKEYBOARD_EVENT_VISIBLE:
                  eventString = "native.keyboardshow";
                  eventString.append(" ");
                  virtualkeyboard_get_height(&a) ;
                  strs << a;
                  str = strs.str();
                  eventString.append("{\"keyboardHeight\":\""+str+"\"}");
                  m_pParent->NotifyEvent(eventString);

                  break;
              case VIRTUALKEYBOARD_EVENT_HIDDEN:

                  m_pParent->NotifyEvent("native.keyboardhide");
                  break;
          }
      }

}
Ejemplo n.º 12
0
bool BbGuiHelper::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(result);
    Q_UNUSED(eventType);

    bps_event_t * const event = static_cast<bps_event_t *>(message);
    if (event && bps_event_get_domain(event) == navigator_get_domain()) {
        const int code = bps_event_get_code(event);
        if (code == NAVIGATOR_ORIENTATION) {
            const int newOrientation = navigator_event_get_orientation_angle(event);
            if (newOrientation != m_currentOrientation) {
                m_currentOrientation = newOrientation;
                emit orientationChanged();
            }
        } else if (code == NAVIGATOR_WINDOW_STATE) {
            const bool appActive =
                    (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN);
            if (m_applicationActive != appActive) {
                m_applicationActive = appActive;
                emit applicationActiveChanged();
            }
        }
    }

    return false;
}
Ejemplo n.º 13
0
static void qnx_input_poll(void *data)
{
   qnx_input_t *qnx = (qnx_input_t*)data;

   /* Request and process all available BPS events. */

   while(true)
   {
      bps_event_t *event = NULL;
      int rc = bps_get_event(&event, 0);

      if(rc == BPS_SUCCESS)
      {
         int domain;

         if (!event)
            break;

         domain = bps_event_get_domain(event);
         if (domain == navigator_get_domain())
            qnx_handle_navigator_event(qnx, event);
         else if (domain == screen_get_domain())
            qnx_handle_screen_event(qnx, event);
      }
   }
}
Ejemplo n.º 14
0
static bool s_eventFilter(void *message)
{
    bps_event_t * const event = static_cast<bps_event_t *>(message);

    if (event &&
        (bps_event_get_domain(event) == mmrenderer_get_domain() ||
         bps_event_get_domain(event) == screen_get_domain() )) {
        const int id = mmrenderer_event_get_userdata(event);
        BbMediaPlayerControl * const control = s_idToPlayerMap.value(id);
        if (control)
            control->bpsEventHandler(event);
    }

    if (s_previousEventFilter)
        return s_previousEventFilter(message);
    else
        return false;
}
Ejemplo n.º 15
0
void BbMediaPlayerControl::bpsEventHandler(bps_event_t *event)
{
    if (m_videoControl)
        m_videoControl->bpsEventHandler(event);

    if (bps_event_get_domain(event) != mmrenderer_get_domain())
        return;

    if (bps_event_get_code(event) == MMRENDERER_STATE_CHANGE) {
        const mmrenderer_state_t newState = mmrenderer_event_get_state(event);
        if (newState == MMR_STOPPED) {

            // Only react to stop events that happen when the end of the stream is reached and
            // playback is stopped because of this.
            // Ignore other stop event sources, souch as calling mmr_stop() ourselves and
            // mmr_input_attach().
            if (m_stopEventsToIgnore > 0) {
                --m_stopEventsToIgnore;
            } else {
                setMediaStatus(QMediaPlayer::EndOfMedia);
                stopInternal(IgnoreMmRenderer);
            }
            return;
        }
    }

    if (bps_event_get_code(event) == MMRENDERER_STATUS_UPDATE) {

        // Prevent spurious position change events from overriding our own position, for example
        // when setting the position to 0 in stop().
        if (m_state != QMediaPlayer::PlayingState ||
            m_mediaStatus == QMediaPlayer::LoadingMedia ||
            m_mediaStatus == QMediaPlayer::NoMedia ||
            m_mediaStatus == QMediaPlayer::InvalidMedia)
            return;

        const qint64 newPosition = QString::fromAscii(mmrenderer_event_get_position(event)).toLongLong();
        if (newPosition != 0 && newPosition != m_position) {
            m_position = newPosition;
            emit positionChanged(m_position);
        }

        const QString bufferStatus = QString::fromAscii(mmrenderer_event_get_bufferlevel(event));
        const int slashPos = bufferStatus.indexOf('/');
        if (slashPos != -1) {
            const int fill = bufferStatus.left(slashPos).toInt();
            const int capacity = bufferStatus.mid(slashPos + 1).toInt();
            if (capacity != 0) {
                m_bufferStatus = fill / static_cast<float>(capacity) * 100.0f;
                emit bufferStatusChanged(m_bufferStatus);
            }
        }
    }
}
bool QQnxVirtualKeyboardBps::handleEvent(bps_event_t *event)
{
    const int eventDomain = bps_event_get_domain(event);
    if (eventDomain == locale_get_domain())
        return handleLocaleEvent(event);

    if (eventDomain == virtualkeyboard_get_domain())
        return handleVirtualKeyboardEvent(event);

    return false;
}
void* eventLoop(void* data) {
	FREContext ctx = (FREContext) data;
	float x, y, z;
	bps_event_t *event = NULL;
	char buffer[256];

    // Initialize BPS
    bps_initialize();

	// Start the gyroscope
	if (sensor_request_events(SENSOR_TYPE_GYROSCOPE) != BPS_SUCCESS) {
		shutdown = true;
	}

	// Receive events through the event channel
	while (!shutdown) {
		event = NULL;

		if (bps_get_event(&event, 50) != BPS_SUCCESS)
			return NULL;

		if (event) {
			if (bps_event_get_domain(event) == sensor_get_domain()) {
				if (bps_event_get_code(event) == SENSOR_GYROSCOPE_READING) {
					if (sensor_event_get_xyz(event, &x, &y, &z) == BPS_SUCCESS) {
						sprintf(buffer, "%f&%f&%f", x, y, z);
						fprintf(stdout, "Sensor event: %f&%f&%f\n", x, y, z);
					    fflush(stdout);

						if(ctx != NULL) {
							FREDispatchStatusEventAsync(ctx, (uint8_t*)"CHANGE", (uint8_t*)buffer);
						}
					}
				}
			}
		}
	}

	if (sensor_stop_events(SENSOR_TYPE_GYROSCOPE) != BPS_SUCCESS) {
		fprintf(stdout, "Unable to stop sensor\n");
	    fflush(stdout);
	}

	// Stop BPS
	bps_shutdown();

	return NULL;
}
Ejemplo n.º 18
0
bool QBBEngine::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(result);

    bps_event_t * const event = static_cast<bps_event_t *>(message);

    Q_ASSERT(event);

    if (bps_event_get_domain(event) == netstatus_get_domain()) {
        qBearerDebug() << Q_FUNC_INFO << "got update request.";
        doRequestUpdate();
    }

    return false;
}
Ejemplo n.º 19
0
void LocatoinData::timerEvent(QTimerEvent *timerevent) {
  bps_event_t *event = NULL;
  bps_get_event(&event, -1);

  if (event) {
    if (bps_event_get_domain(event) == geolocation_get_domain()) {
      Q_EMIT sourceUpdated(d->geoLocationEvent(event));
    } else {
      qDebug() << Q_FUNC_INFO << "Not a Geo Info Event";
      geolocation_stop_events(0);
      this->startGeoTracking();
    }
  } else {
    qDebug() << Q_FUNC_INFO << "Event not ready";
  }
}
Ejemplo n.º 20
0
static void
handle_event()
{
    int rc, domain;

    bps_event_t *event = NULL;
    rc = bps_get_event(&event, -1);
    assert(rc == BPS_SUCCESS);
    if (event) {
        domain = bps_event_get_domain(event);
        if (domain == navigator_get_domain()) {
            handle_navigator_event(event);
        } else if (domain == screen_get_domain()) {
            handle_screen_event(event);
        }
    }
}
Ejemplo n.º 21
0
static void gfx_ctx_check_window(bool *quit,
      bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
   (void)frame_count;
   //Request and process all available BPS events
   bps_event_t *event = NULL;

   bps_get_event(&event, 0);

   *quit = false;

   unsigned new_width, new_height;
   gfx_ctx_get_video_size(&new_width, &new_height);
   if (new_width != *width || new_height != *height)
   {
      *width  = new_width;
      *height = new_height;
      *resize = true;
   }

   if (event)
   {
      int domain = bps_event_get_domain(event);

      if (domain == screen_get_domain())
      {
         screen_event_t screen_event = screen_event_get_event(event);
         int screen_val;
         screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);
         switch (screen_val) {

            case SCREEN_EVENT_MTOUCH_TOUCH:
            case SCREEN_EVENT_MTOUCH_MOVE:
            case SCREEN_EVENT_MTOUCH_RELEASE:

               break;
         }
      }
      else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event)))
         g_extern.lifecycle_state |= (1ULL << RARCH_QUIT_KEY);
   }

   // Check if we are exiting.
   if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY))
      *quit = true;
}
Ejemplo n.º 22
0
bool myEventFilter(void *message) {
	// here we should have all requested bps events (no Qt events here)
    bps_event_t *event = (bps_event_t*)message;
    if (event) {
    	int domain = bps_event_get_domain(event);
    	if (domain == virtualkeyboard_get_domain()) {
    		unsigned int ec = bps_event_get_code(event);
    		 if (!bKBhidden && ec == VIRTUALKEYBOARD_EVENT_INFO){
    			int nNewKBHeight = virtualkeyboard_event_get_height(event);
    			virtualkeyboard_get_height(&nNewKBHeight);
    			if ( nNewKBHeight != nKBHeight){
    				nKBHeight = nNewKBHeight;
    				QRect r = QApplication::desktop()->screenGeometry(0);
    				if (r.width() > 800){
    					// Landscape
    					console->setGeometry(0, 0, r.width()-73, r.height()-nKBHeight);
    				}else{
    					// Portrait - keyboard is taller
    					console->setGeometry(0, 53, r.width(), r.height()-nKBHeight-53);
    				}
    			}
    		}
    		QRect r = QApplication::desktop()->screenGeometry(0);
    		if (ec == VIRTUALKEYBOARD_EVENT_VISIBLE){
				bKBhidden = false;
				nKBHeight = nMaxKBHeight;
				virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_DEFAULT, VIRTUALKEYBOARD_ENTER_DEFAULT);
    		}else if (ec == VIRTUALKEYBOARD_EVENT_HIDDEN){
				bKBhidden = true;
				nKBHeight = 0;
    		}
			if (r.width() > 800) console->setGeometry(0, 0, r.width()-73, r.height()-nKBHeight); // Landscape
			else console->setGeometry(0, 103, r.width(), r.height()-nKBHeight-103); // Portrait

			//font = QFont(QString("Courier New"), 6);
			font.setPixelSize(mainWindow->nFontSize);
		    font.setStyle(QFont::StyleNormal);
		    font.setWeight(QFont::Normal);
			console->setTerminalFont(font);
    	}
   	}
 	mainEventFilter(message); // Call replaced event filter so we deliever everything to Qt that runs in background
	return false;
}
Ejemplo n.º 23
0
bool PaymentService::handle_event(bps_event_t *p_event) {

	if (bps_event_get_domain(p_event) != paymentservice_get_domain()) {
		return false;
	};

	Dictionary dict;
	int res = paymentservice_event_get_response_code(p_event);
	if (res == SUCCESS_RESPONSE) {
		dict["result"] = "ok";

		res = bps_event_get_code(p_event);
		if (res == PURCHASE_RESPONSE) {
			dict["type"] = "purchase";
			const char *pid = paymentservice_event_get_digital_good_id(p_event, 0);
			dict["product_id"] = String(pid ? pid : "");
		};

	} else {
		const char *desc = paymentservice_event_get_error_text(p_event);
		if (strcmp(desc, "alreadyPurchased") == 0) {
			dict["result"] = "ok";
		} else {
			dict["result"] = "error";
			dict["error_description"] = paymentservice_event_get_error_text(p_event);
			dict["error_code"] = paymentservice_event_get_error_id(p_event);
			printf("error code is %i\n", paymentservice_event_get_error_id(p_event));
			printf("error description is %s\n", paymentservice_event_get_error_text(p_event));
		};
		dict["product_id"] = "";
	};

	res = bps_event_get_code(p_event);
	if (res == PURCHASE_RESPONSE) {
		dict["type"] = "purchase";
	};

	printf("********** adding event with result %ls\n", String(dict["result"]).c_str());
	pending_events.push_back(dict);

	return true;
};
Ejemplo n.º 24
0
void BbGuiHelper::handleBpsEvent(bps_event_t *event)
{
    if (event && bps_event_get_domain(event) == navigator_get_domain()) {
        const int code = bps_event_get_code(event);
        if (code == NAVIGATOR_ORIENTATION) {
            const int newOrientation = navigator_event_get_orientation_angle(event);
            if (newOrientation != m_currentOrientation) {
                m_currentOrientation = newOrientation;
                emit orientationChanged();
            }
        } else if (code == NAVIGATOR_WINDOW_STATE) {
            const bool appActive =
                    (navigator_event_get_window_state(event) == NAVIGATOR_WINDOW_FULLSCREEN);
            if (m_applicationActive != appActive) {
                m_applicationActive = appActive;
                emit applicationActiveChanged();
            }
        }
    }
}
Ejemplo n.º 25
0
static void handle_events() {
    //Request and process available BPS events
    for(;;) {
        bps_event_t *event = NULL;
        if (BPS_SUCCESS != bps_get_event(&event, 0)) {
            fprintf(stderr, "bps_get_event failed\n");
            break;
        }

        if (event) {
            int domain = bps_event_get_domain(event);

            if (domain == screen_get_domain()) {
                handleScreenEvent(event);
            } else if (domain == navigator_get_domain()) {
                handleNavigatorEvent(event);
            }
        } else {
            break;
        }
    }
}
Ejemplo n.º 26
0
void BbVideoWindowControl::bpsEventHandler(bps_event_t *event)
{
    if (event && bps_event_get_domain(event) == screen_get_domain()) {
        const screen_event_t screen_event = screen_event_get_event(event);

        int eventType;
        if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
            perror("BbVideoWindowControl: Failed to query screen event type");
            return;
        }

        if (eventType != SCREEN_EVENT_CREATE)
            return;

        screen_window_t window = 0;
        if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
            perror("BbVideoWindowControl: Failed to query window property");
            return;
        }

        const int maxIdStrLength = 128;
        char idString[maxIdStrLength];
        if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
            perror("BbVideoWindowControl: Failed to query window ID string");
            return;
        }

        if (m_windowName == idString) {
            m_window = window;
            updateVideoPosition();

            const int visibleFlag = 1;
            if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &visibleFlag) != 0) {
                perror("BbVideoWindowControl: Failed to make window visible");
                return;
            }
        }
    }
}
Ejemplo n.º 27
0
bool WindowGrabber::nativeEventFilter(const QByteArray&, void *message, long*)
{
    bps_event_t * const event = static_cast<bps_event_t *>(message);

    if (event && bps_event_get_domain(event) == screen_get_domain()) {
        const screen_event_t screen_event = screen_event_get_event(event);

        int eventType;
        if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
            qWarning() << "WindowGrabber: Failed to query screen event type";
            return false;
        }

        if (eventType != SCREEN_EVENT_CREATE)
            return false;

        screen_window_t window = 0;
        if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
            qWarning() << "WindowGrabber: Failed to query window property";
            return false;
        }

        const int maxIdStrLength = 128;
        char idString[maxIdStrLength];
        if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
            qWarning() << "WindowGrabber: Failed to query window ID string";
            return false;
        }

        if (m_windowId == idString) {
            m_window = window;
            start();
        }
    }

    return false;
}
Ejemplo n.º 28
0
/**
 * The main entry point.
 */
int
main(int argc, char *argv[])
{
    pthread_t accel_thread;

    bool exit_application = false;
    int rc;

    /*
     * Before we can listen for events from the BlackBerry Tablet OS platform
     * services, we need to initialize the BPS infrastructure
     */
    bps_initialize();

    /*
     * Initialize the screen so that the window group Id is properly set,
     * to allow the dialogs to be displayed.
     */
    if (setup_screen() != EXIT_SUCCESS) {
        fprintf(stderr, "Unable to initialize screen.");
        exit(-1);
    }

    /*
     * Once the BPS infrastructure has been initialized we can register for
     * events from the various BlackBerry Tablet OS platform services. The
     * Navigator service manages and delivers application life cycle and
     * visibility events.
     *
     * We register a custom event domain so that we can communicate with the
     * the accelerometer thread.  We will need to tell it to quit once we get
     * the NAVIGATOR_EXIT.
     *
     * We request Navigator events so that we can track when the system is
     * terminating the application (NAVIGATOR_EXIT event).
     *
     */
    local_event_domain = bps_register_domain();
    if (local_event_domain == -1) {
        fprintf(stderr, "Error registering custom event domain: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "Error requesting navigator events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != dialog_request_events(0)) {
        fprintf(stderr, "Error requesting dialog events: %s", strerror(errno));
        exit(-1);
    }
    if (BPS_SUCCESS != geolocation_request_events(0)) {
        fprintf(stderr, "Error requesting geolocation events: %s", strerror(errno));
        exit(-1);
    }

    geolocation_set_period(1);

    /*
     * Create and display the dialogs that will show the data.
     */
    create_top_dialog();
    show_top_dialog_message("Geolocation getting first fix");

    /*
     * Before initializing the accelerometer service we must ensure the device
     * supports it.
     */
    if (!sensor_is_supported(SENSOR_TYPE_ACCELEROMETER)) {
        /**
         * If the device does not support accelerometer then notify the user,
         * clean up and exit
         */
        snprintf(msg, MSG_SIZE, "Accelerometer not supported by device!");
        show_top_dialog_message(msg);

        /*
         * Destroy the dialog, if it exists and cleanup screen resources.
         */
        destroy_top_dialog();
        cleanup_screen();
        bps_shutdown();
        return EXIT_FAILURE;
    }

    /*
     * Create the accelerometer event thread.
     */
    rc = pthread_create(&accel_thread, NULL, accel_main, NULL);
    if (rc != 0) {
        fprintf(stderr, "Error in pthread_create: %s", strerror(errno));
        exit(-1);
    }

    while (!exit_application) {
        /*
         * Using a negative timeout (-1) in the call to bps_get_event(...)
         * ensures that we don't busy wait by blocking until an event is
         * available.
         */
        bps_event_t *event = NULL;
        bps_get_event(&event, -1);

        if (event) {
            if (bps_event_get_domain(event) == geolocation_get_domain()) {
                handle_geolocation_response(event);
            }
            else if (bps_event_get_domain(event) == navigator_get_domain()) {
                exit_application = handle_navigator_event(event);
            }
        }
    }

    geolocation_stop_events(0);

    /*
     * Avoid a possible race condition where accel_chid has not yet
     * been assigned a valid channel ID.
     */
    pthread_mutex_lock(&chidMutex);
    while (accel_chid == -1) {
        pthread_cond_wait(&chidCond, &chidMutex);
    }
    pthread_mutex_unlock(&chidMutex);

    bps_event_t *stop_request_event = NULL;

    if (BPS_SUCCESS != bps_event_create(&stop_request_event, local_event_domain, STOP_REQUEST, NULL, NULL)) {
        fprintf(stderr, "Unable to create event: %s", strerror(errno));
        exit(-1);
    }

    if (BPS_SUCCESS != bps_channel_push_event(accel_chid, stop_request_event)) {
        fprintf(stderr, "Unable to push event: %s", strerror(errno));
    }

    pthread_join(accel_thread, NULL);

    /*
     * Destroy the dialog, if it exists.
     */
    destroy_top_dialog();

    bps_shutdown();
    cleanup_screen();

    return 0;
}
Ejemplo n.º 29
0
/**
 * Thread that handles accelerometer events and
 * sends relevant information to a dialog.
 *
 * @param p Unused.
 */
static void *
accel_main (void *p) {
    bool run = true;
    bps_event_t *event;
    float force_x, force_y, force_z;

    bps_initialize();

    /*
     * Each thread that calls bps_initialize() will have its
     * own unique channel ID.  Protect it inside a mutex and
     * condition variable to avoid race condition where main
     * thread tries to use it before we assign it.
     */
    pthread_mutex_lock(&chidMutex);
    accel_chid = bps_channel_get_active();
    pthread_cond_signal(&chidCond);
    pthread_mutex_unlock(&chidMutex);

    /*
     * Create and display a dialog that will show the data.
     */
    create_bottom_dialog();
    show_bottom_dialog_message("\n\nThis is the Accelerometer Dialog");

    if (BPS_SUCCESS != sensor_request_events(SENSOR_TYPE_ACCELEROMETER)) {
        fprintf(stderr, "Error requesting sensor's accelerometer events: %s", strerror(errno));
        bps_shutdown();
        return NULL;
    }

    sensor_set_rate(SENSOR_TYPE_ACCELEROMETER, ACCELEROMETER_RATE);
    sensor_set_skip_duplicates(SENSOR_TYPE_ACCELEROMETER, true);

    while (run) {
        /*
         * Block, at the very least we'll get the "STOP" event
         */
        bps_get_event(&event, -1);
        if (bps_event_get_domain(event) == local_event_domain) {
            if (bps_event_get_code(event) == STOP_REQUEST) {
                run = false;
            }
        }

        if (bps_event_get_domain(event) == sensor_get_domain()) {
            if (SENSOR_ACCELEROMETER_READING == bps_event_get_code(event)) {
                sensor_event_get_xyz(event, &force_x, &force_y, &force_z);
                display_accelerometer_reading(force_x, force_y, force_z);
            }
        }
    }

    sensor_stop_events(0);
    destroy_bottom_dialog();

    bps_shutdown();

    fprintf(stderr, "Exiting accelerometer thread\n");
    return NULL;


}
Ejemplo n.º 30
0
int main(int argc, char *argv[])
{
    int rc;
    int exit_application = 0;

    // Screen variables
    screen_context_t    screen_context = 0;
    screen_window_t     screen_window = 0;

    int screen_size[2] = {0,0};

    // Renderer variables
    mmr_connection_t*     mmr_connection = 0;
    mmr_context_t*        mmr_context = 0;
    strm_dict_t*          dict = NULL;

    // I/O variables
    int                    video_device_output_id = -1;
    int                    audio_device_output_id = -1;

    bps_initialize();

    /*
     * Create the window used for video output.
     */
    if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) {
        return EXIT_FAILURE;
    }

    if (screen_create_window(&screen_window, screen_context) != 0) {
        screen_destroy_context(screen_context);
        return EXIT_FAILURE;
    }

    if (screen_create_window_group(screen_window, window_group_name) != 0) {
        return EXIT_FAILURE;
    }

    int format = SCREEN_FORMAT_RGBA8888;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) {
        return EXIT_FAILURE;
    }

    int usage = SCREEN_USAGE_NATIVE;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) {
        return EXIT_FAILURE;
    }


    if (screen_create_window_buffers(screen_window, 1) != 0) {
        return EXIT_FAILURE;
    }

    /*
     * Configure mm-renderer.
     */
    mmr_connection = mmr_connect(NULL);
    if (mmr_connection == NULL) {
        return EXIT_FAILURE;
    }

    mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
    if (mmr_context == NULL) {
        return EXIT_FAILURE;
    }

    /*
     * Configure video and audio output.
     */
    video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
    if (video_device_output_id == -1) {
        return EXIT_FAILURE;
    }

    audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
    if (audio_device_output_id == -1) {
        return EXIT_FAILURE;
    }

    // Get the render buffer
    screen_buffer_t temp_buffer[1];
    if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) {
        return EXIT_FAILURE;
    }

    // Fill the buffer with a solid color (black)
    int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x0, SCREEN_BLIT_END};
    if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) {
        return EXIT_FAILURE;
    }

    // Make the window visible
    if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) {
        return EXIT_FAILURE;
    }

    int temp_rectangle[4] = {0, 0, screen_size[0], screen_size[1]};
    if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) {
        return EXIT_FAILURE;
    }

    // Prevent the backlight from going off
    int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) {
        return EXIT_FAILURE;
    }

    // Build up the path where our bundled resource is.
    char cwd[PATH_MAX];
    char media_file[PATH_MAX];
    getcwd(cwd,PATH_MAX);

    rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/pb_sample.mp4", cwd);
    if ((rc == -1) || (rc >= PATH_MAX)) {
        return EXIT_FAILURE;
    }

    /*
     * Start the playback.
     */
    if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_play(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    /* Do some work to make the aspect ratio correct.
     */
    dict = calculate_rect(screen_size[0], screen_size[1]);
    if (NULL == dict) {
        return EXIT_FAILURE;
    }

    if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
        return EXIT_FAILURE;
    }

     /* Note that we allocated memory for the dictionary, but the call to 
      * mmr_output_parameters() deallocates that memory even on failure.
      */  
    dict = NULL;

    screen_request_events(screen_context);
    navigator_request_events(0);

    /*
     * Handle keyboard events and stop playback upon user request.
     */
    for (;;) {
        bps_event_t *event = NULL;
        if (bps_get_event(&event, -1) != BPS_SUCCESS) {
            return EXIT_FAILURE;
        }

        if (event) {

            if (bps_event_get_domain(event) == navigator_get_domain() &&
                bps_event_get_code(event) == NAVIGATOR_EXIT) {

                exit_application = 1;
            }

            if (exit_application) {
                break;
            }
        }
    }

    screen_stop_events(screen_context);

    if (mmr_stop(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_context_destroy(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    mmr_context = 0;
    video_device_output_id = -1;
    audio_device_output_id = -1;

    mmr_disconnect(mmr_connection);
    mmr_connection = 0;

    bps_shutdown();

    if (screen_destroy_window(screen_window) != 0) {
        return EXIT_FAILURE;
    }

    if (screen_destroy_context(screen_context) != 0) {
        return EXIT_FAILURE;
    }

    screen_context = 0;
    screen_window = 0;

    return EXIT_SUCCESS;
}