* See the License for the specific language governing permissions and
* limitations under the License
*/
-
+#include <klay/dbus/signal.h>
#include "client.h"
+const std::string SIGNAL_OBJECT_PATH = "/org/tizen/OnDeviceEncryption";
+const std::string SIGNAL_EVENT_INTERFACE = "org.tizen.OnDeviceEncryption.Event";
+
ClientContext::ClientContext() noexcept
{
+ mainloop.reset(new ScopedGMainLoop);
}
ClientContext::~ClientContext() noexcept
{
disconnect();
+ mainloop.reset();
}
int ClientContext::connect(const std::string& address) noexcept
}
int ClientContext::subscribeSignal(const std::string& name,
- const SignalListener& listener,
+ const SignalListener& handler,
void* data)
{
- auto listenerDispatcher = [listener, data](std::string name) {
- listener(data);
- };
-
+ int ret = -1;
try {
- int ret = client->subscribe<std::string>
- (SUBSCRIBER_REGISTER, name, listenerDispatcher);
- if (ret < 0)
- return ode::error::Unknown;
+ mainloop->dispatch([&]() {
+ auto task = [name, handler, data](dbus::Variant variant) {
+ char *state = NULL;
+ variant.get("(s)", &state);
+ std::cout << "Signal: " << state << std::endl;
+ handler(data);
+ };
+
+ dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
+ ret = receiver.subscribe(name, std::move(task));
+ });
return ret;
} catch (runtime::Exception& e) {
- std::cout << e.what() << std::endl;
+ std::cerr << e.what() << std::endl;
return ode::error::Unknown;
}
}
-void ClientContext::unsubscribeSignal(int subscriberId)
+void ClientContext::unsubscribeSignal(int id)
{
- client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId);
+ try {
+ mainloop->dispatch([&]() {
+ dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
+ receiver.unsubscribe(id);
+ });
+ } catch (runtime::Exception& e) {
+ std::cerr << e.what() << std::endl;
+ }
}
#include <klay/rmi/client.h>
#include <rmi/common.h>
+#include <klay/gmainloop.h>
typedef std::function<void(void*)> SignalListener;
typedef std::unique_ptr<rmi::Client> RmiClientPtr;
class ClientContext final {
- const char* SUBSCRIBER_REGISTER = "ServerContext::registerNotificationSubscriber";
- const char* SUBSCRIBER_UNREGISTER = "ServerContext::unregisterNotificationSubscriber";
-
public:
ClientContext() noexcept;
~ClientContext() noexcept;
int subscribeSignal(const std::string& name, const SignalListener& listener, void* data);
void unsubscribeSignal(int subscriberId);
- template<typename ...Args>
- int subscribeSignal(const std::string& name, const std::function<void(Args...)>& listener)
- {
- try {
- int ret = client->subscribe<Args...>(SUBSCRIBER_REGISTER, name, listener);
- if (ret < 0)
- return ode::error::Unknown;
- return ret;
- } catch (runtime::Exception& e) {
- std::cout << e.what() << std::endl;
- return ode::error::Unknown;
- }
- }
-
template<typename Interface, typename... Args>
Interface createInterface(Args&&... args) noexcept
{
private:
RmiClientPtr client;
+ std::unique_ptr<ScopedGMainLoop> mainloop;
};
#endif //__ODE_CLIENT_H__
mountEventCallbackContext.reset(new ClientContext);
RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
- int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data);
+ int ret = mountEventCallbackContext->subscribeSignal("internal", callback, user_data);
if (ret < 0)
return toApiError(ret);
using namespace ode;
namespace {
-std::unique_ptr<ClientContext> luksEventCallbackContext;
int luks_format_internal(bool sync, const char* device, const char* password)
{
int ode_luks_set_event_cb(ode_luks_event_cb callback, void *user_data)
{
- int ret;
-
- RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER);
-
- luksEventCallbackContext.reset(new ClientContext);
- RET_ON_FAILURE(luksEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
-
- std::function<void(std::string, int, int)>cb = [callback, user_data](std::string, int op, int res) {
- callback(static_cast<ode_luks_operation_e>(op), toApiError(res), user_data);
- };
-
- ret = luksEventCallbackContext->subscribeSignal(Luks::NOTIFICATION, cb);
- if (ret < 0)
- return toApiError(ret);
-
- return ODE_ERROR_NONE;
+ return ODE_ERROR_UNKNOWN;
}
void ode_luks_unset_event_cb()
{
- luksEventCallbackContext.reset();
}
int ode_luks_format_sync(const char* device, const char* password)
# limitations under the License.
#
SET(SERVER_SRCS main.cpp
+ event.cpp
server.cpp
misc.cpp
ext4-tool.cpp
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "event.h"
+#include "logger.h"
+
+#include <klay/dbus/signal.h>
+#include <klay/dbus/introspection.h>
+#include <klay/exception.h>
+
+const std::string SIGNAL_OBJECT_PATH = "/org/tizen/OnDeviceEncryption";
+const std::string SIGNAL_EVENT_INTERFACE = "org.tizen.OnDeviceEncryption.Event";
+
+const std::string manifest =
+ "<node>"
+ " <interface name='" + SIGNAL_EVENT_INTERFACE + "'>"
+ " <signal name='" + SIGNAL_OBJECT_PATH + "'>"
+ " <arg type='s' name='argument'/>"
+ " </signal>"
+ " </interface>"
+ "</node>";
+
+void EventNotifier::init(void) noexcept
+{
+ try {
+ dbus::Connection& conn = dbus::Connection::getSystem();
+ conn.registerObject(SIGNAL_OBJECT_PATH, manifest, nullptr, nullptr);
+ WARN(SINK, "Success to init event-notifier.");
+ } catch(runtime::Exception& e) {
+ ERROR(SINK, e.what());
+ }
+}
+
+void EventNotifier::emit(const std::string& name, const std::string& state) noexcept
+{
+ try {
+ dbus::signal::Sender sender(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
+ sender.emit(name, "(s)", state.c_str());
+ WARN(SINK, "Event '" << name << "' has notified with state '" << state << "'");
+ } catch(runtime::Exception& e) {
+ ERROR(SINK, e.what() << ", name: " << name << ", state: " << state);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __ODE_EVENT_NOTIFIER_H__
+#define __ODE_EVENT_NOTIFIER_H__
+
+#include <string>
+
+class EventNotifier {
+public:
+ static void init(void) noexcept;
+ static void create(const std::string& name) noexcept;
+ static void emit(const std::string& name, const std::string& state) noexcept;
+};
+
+#endif //__ODE_EVENT_NOTIFIER_H__
server.expose(this, "", (unsigned int)(InternalEncryptionServer::getSupportedOptions)());
server.expose(this, "", (std::string)(InternalEncryptionServer::getDevicePath)());
- server.createNotification("InternalEncryptionServer::mount");
-
std::string source = findDevPath();
if (getStateInternal() == State::Encrypted) {
try {
engine->mount(key, getOptions());
- server.notify("InternalEncryptionServer::mount");
+ EventNotifier::emit("internal", "mounted");
runtime::File("/tmp/.lazy_mount").create(O_WRONLY);
runtime::File("/tmp/.unlock_mnt").create(O_WRONLY);
INFO(SINK, "Encryption completed.");
::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "encrypted");
- server.notify("InternalEncryptionServer::mount");
+ EventNotifier::emit("internal", "encrypted");
file.remove();
setPrivilegeChecker(std::bind(&ServerContext::checkPeerPrivilege, this, _1, _2));
- expose(this, "", (runtime::FileDescriptor)(ServerContext::registerNotificationSubscriber)(std::string));
- expose(this, "", (int)(ServerContext::unregisterNotificationSubscriber)(std::string, int));
-
keys.reset(new KeyServer(*this));
secureErase.reset(new SecureEraseServer(*this));
if (dbusOwnerId == 0)
throw runtime::Exception("Dbus failed to own name");
+ EventNotifier::init();
+
std::thread timerThread(&ServerContext::timerFunc, this);
timerThread.detach();
}
return true;
}
-runtime::FileDescriptor ServerContext::registerNotificationSubscriber(const std::string& name)
-{
- INFO(SINK, "registerNotificationSubscriber");
- INFO(SINK, name);
-
- RequestLifetime rl(*this);
-
- int fd = subscribeNotification(name);
-
- /**
- * Set @ label so that smack_file_receive() in kernel succeeds in checking
- * 'w' access between the client and the IPOUT of the socket.
- */
- if (smack_fsetlabel(fd, "@", SMACK_LABEL_IPOUT) != 0) {
- ERROR(SINK, "Setting IPOUT label failed");
- throw runtime::Exception("Setting IPOUT label failed");
- }
-
- return runtime::FileDescriptor(fd, true);
-}
-
-int ServerContext::unregisterNotificationSubscriber(const std::string& name, int id)
-{
- RequestLifetime rl(*this);
-
- return unsubscribeNotification(name, id);
-}
-
} // namespace ode
#include <klay/file-descriptor.h>
#include <klay/rmi/service.h>
+#include "event.h"
+
namespace ode {
class SecureEraseServer;
bool checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege);
- runtime::FileDescriptor registerNotificationSubscriber(const std::string& name);
- int unregisterNotificationSubscriber(const std::string& name, int id);
-
void requestStarted();
void requestFinished();