blob: 2f32bc0cde41226bb1814dd42543bb6146e8f961 [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
Lei Zhange7e0ea52012-10-03 19:27:44 -070014#include "device_event_delegate.h"
15#include "device_manager.h"
16#include "file_entry.h"
Lei Zhang91af91d2012-08-03 11:02:20 -070017#include "mtpd_server/mtpd_server.h"
Lei Zhang91af91d2012-08-03 11:02:20 -070018
19namespace mtpd {
20
21class DeviceManager;
22
23// The D-bus server for the mtpd daemon.
Lei Zhang91af91d2012-08-03 11:02:20 -070024class MtpdServer : public org::chromium::Mtpd_adaptor,
Lei Zhang63e89bd2012-08-06 17:05:33 -070025 public DBus::ObjectAdaptor,
26 public DeviceEventDelegate {
Lei Zhang91af91d2012-08-03 11:02:20 -070027 public:
28 explicit MtpdServer(DBus::Connection& connection);
29 virtual ~MtpdServer();
30
31 // org::chromium::Mtpd_adaptor implementation.
Lei Zhangc1768cf2012-11-16 13:35:37 -080032 virtual std::vector<std::string> EnumerateStorages(
33 DBus::Error& error) OVERRIDE;
Lei Zhang6cd0bfc2012-09-06 20:18:26 -070034 virtual std::vector<uint8_t> GetStorageInfo(const std::string& storageName,
35 DBus::Error& error) OVERRIDE;
Lei Zhang91af91d2012-08-03 11:02:20 -070036 virtual std::string OpenStorage(const std::string& storageName,
37 const std::string& mode,
Lei Zhangbd08aa22012-08-22 15:20:36 -070038 DBus::Error& error) OVERRIDE;
Lei Zhang91af91d2012-08-03 11:02:20 -070039 virtual void CloseStorage(const std::string& handle,
Lei Zhangbd08aa22012-08-22 15:20:36 -070040 DBus::Error& error) OVERRIDE;
Lei Zhang8c3a3f32014-07-22 16:33:25 -070041 virtual std::vector<uint32_t> ReadDirectoryEntryIds(
42 const std::string& handle,
43 const uint32_t& fileId,
44 DBus::Error& error) OVERRIDE;
45 virtual std::vector<uint8_t> GetFileInfo(const std::string& handle,
46 const std::vector<uint32_t>& fileIds,
47 DBus::Error& error) OVERRIDE;
Lei Zhang6cd0bfc2012-09-06 20:18:26 -070048 virtual std::vector<uint8_t> ReadDirectoryById(const std::string& handle,
49 const uint32_t& fileId,
50 DBus::Error& error) OVERRIDE;
Lei Zhang032b9e02012-11-13 18:38:38 -080051 virtual std::vector<uint8_t> ReadFileChunkById(const std::string& handle,
52 const uint32_t& fileId,
53 const uint32_t& offset,
54 const uint32_t& count,
55 DBus::Error& error) OVERRIDE;
Lei Zhang6cd0bfc2012-09-06 20:18:26 -070056 virtual std::vector<uint8_t> GetFileInfoById(const std::string& handle,
57 const uint32_t& fileId,
58 DBus::Error& error) OVERRIDE;
Lei Zhangbd08aa22012-08-22 15:20:36 -070059 virtual bool IsAlive(DBus::Error& error) OVERRIDE;
Lei Zhang91af91d2012-08-03 11:02:20 -070060
Lei Zhang63e89bd2012-08-06 17:05:33 -070061 // DeviceEventDelegate implementation.
62 virtual void StorageAttached(const std::string& storage_name) OVERRIDE;
63 virtual void StorageDetached(const std::string& storage_name) OVERRIDE;
64
Lei Zhang91af91d2012-08-03 11:02:20 -070065 // Returns a file descriptor for monitoring device events.
66 int GetDeviceEventDescriptor() const;
67
68 // Processes the available device events.
69 void ProcessDeviceEvents();
70
71 private:
Lei Zhang0d66f922012-08-07 15:22:05 -070072 // Handle to StorageName map.
73 typedef std::map<std::string, std::string> HandleMap;
74
Lei Zhanga3264132012-08-16 22:52:49 -070075 // Returns the StorageName for a handle, or an empty string on failure.
76 std::string LookupHandle(const std::string& handle);
77
Lei Zhang0d66f922012-08-07 15:22:05 -070078 HandleMap handle_map_;
79
80 // Device manager needs to be last, so it is the first to be destroyed.
Lei Zhang63e89bd2012-08-06 17:05:33 -070081 DeviceManager device_manager_;
82
Lei Zhang91af91d2012-08-03 11:02:20 -070083 DISALLOW_COPY_AND_ASSIGN(MtpdServer);
84};
85
86} // namespace mtpd
87
88#endif // MTPD_SERVER_IMPL_H_