blob: 24cc6befe4a45bdcec470b1dfda01bed88b80e7c [file] [log] [blame]
Lei Zhangf0ab3ae2012-08-03 18:02:201// Copyright (c) 2012 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 MTPD_SERVER_IMPL_H_
6#define MTPD_SERVER_IMPL_H_
7
8#include <string>
9#include <vector>
10
11#include <base/basictypes.h>
12#include <base/compiler_specific.h>
13
Lei Zhang0e5015f2012-08-07 00:05:3314#include "mtpd/device_event_delegate.h"
15#include "mtpd/device_manager.h"
Lei Zhangf0ab3ae2012-08-03 18:02:2016#include "mtpd/file_entry.h"
17#include "mtpd_server/mtpd_server.h"
Lei Zhangf0ab3ae2012-08-03 18:02:2018
19namespace mtpd {
20
21class DeviceManager;
22
23// The D-bus server for the mtpd daemon.
24//
25// Example Usage:
26//
27// DBus::Connection server_conn = DBus::Connection::SystemBus();
28// server_conn.request_name("org.chromium.Mtpd");
29// MtpdServer* server = new(std::nothrow) MtpdServer(server_conn, &manager);
30//
31// At this point the server should be attached to the main loop.
32
33class MtpdServer : public org::chromium::Mtpd_adaptor,
Lei Zhang0e5015f2012-08-07 00:05:3334 public DBus::ObjectAdaptor,
35 public DeviceEventDelegate {
Lei Zhangf0ab3ae2012-08-03 18:02:2036 public:
37 explicit MtpdServer(DBus::Connection& connection);
38 virtual ~MtpdServer();
39
40 // org::chromium::Mtpd_adaptor implementation.
41 virtual std::vector<std::string> EnumerateStorage(
42 DBus::Error &error) OVERRIDE;
43 virtual DBusMTPStorage GetStorageInfo(const std::string& storageName,
44 DBus::Error &error) OVERRIDE;
45 virtual std::string OpenStorage(const std::string& storageName,
46 const std::string& mode,
47 DBus::Error &error) OVERRIDE;
48 virtual void CloseStorage(const std::string& handle,
49 DBus::Error &error) OVERRIDE;
50 virtual DBusFileEntries ReadDirectoryByPath(const std::string& handle,
51 const std::string& filePath,
52 DBus::Error &error) OVERRIDE;
53 virtual DBusFileEntries ReadDirectoryById(const std::string& handle,
54 const uint32_t& fileId,
55 DBus::Error &error) OVERRIDE;
56 virtual std::vector<uint8_t> ReadFileByPath(
57 const std::string& handle,
58 const std::string& filePath,
59 DBus::Error &error) OVERRIDE;
60 virtual std::vector<uint8_t> ReadFileById(
61 const std::string& handle,
62 const uint32_t& fileId,
63 DBus::Error &error) OVERRIDE;
64 virtual bool IsAlive(DBus::Error &error) OVERRIDE;
65
Lei Zhang0e5015f2012-08-07 00:05:3366 // DeviceEventDelegate implementation.
67 virtual void StorageAttached(const std::string& storage_name) OVERRIDE;
68 virtual void StorageDetached(const std::string& storage_name) OVERRIDE;
69
Lei Zhangf0ab3ae2012-08-03 18:02:2070 // Returns a file descriptor for monitoring device events.
71 int GetDeviceEventDescriptor() const;
72
73 // Processes the available device events.
74 void ProcessDeviceEvents();
75
76 private:
Lei Zhang0e5015f2012-08-07 00:05:3377 DeviceManager device_manager_;
78
Lei Zhangf0ab3ae2012-08-03 18:02:2079 DISALLOW_COPY_AND_ASSIGN(MtpdServer);
80};
81
82} // namespace mtpd
83
84#endif // MTPD_SERVER_IMPL_H_