blob: 4498c50037759f0c5142437e29e442e046371c8f [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
Alex Vakulenko24aa1222014-05-12 15:55:25 -07008#include <memory>
9#include <string>
10
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070011#include <base/basictypes.h>
12#include <base/memory/scoped_ptr.h>
Christopher Wileyd71774f2014-05-07 09:58:45 -070013#include <base/memory/weak_ptr.h>
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070014#include <base/values.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070015#include <dbus/message.h>
Christopher Wiley54028f92014-04-01 17:33:29 -070016#include <dbus/object_path.h>
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070017
Christopher Wiley106686a2014-03-27 14:51:26 -070018#include "buffet/dbus_constants.h"
19#include "buffet/exported_property_set.h"
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070020#include "buffet/device_registration_info.h"
Christopher Wiley106686a2014-03-27 14:51:26 -070021
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070022namespace buffet {
23
Christopher Wileyd71774f2014-05-07 09:58:45 -070024namespace dbus_utils {
25class ExportedObjectManager;
26} // namespace dbus_utils
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070027
28// The Manager is responsible for global state of Buffet. It exposes
29// interfaces which affect the entire device such as device registration and
30// device state.
31class Manager {
32 public:
Christopher Wiley54028f92014-04-01 17:33:29 -070033 typedef base::Callback<void(bool success)> OnInitFinish;
34
Christopher Wileyd71774f2014-05-07 09:58:45 -070035 Manager(scoped_refptr<dbus::Bus> bus,
36 base::WeakPtr<dbus_utils::ExportedObjectManager> object_manager);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070037 ~Manager();
Christopher Wiley54028f92014-04-01 17:33:29 -070038 void Init(const OnInitFinish& cb);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070039
40 private:
Christopher Wiley106686a2014-03-27 14:51:26 -070041 struct Properties: public dbus_utils::ExportedPropertySet {
42 public:
43 dbus_utils::ExportedProperty<std::string> state_;
Alex Vakulenko24aa1222014-05-12 15:55:25 -070044 explicit Properties(dbus::Bus* bus)
Christopher Wiley54028f92014-04-01 17:33:29 -070045 : dbus_utils::ExportedPropertySet(
46 bus, dbus::ObjectPath(dbus_constants::kManagerServicePath)) {
Christopher Wiley106686a2014-03-27 14:51:26 -070047 RegisterProperty(dbus_constants::kManagerInterface, "State", &state_);
48 }
49 virtual ~Properties() {}
50 };
51
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070052 // Handles calls to org.chromium.Buffet.Manager.CheckDeviceRegistered().
53 scoped_ptr<dbus::Response> HandleCheckDeviceRegistered(
54 dbus::MethodCall* method_call);
55 // Handles calls to org.chromium.Buffet.Manager.GetDeviceInfo().
56 scoped_ptr<dbus::Response> HandleGetDeviceInfo(
57 dbus::MethodCall* method_call);
58 // Handles calls to org.chromium.Buffet.Manager.StartRegisterDevice().
59 scoped_ptr<dbus::Response> HandleStartRegisterDevice(
60 dbus::MethodCall* method_call);
61 // Handles calls to org.chromium.Buffet.Manager.FinishRegisterDevice().
62 scoped_ptr<dbus::Response> HandleFinishRegisterDevice(
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070063 dbus::MethodCall* method_call);
64 // Handles calls to org.chromium.Buffet.Manager.UpdateState().
65 scoped_ptr<dbus::Response> HandleUpdateState(
66 dbus::MethodCall* method_call);
Christopher Wiley2ffa0042014-05-05 16:09:16 -070067 // Handles calls to org.chromium.Buffet.Manager.Test()
68 scoped_ptr<::dbus::Response> HandleTestMethod(
69 ::dbus::MethodCall* method_call);
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070070
Christopher Wileyd71774f2014-05-07 09:58:45 -070071 scoped_refptr<dbus::Bus> bus_;
Christopher Wiley54028f92014-04-01 17:33:29 -070072 dbus::ExportedObject* exported_object_; // weak; owned by the Bus object.
Christopher Wileyd71774f2014-05-07 09:58:45 -070073 base::WeakPtr<dbus_utils::ExportedObjectManager> object_manager_;
Christopher Wiley106686a2014-03-27 14:51:26 -070074 scoped_ptr<Properties> properties_;
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070075
Alex Vakulenkof3d77e52014-04-15 11:36:32 -070076 DeviceRegistrationInfo device_info_;
77
Christopher Wiley4b5f04c2014-03-27 14:45:37 -070078 DISALLOW_COPY_AND_ASSIGN(Manager);
79};
80
81} // namespace buffet
82
83#endif // BUFFET_MANAGER_H_