blob: da9139135ece8265518a1f389b5ad93074f33219 [file] [log] [blame]
Chris Sosa45d9f102014-03-24 11:18:54 -07001// Copyright 2014 The Chromium OS Authors. 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.
4
5#ifndef BUFFET_DBUS_MANAGER_H_
6#define BUFFET_DBUS_MANAGER_H_
7
8#include <string>
9
10#include <base/memory/scoped_ptr.h>
11#include <dbus/bus.h>
12#include <dbus/exported_object.h>
13#include <dbus/message.h>
14
15namespace buffet {
16
17// TODO(sosa): Move to chromeos/system_api once we're ready.
18const char kBuffetInterface[] = "org.chromium.Buffet";
19const char kBuffetServicePath[] = "/org/chromium/Buffet";
20const char kBuffetServiceName[] = "org.chromium.Buffet";
21
22// Methods exposed by buffet.
23const char kTestMethod[] = "TestMethod";
24
25class DBusManager;
26
27// Pointer to a member function for handling D-Bus method calls. If an empty
28// scoped_ptr is returned, an empty (but successful) response will be sent.
29typedef scoped_ptr<dbus::Response> (DBusManager::*DBusMethodCallMemberFunction)(
30 dbus::MethodCall*);
31
32// Class that manages dbus interactions in buffet.
33class DBusManager {
34 public:
35 DBusManager();
36 virtual ~DBusManager();
37
38 void Init();
39 void Finalize();
40
41 private:
42 // Connects to the D-Bus system bus and exports methods.
43 void InitDBus();
44 void ShutDownDBus();
45
46 // Exports |method_name| and uses |member| to handle calls.
47 void ExportDBusMethod(const std::string& method_name,
48 DBusMethodCallMemberFunction member);
49
50 // Callbacks for handling D-Bus signals and method calls.
51 scoped_ptr<dbus::Response> HandleTestMethod(dbus::MethodCall* method_call);
52
53 scoped_refptr<dbus::Bus> bus_;
54 dbus::ExportedObject* buffet_dbus_object_; // weak; owned by |bus_|
55
56 DISALLOW_COPY_AND_ASSIGN(DBusManager);
57};
58
59} // namespace buffet
60
61#endif // BUFFET_DBUS_MANAGER_H_