10f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
20f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
30f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// found in the LICENSE file.
40f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
50f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#ifndef CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
60f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#define CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
70f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
80f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <map>
90f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <string>
100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include <vector>
110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/values.h"
130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/chromeos_export.h"
140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/dbus_client.h"
150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/nfc_client_helpers.h"
160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chromeos/dbus/nfc_property_set.h"
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "chromeos/dbus/nfc_record_client.h"
180f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "dbus/object_path.h"
190f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "dbus/object_proxy.h"
200f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "dbus/property.h"
210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)namespace chromeos {
230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class NfcAdapterClient;
250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// NfcDeviceClient is used to communicate with objects representing remote NFC
270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// devices that can be communicated with.
280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class CHROMEOS_EXPORT NfcDeviceClient : public DBusClient {
290f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) public:
300f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Structure of properties associated with an NFC device.
310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  struct Properties : public NfcPropertySet {
320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // List of object paths for NDEF records associated with the NFC device.
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    // Read-only.
340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    dbus::Property<std::vector<dbus::ObjectPath> > records;
350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    Properties(dbus::ObjectProxy* object_proxy,
370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)               const PropertyChangedCallback& callback);
380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    virtual ~Properties();
390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  };
400f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
410f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Interface for observing changes from a remote NFC device.
420f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  class Observer {
430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)   public:
440f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    virtual ~Observer() {}
450f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Called when a remote NFC device with the object |object_path| is added
470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // to the set of known devices.
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    virtual void DeviceAdded(const dbus::ObjectPath& object_path) {}
490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Called when a remote NFC device with the object path |object_path| is
510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // removed from the set of known devices.
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    virtual void DeviceRemoved(const dbus::ObjectPath& object_path) {}
530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // Called when the device property with the name |property_name| on device
550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    // with object path |object_path| has acquired a new value.
560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                                       const std::string& property_name) {}
580f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  };
590f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
600f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual ~NfcDeviceClient();
610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Adds and removes observers for events on all remote NFC devices. Check the
630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // |object_path| parameter of observer methods to determine which device is
640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // issuing the event.
650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual void AddObserver(Observer* observer) = 0;
660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual void RemoveObserver(Observer* observer) = 0;
670f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns the list of device object paths associated with the given adapter
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // identified by the D-Bus object path |adapter_path|.
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual std::vector<dbus::ObjectPath> GetDevicesForAdapter(
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const dbus::ObjectPath& adapter_path) = 0;
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
730f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Obtain the properties for the NFC device with object path |object_path|;
740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // any values should be copied if needed.
750f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Creates an NDEF record for the NFC device with object path |object_path|
780f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // using the parameters in |attributes|. |attributes| is a dictionary,
790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // containing the NFC Record properties which will be assigned to the
800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // resulting record object and pushed to the device. The properties are
810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // defined by the NFC Record interface (see namespace "nfc_record" in
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // third_party/cros_system_api/dbus/service_constants.h and
830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // NfcRecordClient::Properties). |attributes| should at least contain a
840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // "Type" plus any other properties associated with that type. For example:
850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //
860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //    {
870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //      "Type": "Text",
880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //      "Encoding": "UTF-8",
890f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //      "Language": "en",
900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //      "Representation": "Chrome OS rulez!"
910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //    },
920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //    {
930f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //      "Type": "URI",
940f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //      "URI": "http://www.chromium.org"
950f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //    },
960f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  //    etc.
970f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  virtual void Push(
980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const dbus::ObjectPath& object_path,
99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const base::DictionaryValue& attributes,
1000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const base::Closure& callback,
1010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      const nfc_client_helpers::ErrorCallback& error_callback) = 0;
1020f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Creates the instance.
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  static NfcDeviceClient* Create(NfcAdapterClient* adapter_client);
1050f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) protected:
1070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  friend class NfcClientTest;
1080f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  NfcDeviceClient();
1100f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1110f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) private:
1120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(NfcDeviceClient);
1130f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)};
1140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}  // namespace chromeos
1160f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1170f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#endif  // CHROMEOS_DBUS_NFC_DEVICE_CLIENT_H_
118