| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 The Chromium 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 CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "chrome/common/extensions/api/serial.h" | |
| 12 #include "device/serial/serial.mojom.h" | |
| 13 #include "extensions/browser/api/api_resource_manager.h" | |
| 14 #include "extensions/browser/api/async_api_function.h" | |
| 15 | |
| 16 namespace extensions { | |
| 17 | |
| 18 class SerialConnection; | |
| 19 | |
| 20 namespace api { | |
| 21 | |
| 22 class SerialEventDispatcher; | |
| 23 | |
| 24 class SerialAsyncApiFunction : public AsyncApiFunction { | |
| 25 public: | |
| 26 SerialAsyncApiFunction(); | |
| 27 | |
| 28 protected: | |
| 29 virtual ~SerialAsyncApiFunction(); | |
| 30 | |
| 31 // AsyncApiFunction: | |
| 32 virtual bool PrePrepare() OVERRIDE; | |
| 33 virtual bool Respond() OVERRIDE; | |
| 34 | |
| 35 SerialConnection* GetSerialConnection(int api_resource_id); | |
| 36 void RemoveSerialConnection(int api_resource_id); | |
| 37 | |
| 38 ApiResourceManager<SerialConnection>* manager_; | |
| 39 }; | |
| 40 | |
| 41 class SerialGetDevicesFunction : public SerialAsyncApiFunction { | |
| 42 public: | |
| 43 DECLARE_EXTENSION_FUNCTION("serial.getDevices", SERIAL_GETDEVICES) | |
| 44 | |
| 45 SerialGetDevicesFunction(); | |
| 46 | |
| 47 protected: | |
| 48 virtual ~SerialGetDevicesFunction() {} | |
| 49 | |
| 50 // AsyncApiFunction: | |
| 51 virtual bool Prepare() OVERRIDE; | |
| 52 virtual void Work() OVERRIDE; | |
| 53 }; | |
| 54 | |
| 55 class SerialConnectFunction : public SerialAsyncApiFunction { | |
| 56 public: | |
| 57 DECLARE_EXTENSION_FUNCTION("serial.connect", SERIAL_CONNECT) | |
| 58 | |
| 59 SerialConnectFunction(); | |
| 60 | |
| 61 protected: | |
| 62 virtual ~SerialConnectFunction(); | |
| 63 | |
| 64 // AsyncApiFunction: | |
| 65 virtual bool Prepare() OVERRIDE; | |
| 66 virtual void AsyncWorkStart() OVERRIDE; | |
| 67 | |
| 68 virtual SerialConnection* CreateSerialConnection( | |
| 69 const std::string& port, | |
| 70 const std::string& extension_id) const; | |
| 71 | |
| 72 private: | |
| 73 void OnConnected(bool success); | |
| 74 void FinishConnect(); | |
| 75 | |
| 76 scoped_ptr<serial::Connect::Params> params_; | |
| 77 | |
| 78 // SerialEventDispatcher is owned by a BrowserContext. | |
| 79 SerialEventDispatcher* serial_event_dispatcher_; | |
| 80 | |
| 81 // This connection is created within SerialConnectFunction. | |
| 82 // From there it is either destroyed in OnConnected (upon failure) | |
| 83 // or its ownership is transferred to the | |
| 84 // ApiResourceManager<SerialConnection>. | |
| 85 SerialConnection* connection_; | |
| 86 }; | |
| 87 | |
| 88 class SerialUpdateFunction : public SerialAsyncApiFunction { | |
| 89 public: | |
| 90 DECLARE_EXTENSION_FUNCTION("serial.update", SERIAL_UPDATE); | |
| 91 | |
| 92 SerialUpdateFunction(); | |
| 93 | |
| 94 protected: | |
| 95 virtual ~SerialUpdateFunction(); | |
| 96 | |
| 97 // AsyncApiFunction: | |
| 98 virtual bool Prepare() OVERRIDE; | |
| 99 virtual void Work() OVERRIDE; | |
| 100 | |
| 101 private: | |
| 102 scoped_ptr<serial::Update::Params> params_; | |
| 103 }; | |
| 104 | |
| 105 class SerialDisconnectFunction : public SerialAsyncApiFunction { | |
| 106 public: | |
| 107 DECLARE_EXTENSION_FUNCTION("serial.disconnect", SERIAL_DISCONNECT) | |
| 108 | |
| 109 SerialDisconnectFunction(); | |
| 110 | |
| 111 protected: | |
| 112 virtual ~SerialDisconnectFunction(); | |
| 113 | |
| 114 // AsyncApiFunction: | |
| 115 virtual bool Prepare() OVERRIDE; | |
| 116 virtual void Work() OVERRIDE; | |
| 117 | |
| 118 private: | |
| 119 scoped_ptr<serial::Disconnect::Params> params_; | |
| 120 }; | |
| 121 | |
| 122 class SerialSetPausedFunction : public SerialAsyncApiFunction { | |
| 123 public: | |
| 124 DECLARE_EXTENSION_FUNCTION("serial.setPaused", SERIAL_SETPAUSED) | |
| 125 | |
| 126 SerialSetPausedFunction(); | |
| 127 | |
| 128 protected: | |
| 129 virtual ~SerialSetPausedFunction(); | |
| 130 | |
| 131 // AsyncApiFunction: | |
| 132 virtual bool Prepare() OVERRIDE; | |
| 133 virtual void Work() OVERRIDE; | |
| 134 | |
| 135 private: | |
| 136 scoped_ptr<serial::SetPaused::Params> params_; | |
| 137 SerialEventDispatcher* serial_event_dispatcher_; | |
| 138 }; | |
| 139 | |
| 140 class SerialGetInfoFunction : public SerialAsyncApiFunction { | |
| 141 public: | |
| 142 DECLARE_EXTENSION_FUNCTION("serial.getInfo", SERIAL_GETINFO) | |
| 143 | |
| 144 SerialGetInfoFunction(); | |
| 145 | |
| 146 protected: | |
| 147 virtual ~SerialGetInfoFunction(); | |
| 148 | |
| 149 // AsyncApiFunction: | |
| 150 virtual bool Prepare() OVERRIDE; | |
| 151 virtual void Work() OVERRIDE; | |
| 152 | |
| 153 private: | |
| 154 scoped_ptr<serial::GetInfo::Params> params_; | |
| 155 }; | |
| 156 | |
| 157 class SerialGetConnectionsFunction : public SerialAsyncApiFunction { | |
| 158 public: | |
| 159 DECLARE_EXTENSION_FUNCTION("serial.getConnections", SERIAL_GETCONNECTIONS); | |
| 160 | |
| 161 SerialGetConnectionsFunction(); | |
| 162 | |
| 163 protected: | |
| 164 virtual ~SerialGetConnectionsFunction(); | |
| 165 | |
| 166 // AsyncApiFunction: | |
| 167 virtual bool Prepare() OVERRIDE; | |
| 168 virtual void Work() OVERRIDE; | |
| 169 }; | |
| 170 | |
| 171 class SerialSendFunction : public SerialAsyncApiFunction { | |
| 172 public: | |
| 173 DECLARE_EXTENSION_FUNCTION("serial.send", SERIAL_SEND) | |
| 174 | |
| 175 SerialSendFunction(); | |
| 176 | |
| 177 protected: | |
| 178 virtual ~SerialSendFunction(); | |
| 179 | |
| 180 // AsyncApiFunction: | |
| 181 virtual bool Prepare() OVERRIDE; | |
| 182 virtual void AsyncWorkStart() OVERRIDE; | |
| 183 | |
| 184 private: | |
| 185 void OnSendComplete(int bytes_sent, serial::SendError error); | |
| 186 | |
| 187 scoped_ptr<serial::Send::Params> params_; | |
| 188 }; | |
| 189 | |
| 190 class SerialFlushFunction : public SerialAsyncApiFunction { | |
| 191 public: | |
| 192 DECLARE_EXTENSION_FUNCTION("serial.flush", SERIAL_FLUSH) | |
| 193 | |
| 194 SerialFlushFunction(); | |
| 195 | |
| 196 protected: | |
| 197 virtual ~SerialFlushFunction(); | |
| 198 | |
| 199 // AsyncApiFunction: | |
| 200 virtual bool Prepare() OVERRIDE; | |
| 201 virtual void Work() OVERRIDE; | |
| 202 | |
| 203 private: | |
| 204 scoped_ptr<serial::Flush::Params> params_; | |
| 205 }; | |
| 206 | |
| 207 class SerialGetControlSignalsFunction : public SerialAsyncApiFunction { | |
| 208 public: | |
| 209 DECLARE_EXTENSION_FUNCTION("serial.getControlSignals", | |
| 210 SERIAL_GETCONTROLSIGNALS) | |
| 211 | |
| 212 SerialGetControlSignalsFunction(); | |
| 213 | |
| 214 protected: | |
| 215 virtual ~SerialGetControlSignalsFunction(); | |
| 216 | |
| 217 // AsyncApiFunction: | |
| 218 virtual bool Prepare() OVERRIDE; | |
| 219 virtual void Work() OVERRIDE; | |
| 220 | |
| 221 private: | |
| 222 scoped_ptr<serial::GetControlSignals::Params> params_; | |
| 223 }; | |
| 224 | |
| 225 class SerialSetControlSignalsFunction : public SerialAsyncApiFunction { | |
| 226 public: | |
| 227 DECLARE_EXTENSION_FUNCTION("serial.setControlSignals", | |
| 228 SERIAL_SETCONTROLSIGNALS) | |
| 229 | |
| 230 SerialSetControlSignalsFunction(); | |
| 231 | |
| 232 protected: | |
| 233 virtual ~SerialSetControlSignalsFunction(); | |
| 234 | |
| 235 // AsyncApiFunction: | |
| 236 virtual bool Prepare() OVERRIDE; | |
| 237 virtual void Work() OVERRIDE; | |
| 238 | |
| 239 private: | |
| 240 scoped_ptr<serial::SetControlSignals::Params> params_; | |
| 241 }; | |
| 242 | |
| 243 } // namespace api | |
| 244 | |
| 245 } // namespace extensions | |
| 246 | |
| 247 namespace mojo { | |
| 248 | |
| 249 template <> | |
| 250 class TypeConverter<device::serial::DeviceInfoPtr, | |
| 251 linked_ptr<extensions::api::serial::DeviceInfo> > { | |
| 252 public: | |
| 253 static linked_ptr<extensions::api::serial::DeviceInfo> ConvertTo( | |
| 254 const device::serial::DeviceInfoPtr& input); | |
| 255 }; | |
| 256 | |
| 257 } // namespace mojo | |
| 258 | |
| 259 #endif // CHROME_BROWSER_EXTENSIONS_API_SERIAL_SERIAL_API_H_ | |
| OLD | NEW |