Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] Implement luna-service integration
Used by LuneOS, made optional so shouldn't have any influence on Mer code. Signed-off-by: Nikolay Nizov <nizovn@gmail.com> Signed-off-by: Herman van Hazendonk <github.com@herrie.org> Fixups based on feedback Final fix based on comments & review Another cleanup
- Loading branch information
Showing
10 changed files
with
398 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"role": { | ||
"exeName":"/usr/sbin/sensorfwd", | ||
"type": "privileged", | ||
"allowedNames": ["com.nokia.SensorService"] | ||
}, | ||
"permissions": [ | ||
{ | ||
"service":"com.nokia.SensorService", | ||
"inbound":["*"], | ||
"outbound":["*"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[D-BUS Service] | ||
Name=com.nokia.SensorService | ||
Exec=/usr/sbin/sensrofwd | ||
Type=static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=Sensor daemon for sensor framework | ||
After=dbus.socket ls-hubd_private.service | ||
Requires=dbus.service ls-hubd_private.service | ||
Conflicts=actdead.target | ||
|
||
[Service] | ||
Type=forking | ||
BusName=com.nokia.SensorService | ||
ExecStartPre=/bin/sh /usr/bin/sensord-daemon-conf-setup | ||
ExecStart=/usr/sbin/sensorfwd -c=/etc/sensorfw/primaryuse.conf -d --log-level=warning --no-magnetometer-bg-calibration | ||
ExecReload=/bin/kill -HUP $MAINPID | ||
Restart=always | ||
RestartSec=1 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/** | ||
@file lsclient.cpp | ||
@brief LunaService signal utility | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
Copyright (C) 2015-2018 Nikolay Nizov | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
@author Lihan Guo <ext-lihan.4.guo@nokia.com> | ||
@author Nikolay Nizov <nizovn@gmail.com> | ||
This file is part of Sensord. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#include "lsclient.h" | ||
#include "JSONUtils.h" | ||
#include "HostBase.h" | ||
#include <json.h> | ||
|
||
#define URI_SIGNAL_ADDMATCH "palm://com.palm.lunabus/signal/addmatch" | ||
#define JSON_CHARGER_SIGNAL_ADDMATCH "{\"category\":\"/com/palm/power\",\"method\":\"chargerStatus\"}" | ||
#define URI_DISPLAY_STATUS "palm://com.palm.display/control/status" | ||
#define JSON_DISPLAY_SUBSCRIBE "{\"subscribe\":true}" | ||
|
||
LSClient::LSClient(QObject* parent) : QObject(parent), | ||
displayState(true), | ||
powerSave(true) | ||
{ | ||
bool retVal; | ||
LSError lserror; | ||
LSErrorInit(&lserror); | ||
LSHandle *serviceHandle; | ||
|
||
retVal = LSRegister("com.nokia.SensorService", &serviceHandle, &lserror); | ||
if (!retVal) { | ||
goto error; | ||
} | ||
|
||
retVal = LSCall(serviceHandle, URI_SIGNAL_ADDMATCH, JSON_CHARGER_SIGNAL_ADDMATCH, LSClient::chargerCallback, this, NULL, &lserror); | ||
if (!retVal) { | ||
goto error; | ||
} | ||
|
||
retVal = LSCall(serviceHandle, URI_DISPLAY_STATUS, JSON_DISPLAY_SUBSCRIBE, LSClient::displayCallback, this, NULL, &lserror); | ||
if (!retVal) { | ||
goto error; | ||
} | ||
|
||
retVal = LSGmainAttach(serviceHandle, HostBase::instance()->mainLoop(), &lserror); | ||
if (!retVal) { | ||
goto error; | ||
} | ||
|
||
return; | ||
|
||
error: | ||
if (LSErrorIsSet(&lserror)) { | ||
LSErrorPrint(&lserror, stderr); | ||
LSErrorFree(&lserror); | ||
} | ||
|
||
qDebug() << "Unable to start service."; | ||
} | ||
|
||
bool LSClient::displayEnabled() const | ||
{ | ||
return displayState; | ||
} | ||
|
||
bool LSClient::PSMEnabled() const | ||
{ | ||
return powerSave; | ||
} | ||
|
||
bool LSClient::chargerCallback(LSHandle *sh, LSMessage *message, void *ctx) | ||
{ | ||
LSError lserror; | ||
LSErrorInit(&lserror); | ||
|
||
// {"type": string, "connected": boolean} | ||
VALIDATE_SCHEMA_AND_RETURN(sh, | ||
message, | ||
SCHEMA_2(REQUIRED(type, string), REQUIRED(connected, boolean))); | ||
|
||
LSClient* lsclient = (LSClient*)ctx; | ||
|
||
json_object* label = 0; | ||
json_object* root = 0; | ||
bool newState = true; | ||
const char* str = LSMessageGetPayload(message); | ||
if (!str) | ||
goto error; | ||
|
||
root = json_tokener_parse(str); | ||
if (!root || is_error(root)) | ||
goto error; | ||
|
||
label = json_object_object_get(root, "connected"); | ||
if (!label) | ||
goto error; | ||
|
||
newState = !json_object_get_boolean(label); | ||
|
||
if (lsclient->powerSave != newState) | ||
{ | ||
lsclient->powerSave = newState; | ||
emit lsclient->devicePSMStateChanged(newState); | ||
} | ||
|
||
error: | ||
|
||
if (root && !is_error(root)) | ||
json_object_put(root); | ||
|
||
return true; | ||
} | ||
|
||
bool LSClient::displayCallback(LSHandle *sh, LSMessage *message, void *ctx) | ||
{ | ||
LSError lserror; | ||
LSErrorInit(&lserror); | ||
|
||
VALIDATE_SCHEMA_AND_RETURN(sh, | ||
message, | ||
SCHEMA_7( | ||
REQUIRED(returnValue, boolean), | ||
REQUIRED(event, string), | ||
OPTIONAL(state, string), | ||
OPTIONAL(timeout, integer), | ||
OPTIONAL(blockDisplay, string), | ||
OPTIONAL(active, boolean), | ||
OPTIONAL(subscribed, boolean) | ||
)); | ||
|
||
LSClient* lsclient = (LSClient*)ctx; | ||
|
||
json_object* root = 0; | ||
const char* value = 0; | ||
bool newState = true; | ||
bool ret = false; | ||
const char* str = LSMessageGetPayload(message); | ||
if (!str) | ||
goto error; | ||
|
||
root = json_tokener_parse(str); | ||
if (!root || is_error(root)) | ||
goto error; | ||
|
||
ret = json_object_get_boolean(json_object_object_get(root, "returnValue")); | ||
if (!ret) | ||
goto error; | ||
|
||
value = json_object_get_string(json_object_object_get(root, "event")); | ||
if (!value || is_error(value)) | ||
goto error; | ||
|
||
if (0 == strcmp (value, "displayOff")) | ||
newState = false; | ||
|
||
value = json_object_get_string(json_object_object_get(root, "state")); | ||
if (value && !is_error(value)) | ||
if (0 == strcmp (value, "off")) | ||
newState = false; | ||
|
||
if (lsclient->displayState != newState) | ||
{ | ||
lsclient->displayState = newState; | ||
emit lsclient->displayStateChanged(newState); | ||
} | ||
|
||
error: | ||
|
||
if (root && !is_error(root)) | ||
json_object_put(root); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
@file lsclient.h | ||
@brief LunaService signal utility | ||
<p> | ||
Copyright (C) 2009-2010 Nokia Corporation | ||
Copyright (C) 2015-2018 Nikolay Nizov | ||
@author Timo Rongas <ext-timo.2.rongas@nokia.com> | ||
@author Lihan Guo <ext-lihan.4.guo@nokia.com> | ||
@author Antti Virtanen <antti.i.virtanen@nokia.com> | ||
@author Nikolay Nizov <nizovn@gmail.com> | ||
This file is part of Sensord. | ||
Sensord is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License | ||
version 2.1 as published by the Free Software Foundation. | ||
Sensord is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with Sensord. If not, see <http://www.gnu.org/licenses/>. | ||
</p> | ||
*/ | ||
|
||
#ifndef SENSORD_LUNA_SERVICE_CLIENT_H | ||
#define SENSORD_LUNA_SERVICE_CLIENT_H | ||
|
||
#include <QObject> | ||
#include <luna-service2/lunaservice.h> | ||
|
||
/** | ||
* Class for monitoring various LS signals. | ||
*/ | ||
class LSClient : public QObject | ||
{ | ||
Q_OBJECT | ||
Q_DISABLE_COPY(LSClient) | ||
|
||
public: | ||
/** | ||
* Constructor. | ||
* | ||
* @param parent Parent object. | ||
*/ | ||
LSClient(QObject* parent = 0); | ||
|
||
/** | ||
* Get display state. | ||
* | ||
* @return display state. | ||
*/ | ||
bool displayEnabled() const; | ||
|
||
/** | ||
* Get powersave-mode state. | ||
* | ||
* @return powersave-mode state. | ||
*/ | ||
bool PSMEnabled() const; | ||
|
||
signals: | ||
/** | ||
* Emitted when display state has changed. | ||
* | ||
* @param displayOn \c true if display went to 'on' or 'dimmed', | ||
* \c false if 'off'. | ||
*/ | ||
void displayStateChanged(bool displayOn); | ||
|
||
/** | ||
* Emitted when powersave-mode has changed. | ||
* | ||
* @param PSM is powersave-mode enabled or not. | ||
*/ | ||
void devicePSMStateChanged(bool PSM); | ||
|
||
private slots: | ||
/** | ||
* Slot for LS display state change signals. | ||
* | ||
* @param state name of the state. | ||
*/ | ||
static bool displayCallback(LSHandle *sh, LSMessage *message, void *ctx); | ||
|
||
/** | ||
* Slot for LS powersave-mode state change signals. | ||
* | ||
* @param mode is powersave-mode enabled or not. | ||
*/ | ||
static bool chargerCallback(LSHandle *sh, LSMessage *message, void *ctx); | ||
|
||
private: | ||
bool displayState; /**< current display state */ | ||
bool powerSave; /**< current powersave-mode state */ | ||
|
||
}; | ||
|
||
#endif // SENSORD_LUNA_SERVICE_CLIENT_H |
Oops, something went wrong.