blob: ad66252673952a5577145513f1792066774df651 [file] [log] [blame]
Christopher Wiley4b5f04c2014-03-27 14:45:37 -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_MANAGER_H_
6#define BUFFET_MANAGER_H_
7
8#include <base/basictypes.h>
9#include <base/memory/scoped_ptr.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070010#include <base/values.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070011#include <dbus/message.h>
Christopher Wiley54028f92014-04-01 17:33:29 -070012#include <dbus/object_path.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070013#include <memory>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070014
Christopher Wiley106686a2014-03-27 14:51:26 -070015#include "buffet/dbus_constants.h"
16#include "buffet/exported_property_set.h"
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070017#include "buffet/device_registration_info.h"
Christopher Wiley106686a2014-03-27 14:51:26 -070018
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070019namespace buffet {
20
21class DBusManager;
22
23// The Manager is responsible for global state of Buffet. It exposes
24// interfaces which affect the entire device such as device registration and
25// device state.
26class Manager {
27 public:
Christopher Wiley54028f92014-04-01 17:33:29 -070028 typedef base::Callback<void(bool success)> OnInitFinish;
29
30 Manager(dbus::Bus* bus);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070031 ~Manager();
Christopher Wiley54028f92014-04-01 17:33:29 -070032 void Init(const OnInitFinish& cb);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070033
34 private:
Christopher Wiley106686a2014-03-27 14:51:26 -070035 struct Properties: public dbus_utils::ExportedPropertySet {
36 public:
37 dbus_utils::ExportedProperty<std::string> state_;
Christopher Wiley54028f92014-04-01 17:33:29 -070038 Properties(dbus::Bus* bus)
39 : dbus_utils::ExportedPropertySet(
40 bus, dbus::ObjectPath(dbus_constants::kManagerServicePath)) {
Christopher Wiley106686a2014-03-27 14:51:26 -070041 RegisterProperty(dbus_constants::kManagerInterface, "State", &state_);
42 }
43 virtual ~Properties() {}
44 };
45
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070046 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
47 scoped_ptr<dbus::Response> HandleCheckDeviceRegistered(
48 dbus::MethodCall* method_call);
49 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
50 scoped_ptr<dbus::Response> HandleGetDeviceInfo(
51 dbus::MethodCall* method_call);
52 // Handles calls to org.chromium.Buffet.Manager.StartRegisterDevice().
53 scoped_ptr<dbus::Response> HandleStartRegisterDevice(
54 dbus::MethodCall* method_call);
55 // Handles calls to org.chromium.Buffet.Manager.FinishRegisterDevice().
56 scoped_ptr<dbus::Response> HandleFinishRegisterDevice(
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070057 dbus::MethodCall* method_call);
58 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
59 scoped_ptr<dbus::Response> HandleUpdateState(
60 dbus::MethodCall* method_call);
61
Christopher Wiley54028f92014-04-01 17:33:29 -070062 dbus::Bus* bus_;
63 dbus::ExportedObject* exported_object_; // weak; owned by the Bus object.
Christopher Wiley106686a2014-03-27 14:51:26 -070064 scoped_ptr<Properties> properties_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070065
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070066 DeviceRegistrationInfo device_info_;
67
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070068 DISALLOW_COPY_AND_ASSIGN(Manager);
69};
70
71} // namespace buffet
72
73#endif // BUFFET_MANAGER_H_