OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ |
| 6 #define PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "ppapi/c/extensions/dev/ppb_ext_socket_dev.h" |
| 12 #include "ppapi/cpp/dev/var_dictionary_dev.h" |
| 13 #include "ppapi/cpp/extensions/dict_field.h" |
| 14 #include "ppapi/cpp/extensions/ext_output_traits.h" |
| 15 #include "ppapi/cpp/instance_handle.h" |
| 16 #include "ppapi/cpp/var.h" |
| 17 #include "ppapi/cpp/var_array_buffer.h" |
| 18 |
| 19 namespace pp { |
| 20 |
| 21 template <class T> |
| 22 class CompletionCallbackWithOutput; |
| 23 |
| 24 namespace ext { |
| 25 |
| 26 template <class T> |
| 27 class Optional; |
| 28 |
| 29 namespace socket { |
| 30 |
| 31 // Data types ------------------------------------------------------------------ |
| 32 class SocketType_Dev { |
| 33 public: |
| 34 enum ValueType { |
| 35 NONE, |
| 36 TCP, |
| 37 UDP |
| 38 }; |
| 39 |
| 40 SocketType_Dev(); |
| 41 SocketType_Dev(ValueType in_value); |
| 42 ~SocketType_Dev(); |
| 43 |
| 44 bool Populate(const PP_Var& var_value); |
| 45 |
| 46 Var CreateVar() const; |
| 47 |
| 48 ValueType value; |
| 49 |
| 50 static const char* const kTcp; |
| 51 static const char* const kUdp; |
| 52 }; |
| 53 |
| 54 typedef VarDictionary_Dev CreateOptions_Dev; |
| 55 |
| 56 class CreateInfo_Dev : public internal::OutputObjectBase { |
| 57 public: |
| 58 CreateInfo_Dev(); |
| 59 ~CreateInfo_Dev(); |
| 60 |
| 61 bool Populate(const PP_Ext_Socket_CreateInfo_Dev& value); |
| 62 |
| 63 Var CreateVar() const; |
| 64 |
| 65 static const char* const kSocketId; |
| 66 |
| 67 DictField<int32_t> socket_id; |
| 68 }; |
| 69 |
| 70 class AcceptInfo_Dev : public internal::OutputObjectBase { |
| 71 public: |
| 72 AcceptInfo_Dev(); |
| 73 ~AcceptInfo_Dev(); |
| 74 |
| 75 bool Populate(const PP_Ext_Socket_AcceptInfo_Dev& value); |
| 76 |
| 77 Var CreateVar() const; |
| 78 |
| 79 static const char* const kResultCode; |
| 80 static const char* const kSocketId; |
| 81 |
| 82 DictField<int32_t> result_code; |
| 83 OptionalDictField<int32_t> socket_id; |
| 84 }; |
| 85 |
| 86 class ReadInfo_Dev : public internal::OutputObjectBase { |
| 87 public: |
| 88 ReadInfo_Dev(); |
| 89 ~ReadInfo_Dev(); |
| 90 |
| 91 bool Populate(const PP_Ext_Socket_ReadInfo_Dev& value); |
| 92 |
| 93 Var CreateVar() const; |
| 94 |
| 95 static const char* const kResultCode; |
| 96 static const char* const kData; |
| 97 |
| 98 DictField<int32_t> result_code; |
| 99 // TODO(yzshen): It is more natural to use VarArrayBuffer, but it doesn't have |
| 100 // a default constructor currently. |
| 101 DictField<Var> data; |
| 102 }; |
| 103 |
| 104 class WriteInfo_Dev : public internal::OutputObjectBase { |
| 105 public: |
| 106 WriteInfo_Dev(); |
| 107 ~WriteInfo_Dev(); |
| 108 |
| 109 bool Populate(const PP_Ext_Socket_WriteInfo_Dev& value); |
| 110 |
| 111 Var CreateVar() const; |
| 112 |
| 113 static const char* const kBytesWritten; |
| 114 |
| 115 DictField<int32_t> bytes_written; |
| 116 }; |
| 117 |
| 118 class RecvFromInfo_Dev : public internal::OutputObjectBase { |
| 119 public: |
| 120 RecvFromInfo_Dev(); |
| 121 ~RecvFromInfo_Dev(); |
| 122 |
| 123 bool Populate(const PP_Ext_Socket_RecvFromInfo_Dev& value); |
| 124 |
| 125 Var CreateVar() const; |
| 126 |
| 127 static const char* const kResultCode; |
| 128 static const char* const kData; |
| 129 static const char* const kAddress; |
| 130 static const char* const kPort; |
| 131 |
| 132 DictField<int32_t> result_code; |
| 133 DictField<Var> data; |
| 134 DictField<std::string> address; |
| 135 DictField<int32_t> port; |
| 136 }; |
| 137 |
| 138 class SocketInfo_Dev : public internal::OutputObjectBase { |
| 139 public: |
| 140 SocketInfo_Dev(); |
| 141 ~SocketInfo_Dev(); |
| 142 |
| 143 bool Populate(const PP_Ext_Socket_SocketInfo_Dev& value); |
| 144 |
| 145 Var CreateVar() const; |
| 146 |
| 147 static const char* const kSocketType; |
| 148 static const char* const kConnected; |
| 149 static const char* const kPeerAddress; |
| 150 static const char* const kPeerPort; |
| 151 static const char* const kLocalAddress; |
| 152 static const char* const kLocalPort; |
| 153 |
| 154 DictField<SocketType_Dev> socket_type; |
| 155 DictField<bool> connected; |
| 156 OptionalDictField<std::string> peer_address; |
| 157 OptionalDictField<int32_t> peer_port; |
| 158 OptionalDictField<std::string> local_address; |
| 159 OptionalDictField<int32_t> local_port; |
| 160 }; |
| 161 |
| 162 class NetworkInterface_Dev : public internal::OutputObjectBase { |
| 163 public: |
| 164 NetworkInterface_Dev(); |
| 165 ~NetworkInterface_Dev(); |
| 166 |
| 167 bool Populate(const PP_Ext_Socket_NetworkInterface_Dev& value); |
| 168 |
| 169 Var CreateVar() const; |
| 170 |
| 171 static const char* const kName; |
| 172 static const char* const kAddress; |
| 173 |
| 174 DictField<std::string> name; |
| 175 DictField<std::string> address; |
| 176 }; |
| 177 |
| 178 // Functions ------------------------------------------------------------------- |
| 179 class Socket_Dev { |
| 180 public: |
| 181 explicit Socket_Dev(const InstanceHandle& instance); |
| 182 ~Socket_Dev(); |
| 183 |
| 184 int32_t Create(const SocketType_Dev& type, |
| 185 const Optional<CreateOptions_Dev>& options, |
| 186 const CompletionCallbackWithOutput<CreateInfo_Dev>& callback); |
| 187 void Destroy(int32_t socket_id); |
| 188 // TODO(yzshen): Support more powerful traits. |
| 189 //int32_t Connect(int32_t socket_id, |
| 190 // const std::string& hostname, |
| 191 // int32_t port, |
| 192 // const CompletionCallbackWithOutput<int32_t>& callback); |
| 193 //int32_t Bind(int32_t socket_id, |
| 194 // const std::string& address, |
| 195 // int32_t port, |
| 196 // const CompletionCallbackWithOutput<int32_t>& callback); |
| 197 void Disconnect(int32_t socket_id); |
| 198 int32_t Read(int32_t socket_id, |
| 199 const Optional<int32_t>& buffer_size, |
| 200 const CompletionCallbackWithOutput<ReadInfo_Dev>& callback); |
| 201 int32_t Write(int32_t socket_id, |
| 202 const Var& data, |
| 203 const CompletionCallbackWithOutput<WriteInfo_Dev>& callback); |
| 204 int32_t RecvFrom( |
| 205 int32_t socket_id, |
| 206 const Optional<int32_t>& buffer_size, |
| 207 const CompletionCallbackWithOutput<RecvFromInfo_Dev>& callback); |
| 208 int32_t SendTo(int32_t socket_id, |
| 209 const Var& data, |
| 210 const std::string& address, |
| 211 int32_t port, |
| 212 const CompletionCallbackWithOutput<WriteInfo_Dev>& callback); |
| 213 // TODO(yzshen): Support more powerful traits. |
| 214 //int32_t Listen(int32_t socket_id, |
| 215 // const std::string& address, |
| 216 // int32_t port, |
| 217 // const Optional<int32_t>& backlog, |
| 218 // const CompletionCallbackWithOutput<int32_t>& callback); |
| 219 int32_t Accept(int32_t socket_id, |
| 220 const CompletionCallbackWithOutput<AcceptInfo_Dev>& callback); |
| 221 // TODO(yzshen): Support more powerful traits. |
| 222 //int32_t SetKeepAlive(int32_t socket_id, |
| 223 // bool enable, |
| 224 // const Optional<int32_t>& delay, |
| 225 // const CompletionCallbackWithOutput<bool>& callback); |
| 226 //int32_t SetNoDelay(int32_t socket_id, |
| 227 // bool no_delay, |
| 228 // const CompletionCallbackWithOutput<bool>& callback); |
| 229 int32_t GetInfo(int32_t socket_id, |
| 230 const CompletionCallbackWithOutput<SocketInfo_Dev>& callback); |
| 231 int32_t GetNetworkList( |
| 232 const CompletionCallbackWithOutput<std::vector<NetworkInterface_Dev> >& |
| 233 callback); |
| 234 |
| 235 private: |
| 236 InstanceHandle instance_; |
| 237 }; |
| 238 |
| 239 } // namespace socket |
| 240 } // namespace ext |
| 241 } // namespace pp |
| 242 |
| 243 #endif // PPAPI_CPP_EXTENSIONS_DEV_SOCKET_DEV_H_ |
OLD | NEW |