Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
headless apps update with cleanup,bug fixes, etc
  • Loading branch information
Adam Sosnowski committed Oct 18, 2013
1 parent d748ec5 commit c346375
Show file tree
Hide file tree
Showing 24 changed files with 779 additions and 591 deletions.
102 changes: 102 additions & 0 deletions headlesservice/bar-descriptor.xml
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!--
Copyright (c) 2011, 2012, 2013 Research In Motion Limited.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<qnx xmlns="http://www.qnx.com/schemas/application/1.0">

<!-- BlackBerry 10 application descriptor file.
Specifies parameters for identifying, installing, and launching native applications on BlackBerry 10.
-->

<!-- A universally unique application identifier. Must be unique across all BlackBerry 10 applications.
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
<id>com.example.headlesservice</id>

<!-- The name that is displayed in the BlackBerry 10 application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
<name>headlesservice</name>

<!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade.
Values can also be 1-part or 2-part. It is not necessary to have a 3-part value.
An updated version of application must have a versionNumber value higher than the previous version. Required. -->
<versionNumber>1.0.0</versionNumber>

<!-- Fourth digit segment of the package version. First three segments are taken from the
<versionNumber> element. Must be an integer from 0 to 2^16-1 -->
<buildId>1</buildId>

<!-- A string value (such as "v1", "2.5", or "Alpha 1") that represents the version of the application, as it should be shown to users. Optional. -->
<!-- <versionLabel></versionLabel> -->

<!-- Description, displayed in the BlackBerry 10 application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->
<description>The headlesservice application</description>

<!-- Copyright information. Optional. -->
<!-- <copyright></copyright> -->

<!-- Name of author which is used for signing. Must match the developer name of your development certificate. -->
<author>Example Inc.</author>

<!-- Unique author ID assigned by signing authority. Required if using debug tokens. -->
<!-- <authorId>ABC1234YjsnUk235h</authorId> -->

<initialWindow>
<autoOrients>true</autoOrients>
<systemChrome>none</systemChrome>
<transparent>false</transparent>
</initialWindow>

<!-- The category where the application appears. Either core.games or core.media. -->
<configuration name="Device-Debug">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="arm/o.le-v7-g/headlesservice" entry="true" type="Qnx/Elf">headlesservice</asset>
</configuration>
<configuration name="Device-Release">
<entryPointType>Qnx/Cascades</entryPointType>
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="arm/o.le-v7/headlesservice.so" entry="true" type="Qnx/Elf">headlesservice.so</asset>
</configuration>
<configuration name="Device-Profile">
<platformArchitecture>armle-v7</platformArchitecture>
<asset path="arm-p/o.le-v7-g/headlesservice" entry="true" type="Qnx/Elf">headlesservice</asset>
</configuration>
<configuration name="Simulator-Debug">
<platformArchitecture>x86</platformArchitecture>
<asset path="x86/o-g/headlesservice" entry="true" type="Qnx/Elf">headlesservice</asset>
</configuration>

<!-- The icon for the application, which should be 114x114. -->
<icon>
<image>icon.png</image>
</icon>

<asset path="icon.png">icon.png</asset>
<asset path="assets">assets</asset>

<!-- Locale support -->
<asset path="translations" dest="qm">
<include name="*.qm"/>
</asset>

<!-- Request permission to execute native code. Required for native applications. -->
<permission system="true">run_native</permission>
<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>

</qnx>
12 changes: 9 additions & 3 deletions headlesservice/config.pri
Expand Up @@ -16,9 +16,11 @@ device {
-lbbsystem

SOURCES += $$quote($$BASEDIR/src/applicationheadless.cpp) \
$$quote($$BASEDIR/src/applicationui.cpp) \
$$quote($$BASEDIR/src/main.cpp)

HEADERS += $$quote($$BASEDIR/src/applicationheadless.hpp)
HEADERS += $$quote($$BASEDIR/src/applicationheadless.hpp) \
$$quote($$BASEDIR/src/applicationui.hpp)
}

CONFIG(release, debug|release) {
Expand All @@ -35,9 +37,11 @@ device {
-lbbsystem

SOURCES += $$quote($$BASEDIR/src/applicationheadless.cpp) \
$$quote($$BASEDIR/src/applicationui.cpp) \
$$quote($$BASEDIR/src/main.cpp)

HEADERS += $$quote($$BASEDIR/src/applicationheadless.hpp)
HEADERS += $$quote($$BASEDIR/src/applicationheadless.hpp) \
$$quote($$BASEDIR/src/applicationui.hpp)
}
}

Expand All @@ -56,9 +60,11 @@ simulator {
-lbbsystem

SOURCES += $$quote($$BASEDIR/src/applicationheadless.cpp) \
$$quote($$BASEDIR/src/applicationui.cpp) \
$$quote($$BASEDIR/src/main.cpp)

HEADERS += $$quote($$BASEDIR/src/applicationheadless.hpp)
HEADERS += $$quote($$BASEDIR/src/applicationheadless.hpp) \
$$quote($$BASEDIR/src/applicationui.hpp)
}
}

Expand Down
133 changes: 77 additions & 56 deletions headlesservice/src/applicationheadless.cpp
Expand Up @@ -36,83 +36,104 @@ using namespace bb::device;
using namespace bb::system;

//! [1]
ApplicationHeadless::ApplicationHeadless(bb::Application *app) :
QObject(app), m_invokeManager(new InvokeManager(this)), m_led(0), m_flashCount(20) {
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
// log the service PID
qDebug() << "PID------------" << QString::number(QCoreApplication::applicationPid());
ApplicationHeadless::ApplicationHeadless(bb::Application *app)
: QObject(app)
, m_invokeManager(new InvokeManager(this))
, m_led(0)
, m_flashCount(20)
, m_settingsWatcher(new QFileSystemWatcher(this))
{
QMetaObject::invokeMethod(this, "init", Qt::QueuedConnection);
// log the service PID
qDebug() << "PID------------" << QString::number(QCoreApplication::applicationPid());
}
//! [1]
//! [3]
void ApplicationHeadless::onInvoked(const bb::system::InvokeRequest& request) {
qDebug() << "##service got invoked: " << request.action();
void ApplicationHeadless::onInvoked(const bb::system::InvokeRequest& request)
{
qDebug() << "##service got invoked: " << request.action();

// start led flashing once the start request is received
if (request.action().compare("bb.action.system.STARTED") == 0) {
m_led->flash(m_flashCount);
} else {
// write service running status to qsettings
QSettings settings(m_author, m_appName);
settings.setValue(m_serviceStatus, request.action());
}
// start led flashing once the start request is received
if (request.action().compare("bb.action.system.STARTED") == 0) {
m_led->flash(m_flashCount);
} else {
// write service running status to qsettings
QSettings settings(m_author, m_appName);
settings.setValue(m_serviceStatus, request.action());
}
}
//! [3]
//! [4]
void ApplicationHeadless::flashCountChanged(int x) {
qDebug() << "---------" + QString::number(x);
QSettings settings(m_author, m_appName);
settings.setValue(m_remainingCount, x);
void ApplicationHeadless::flashCountChanged(int x)
{
qDebug() << "---------" + QString::number(x);
QSettings settings(m_author, m_appName);
settings.setValue(m_remainingCount, x);
}

void ApplicationHeadless::activeUpdate(bool active) {
QSettings settings(m_author, m_appName);
settings.value(m_ledActive, active);
void ApplicationHeadless::activeUpdate(bool active)
{
qDebug() << "---active: " << active;
QSettings settings(m_author, m_appName);
settings.value(m_ledActive, active);
if(!active) {
QSettings settings(m_author, m_appName);
settings.setValue(m_remainingCount, m_led->remainingFlashCount());
}
}
//! [4]

void ApplicationHeadless::settingsChanged(const QString & path) {
QSettings settings(m_author, m_appName);
if (settings.value(m_reset).toBool()) {
settings.setValue(m_reset, false);
settings.setValue(m_flashNumber, m_flashCount);
settings.setValue(m_remainingCount, m_flashCount);
m_led->cancel();
delete m_led;
m_led = new Led(LedColor::Blue);
connect(m_led, SIGNAL(remainingFlashCountChanged(int)), this, SLOT(flashCountChanged(int)));
m_led->flash(m_flashCount);
}
void ApplicationHeadless::settingsChanged(const QString & path)
{
QSettings settings(m_author, m_appName);
if (settings.value(m_reset).toBool()) {
settings.setValue(m_reset, false);
settings.setValue(m_flashNumber, m_flashCount);
settings.setValue(m_remainingCount, m_flashCount);
settings.value(m_ledActive, false);
m_led->cancel();
disconnect(m_led, SIGNAL(remainingFlashCountChanged(int)), this, SLOT(flashCountChanged(int)));
disconnect(m_led, SIGNAL(activeChanged(bool)), this, SLOT(activeUpdate(bool)));
delete m_led;
m_led = new Led(LedColor::Blue, this);
bool ok = connect(m_led, SIGNAL(remainingFlashCountChanged(int)), this, SLOT(flashCountChanged(int)));
Q_ASSERT(ok);
ok = connect(m_led, SIGNAL(activeChanged(bool)), this, SLOT(activeUpdate(bool)));
Q_ASSERT(ok);
Q_UNUSED(ok);
m_led->flash(m_flashCount);
}
}

//! [2]
void ApplicationHeadless::init() {
m_led = new Led(LedColor::Blue, this);
void ApplicationHeadless::init()
{
m_led = new Led(LedColor::Blue, this);

// set the initial qsettings keys/values upon startup
QSettings settings(m_author, m_appName);
// set the initial qsettings keys/values upon startup
QSettings settings(m_author, m_appName);

settings.setValue(m_serviceStatus, "running");
settings.setValue(m_flashNumber, m_flashCount);
settings.setValue(m_remainingCount, m_flashCount);
// Force the creation of the settings file so that we can watch it for changes.
settings.sync();
settings.setValue(m_serviceStatus, "running");
settings.setValue(m_flashNumber, m_flashCount);
settings.setValue(m_remainingCount, m_flashCount);
// Force the creation of the settings file so that we can watch it for changes.
settings.sync();

// Watcher for changes in the settings file.
settingsWatcher = new QFileSystemWatcher(this);
settingsWatcher->addPath(settings.fileName());
// Watcher for changes in the settings file.
m_settingsWatcher->addPath(settings.fileName());

// Do all the necessary signal/slot connections to be invokable to receive led updates.
bool ok = connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)), this, SLOT(onInvoked(const bb::system::InvokeRequest&)));
Q_ASSERT(ok);
// Do all the necessary signal/slot connections to be invokable to receive led updates.
bool ok = connect(m_invokeManager, SIGNAL(invoked(const bb::system::InvokeRequest&)), this, SLOT(onInvoked(const bb::system::InvokeRequest&)));
Q_ASSERT (ok);

ok = connect(m_led, SIGNAL(remainingFlashCountChanged(int)), this, SLOT(flashCountChanged(int)));
Q_ASSERT(ok);
ok = connect(m_led, SIGNAL(remainingFlashCountChanged(int)), this, SLOT(flashCountChanged(int)));
Q_ASSERT(ok);

ok = connect(m_led, SIGNAL(activeChanged(bool)), this, SLOT(activeUpdate(bool)));
Q_ASSERT(ok);
ok = connect(m_led, SIGNAL(activeChanged(bool)), this, SLOT(activeUpdate(bool)));
Q_ASSERT(ok);

ok = connect(settingsWatcher, SIGNAL(fileChanged(const QString&)), this, SLOT(settingsChanged(const QString&)));
Q_ASSERT(ok);
Q_UNUSED(ok);
ok = connect(m_settingsWatcher, SIGNAL(fileChanged(const QString&)), this, SLOT(settingsChanged(const QString&)));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
//! [2]

0 comments on commit c346375

Please sign in to comment.