Lei Zhang | f0ab3ae | 2012-08-03 18:02:20 | [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 | 0e5015f | 2012-08-07 00:05:33 | [diff] [blame^] | 14 | #include "mtpd/device_event_delegate.h" |
| 15 | #include "mtpd/device_manager.h" |
Lei Zhang | f0ab3ae | 2012-08-03 18:02:20 | [diff] [blame] | 16 | #include "mtpd/file_entry.h" |
| 17 | #include "mtpd_server/mtpd_server.h" |
Lei Zhang | f0ab3ae | 2012-08-03 18:02:20 | [diff] [blame] | 18 | |
| 19 | namespace mtpd { |
| 20 | |
| 21 | class 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 | |
| 33 | class MtpdServer : public org::chromium::Mtpd_adaptor, |
Lei Zhang | 0e5015f | 2012-08-07 00:05:33 | [diff] [blame^] | 34 | public DBus::ObjectAdaptor, |
| 35 | public DeviceEventDelegate { |
Lei Zhang | f0ab3ae | 2012-08-03 18:02:20 | [diff] [blame] | 36 | 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 Zhang | 0e5015f | 2012-08-07 00:05:33 | [diff] [blame^] | 66 | // DeviceEventDelegate implementation. |
| 67 | virtual void StorageAttached(const std::string& storage_name) OVERRIDE; |
| 68 | virtual void StorageDetached(const std::string& storage_name) OVERRIDE; |
| 69 | |
Lei Zhang | f0ab3ae | 2012-08-03 18:02:20 | [diff] [blame] | 70 | // 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 Zhang | 0e5015f | 2012-08-07 00:05:33 | [diff] [blame^] | 77 | DeviceManager device_manager_; |
| 78 | |
Lei Zhang | f0ab3ae | 2012-08-03 18:02:20 | [diff] [blame] | 79 | DISALLOW_COPY_AND_ASSIGN(MtpdServer); |
| 80 | }; |
| 81 | |
| 82 | } // namespace mtpd |
| 83 | |
| 84 | #endif // MTPD_SERVER_IMPL_H_ |