1 // Copyright 2020 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BROWSER_WRT_IPC_H_
6 #define BROWSER_WRT_IPC_H_
15 class InterProcessCommunication {
17 InterProcessCommunication(bool is_daemon = false);
18 ~InterProcessCommunication();
22 Message(DBusConnection* connection,
24 InterProcessCommunication* ipc);
26 const char* Sender() const;
27 void CloseDBusConnection() const;
28 void Reply(const char* argument) const;
31 DBusConnection* connection_;
32 DBusMessage* message_;
33 InterProcessCommunication* ipc_ = nullptr;
36 typedef std::function<void(const char* type, const char* argument, const Message& message)> MessageHandler;
38 void AddMessageHandler(const char* type, MessageHandler handler);
39 void SetExitOnDisconnect(bool exit_on_disconnect);
43 bool HasDbusOwner(const char* dbus_name);
44 bool SendMessage(const char* type, const char* argument);
45 bool SendMessage(const char* receiver, const char* type, const char* argument);
46 bool SendMessageAndWaitReply(const char* type, const char* argument, std::string& reply_argument);
47 bool SendMessageAndWaitReply(const char* receiver, const char* type, const char* argument, std::string& reply_argument);
50 static DBusHandlerResult OnMessage(DBusConnection* connection, DBusMessage* message, void* user_data);
52 DBusMessage* InternalSendMessage(const char* receiver, const char* type, const char* argument, bool need_reply);
54 DBusConnection* connection_;
55 std::map<const std::string, MessageHandler> message_handlers_;
56 bool will_close_ = false;
61 #endif // BROWSER_WRT_IPC_H_