--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __CONTEXT_DBUS_CALLER_H__
+#define __CONTEXT_DBUS_CALLER_H__
+
+#include <string>
+#include <ContextTypes.h>
+
+namespace ctx {
+
+ class EXPORT_API DBusCaller {
+ public:
+ GVariant* call(const std::string& busName, const std::string& objectPath,
+ const std::string& interface, const std::string& methodName,
+ GVariant* param);
+ };
+
+}
+
+#endif
class EXPORT_API DBusMonitor {
public:
- DBusMonitor(GDBusConnection* conn);
+ DBusMonitor();
~DBusMonitor();
+ /* Backward compatibility */
+ DBusMonitor(GDBusConnection* conn);
+
unsigned int subscribe(
const char* sender, const char* objPath,
const std::string& interface, const std::string& signalName,
static void __signalCb(GDBusConnection* conn, const gchar* sender, const gchar* path,
const gchar* iface, const gchar* name, GVariant* param, gpointer userData);
- GDBusConnection* __connection;
std::set<unsigned int> __subscriptionIds;
};
std::vector<std::string> get_files(const std::string& dir, bool symlink = false);
+ void set_dbus_connection(GDBusConnection* conn);
+
+ GDBusConnection* get_dbus_connection();
+
} }
#endif /* __CONTEXT_SERVER_UTIL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include <ServerUtil.h>
+#include <DBusCaller.h>
+
+using namespace ctx;
+
+GVariant* DBusCaller::call(const std::string& busName, const std::string& objectPath,
+ const std::string& interface, const std::string& methodName, GVariant* param)
+{
+ GError* gerr = NULL;
+
+ GVariant* result = g_dbus_connection_call_sync(util::get_dbus_connection(),
+ busName.c_str(), objectPath.c_str(), interface.c_str(), methodName.c_str(), param,
+ NULL, G_DBUS_CALL_FLAGS_NONE, CTX_DBUS_TIMEOUT, NULL, &gerr);
+
+ HANDLE_GERROR(gerr);
+
+ return result;
+}
* limitations under the License.
*/
+#include <ServerUtil.h>
#include <IDBusSignalListener.h>
#include <DBusMonitor.h>
using namespace ctx;
-DBusMonitor::DBusMonitor(GDBusConnection* conn) :
- __connection(conn)
+DBusMonitor::DBusMonitor(GDBusConnection* conn)
+{
+}
+
+DBusMonitor::DBusMonitor()
{
}
DBusMonitor::~DBusMonitor()
{
for (auto& sid : __subscriptionIds) {
- g_dbus_connection_signal_unsubscribe(__connection, sid);
+ g_dbus_connection_signal_unsubscribe(util::get_dbus_connection(), sid);
}
}
unsigned int DBusMonitor::subscribe(const char* sender, const char* objPath,
const std::string& interface, const std::string& signalName, IDBusSignalListener* listener)
{
- unsigned int sid = g_dbus_connection_signal_subscribe(__connection, sender,
+ unsigned int sid = g_dbus_connection_signal_subscribe(util::get_dbus_connection(), sender,
interface.c_str(), signalName.c_str(), objPath, NULL,
G_DBUS_SIGNAL_FLAGS_NONE, __signalCb, listener, NULL);
__subscriptionIds.insert(sid);
{
unsigned int erased = __subscriptionIds.erase(subscriptionId);
if (erased > 0)
- g_dbus_connection_signal_unsubscribe(__connection, subscriptionId);
+ g_dbus_connection_signal_unsubscribe(util::get_dbus_connection(), subscriptionId);
}
void DBusMonitor::__signalCb(GDBusConnection* conn, const gchar* sender, const gchar* path,
static GMutex __pathMutex;
static uid_t __normalUid = ROOT_UID; // Last known normal user UID
static uid_t __containerUid = ROOT_UID; // Last known container user UID
+static GDBusConnection* __dbusConnection = NULL;
EXPORT_API bool util::is_normal_user(uid_t uid)
{
closedir(dir);
return fileNames;
}
+
+EXPORT_API void set_dbus_connection(GDBusConnection* conn)
+{
+ __dbusConnection = conn;
+}
+
+EXPORT_API GDBusConnection* get_dbus_connection()
+{
+ return __dbusConnection;
+}
*/
#include <atomic>
+#include <ServerUtil.h>
#include <WakeLock.h>
+#define DEVICED_DBUS_DEST "org.tizen.system.deviced"
+#define DISPLAY_OBJ_PATH "/Org/Tizen/System/DeviceD/Display"
+#define DISPLAY_INTERFACE "org.tizen.system.deviced.display"
+
using namespace ctx;
static std::atomic_uint __refCount(0);
static void __acquire()
{
_I("Acquiring a WakeLock");
- // TODO
+
+ GError* gerr = NULL;
+ GVariant* result = g_dbus_connection_call_sync(util::get_dbus_connection(),
+ DEVICED_DBUS_DEST, DISPLAY_OBJ_PATH, DISPLAY_INTERFACE, "lockstate",
+ g_variant_new("(sssi)", "lcdoff", "staycurstate", "NULL", 0),
+ NULL, G_DBUS_CALL_FLAGS_NONE, CTX_DBUS_TIMEOUT, NULL, &gerr);
+
+ if (result) {
+ //TODO: Print the result?
+ g_variant_unref(result);
+ }
+
+ HANDLE_GERROR(gerr);
}
static void __release()
{
_I("Releasing the WakeLock");
- // TODO
+
+ GError* gerr = NULL;
+ GVariant* result = g_dbus_connection_call_sync(util::get_dbus_connection(),
+ DEVICED_DBUS_DEST, DISPLAY_OBJ_PATH, DISPLAY_INTERFACE, "unlockstate",
+ g_variant_new("(ss)", "lcdoff", "sleepmargin"),
+ NULL, G_DBUS_CALL_FLAGS_NONE, CTX_DBUS_TIMEOUT, NULL, &gerr);
+
+ if (result) {
+ //TODO: Print the result?
+ g_variant_unref(result);
+ }
+
+ HANDLE_GERROR(gerr);
}
WakeLock::WakeLock()