Upstream version 6.34.113.0
[platform/framework/web/crosswalk.git] / src / xwalk / sysapps / raw_socket / udp_socket_object.h
1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_SYSAPPS_RAW_SOCKET_UDP_SOCKET_OBJECT_H_
6 #define XWALK_SYSAPPS_RAW_SOCKET_UDP_SOCKET_OBJECT_H_
7
8 #include <string>
9
10 #include "net/base/address_list.h"
11 #include "net/base/io_buffer.h"
12 #include "net/dns/single_request_host_resolver.h"
13 #include "net/udp/udp_socket.h"
14 #include "xwalk/sysapps/raw_socket/raw_socket_object.h"
15
16 namespace xwalk {
17 namespace sysapps {
18
19 class UDPSocketObject : public RawSocketObject {
20  public:
21   UDPSocketObject();
22   virtual ~UDPSocketObject();
23
24  private:
25   void DoRead();
26
27   // JavaScript function handlers.
28   void OnInit(scoped_ptr<XWalkExtensionFunctionInfo> info);
29   void OnClose(scoped_ptr<XWalkExtensionFunctionInfo> info);
30   void OnSuspend(scoped_ptr<XWalkExtensionFunctionInfo> info);
31   void OnResume(scoped_ptr<XWalkExtensionFunctionInfo> info);
32   void OnJoinMulticast(scoped_ptr<XWalkExtensionFunctionInfo> info);
33   void OnLeaveMulticast(scoped_ptr<XWalkExtensionFunctionInfo> info);
34   void OnSendString(scoped_ptr<XWalkExtensionFunctionInfo> info);
35
36   // net::UDPSocket callbacks.
37   void OnRead(int status);
38   void OnWrite(int status);
39
40   // net::SingleRequestHostResolver callbacks.
41   void OnConnectionOpen(int status);
42   void OnSend(int status);
43
44   bool has_write_pending_;
45   bool is_suspended_;
46   bool is_reading_;
47
48   scoped_refptr<net::IOBuffer> read_buffer_;
49   scoped_refptr<net::IOBuffer> write_buffer_;
50   scoped_ptr<net::UDPSocket> socket_;
51
52   unsigned write_buffer_size_;
53
54   scoped_ptr<net::HostResolver> resolver_;
55   scoped_ptr<net::SingleRequestHostResolver> single_resolver_;
56   net::AddressList addresses_;
57   net::IPEndPoint from_;
58 };
59
60 }  // namespace sysapps
61 }  // namespace xwalk
62
63 #endif  // XWALK_SYSAPPS_RAW_SOCKET_UDP_SOCKET_OBJECT_H_