Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 1 | // 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 Zhang | e7e0ea5 | 2012-10-03 19:27:44 -0700 | [diff] [blame] | 14 | #include "device_event_delegate.h" |
| 15 | #include "device_manager.h" |
| 16 | #include "file_entry.h" |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 17 | #include "mtpd_server/mtpd_server.h" |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 18 | |
| 19 | namespace mtpd { |
| 20 | |
| 21 | class DeviceManager; |
| 22 | |
| 23 | // The D-bus server for the mtpd daemon. |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 24 | class MtpdServer : public org::chromium::Mtpd_adaptor, |
Lei Zhang | 63e89bd | 2012-08-06 17:05:33 -0700 | [diff] [blame] | 25 | public DBus::ObjectAdaptor, |
| 26 | public DeviceEventDelegate { |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 27 | public: |
| 28 | explicit MtpdServer(DBus::Connection& connection); |
| 29 | virtual ~MtpdServer(); |
| 30 | |
| 31 | // org::chromium::Mtpd_adaptor implementation. |
Lei Zhang | c1768cf | 2012-11-16 13:35:37 -0800 | [diff] [blame] | 32 | virtual std::vector<std::string> EnumerateStorages( |
| 33 | DBus::Error& error) OVERRIDE; |
Lei Zhang | 6cd0bfc | 2012-09-06 20:18:26 -0700 | [diff] [blame] | 34 | virtual std::vector<uint8_t> GetStorageInfo(const std::string& storageName, |
| 35 | DBus::Error& error) OVERRIDE; |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 36 | virtual std::string OpenStorage(const std::string& storageName, |
| 37 | const std::string& mode, |
Lei Zhang | bd08aa2 | 2012-08-22 15:20:36 -0700 | [diff] [blame] | 38 | DBus::Error& error) OVERRIDE; |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 39 | virtual void CloseStorage(const std::string& handle, |
Lei Zhang | bd08aa2 | 2012-08-22 15:20:36 -0700 | [diff] [blame] | 40 | DBus::Error& error) OVERRIDE; |
Lei Zhang | 8c3a3f3 | 2014-07-22 16:33:25 -0700 | [diff] [blame^] | 41 | 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 Zhang | 6cd0bfc | 2012-09-06 20:18:26 -0700 | [diff] [blame] | 48 | virtual std::vector<uint8_t> ReadDirectoryById(const std::string& handle, |
| 49 | const uint32_t& fileId, |
| 50 | DBus::Error& error) OVERRIDE; |
Lei Zhang | 032b9e0 | 2012-11-13 18:38:38 -0800 | [diff] [blame] | 51 | 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 Zhang | 6cd0bfc | 2012-09-06 20:18:26 -0700 | [diff] [blame] | 56 | virtual std::vector<uint8_t> GetFileInfoById(const std::string& handle, |
| 57 | const uint32_t& fileId, |
| 58 | DBus::Error& error) OVERRIDE; |
Lei Zhang | bd08aa2 | 2012-08-22 15:20:36 -0700 | [diff] [blame] | 59 | virtual bool IsAlive(DBus::Error& error) OVERRIDE; |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 60 | |
Lei Zhang | 63e89bd | 2012-08-06 17:05:33 -0700 | [diff] [blame] | 61 | // DeviceEventDelegate implementation. |
| 62 | virtual void StorageAttached(const std::string& storage_name) OVERRIDE; |
| 63 | virtual void StorageDetached(const std::string& storage_name) OVERRIDE; |
| 64 | |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 65 | // 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 Zhang | 0d66f92 | 2012-08-07 15:22:05 -0700 | [diff] [blame] | 72 | // Handle to StorageName map. |
| 73 | typedef std::map<std::string, std::string> HandleMap; |
| 74 | |
Lei Zhang | a326413 | 2012-08-16 22:52:49 -0700 | [diff] [blame] | 75 | // Returns the StorageName for a handle, or an empty string on failure. |
| 76 | std::string LookupHandle(const std::string& handle); |
| 77 | |
Lei Zhang | 0d66f92 | 2012-08-07 15:22:05 -0700 | [diff] [blame] | 78 | HandleMap handle_map_; |
| 79 | |
| 80 | // Device manager needs to be last, so it is the first to be destroyed. |
Lei Zhang | 63e89bd | 2012-08-06 17:05:33 -0700 | [diff] [blame] | 81 | DeviceManager device_manager_; |
| 82 | |
Lei Zhang | 91af91d | 2012-08-03 11:02:20 -0700 | [diff] [blame] | 83 | DISALLOW_COPY_AND_ASSIGN(MtpdServer); |
| 84 | }; |
| 85 | |
| 86 | } // namespace mtpd |
| 87 | |
| 88 | #endif // MTPD_SERVER_IMPL_H_ |