blob: 55d89d1e894d90f971ee12e7a7a08aba4ef19b2b [file] [log] [blame]
Lei Zhang91af91d2012-08-03 11:02:20 -07001// 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
14#include "mtpd/file_entry.h"
15#include "mtpd_server/mtpd_server.h"
16#include "mtpd/storage_info.h"
17
18namespace mtpd {
19
20class DeviceManager;
21
22// The D-bus server for the mtpd daemon.
23//
24// Example Usage:
25//
26// DBus::Connection server_conn = DBus::Connection::SystemBus();
27// server_conn.request_name("org.chromium.Mtpd");
28// MtpdServer* server = new(std::nothrow) MtpdServer(server_conn, &manager);
29//
30// At this point the server should be attached to the main loop.
31
32class MtpdServer : public org::chromium::Mtpd_adaptor,
33 public DBus::ObjectAdaptor {
34 public:
35 explicit MtpdServer(DBus::Connection& connection);
36 virtual ~MtpdServer();
37
38 // org::chromium::Mtpd_adaptor implementation.
39 virtual std::vector<std::string> EnumerateStorage(
40 DBus::Error &error) OVERRIDE;
41 virtual DBusMTPStorage GetStorageInfo(const std::string& storageName,
42 DBus::Error &error) OVERRIDE;
43 virtual std::string OpenStorage(const std::string& storageName,
44 const std::string& mode,
45 DBus::Error &error) OVERRIDE;
46 virtual void CloseStorage(const std::string& handle,
47 DBus::Error &error) OVERRIDE;
48 virtual DBusFileEntries ReadDirectoryByPath(const std::string& handle,
49 const std::string& filePath,
50 DBus::Error &error) OVERRIDE;
51 virtual DBusFileEntries ReadDirectoryById(const std::string& handle,
52 const uint32_t& fileId,
53 DBus::Error &error) OVERRIDE;
54 virtual std::vector<uint8_t> ReadFileByPath(
55 const std::string& handle,
56 const std::string& filePath,
57 DBus::Error &error) OVERRIDE;
58 virtual std::vector<uint8_t> ReadFileById(
59 const std::string& handle,
60 const uint32_t& fileId,
61 DBus::Error &error) OVERRIDE;
62 virtual bool IsAlive(DBus::Error &error) OVERRIDE;
63
64 // Returns a file descriptor for monitoring device events.
65 int GetDeviceEventDescriptor() const;
66
67 // Processes the available device events.
68 void ProcessDeviceEvents();
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(MtpdServer);
72};
73
74} // namespace mtpd
75
76#endif // MTPD_SERVER_IMPL_H_