Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / cpp / Sample / Tizen C++ / SocketChat / SocketChat / project / inc / ChatFrm.h
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Flora License, Version 1.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.tizenopensource.org/license\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an AS IS BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 \r
18 #ifndef _CHATFRM_H_\r
19 #define _CHATFRM_H_\r
20 \r
21 #include <FBase.h>\r
22 #include <FUi.h>\r
23 #include <FNet.h>\r
24 #include <FApp.h>\r
25 \r
26 using namespace Osp::Net;\r
27 using namespace Osp::Net::Sockets;\r
28 using namespace Osp::Base;\r
29 class ChatFrm :\r
30         public Osp::Ui::Controls::Form,\r
31         public Osp::Ui::IActionEventListener,\r
32         public Osp::Net::Sockets::ISocketEventListener,\r
33         public Osp::Ui::Controls::IFormBackEventListener\r
34 \r
35 {\r
36 \r
37 // Construction\r
38 private:\r
39                 ChatFrm(void);\r
40 public:\r
41         ChatFrm(Ip4Address *add, int port, bool server, bool protocol,Osp::Ui::Controls::Form* prv);\r
42         virtual ~ChatFrm(void);\r
43         bool Initialize(void);\r
44 \r
45 // Implementation\r
46 protected:\r
47         static const int                                        ID_BUTTON_SEND                  = 101;\r
48         static const int                                        ID_LABEL_WAIT                   = 102;\r
49         static const int                                        ID_BUTTON_CLOSE_POPUP   = 103;\r
50         Osp::Ui::Controls::Form                         *__pFormme;\r
51         Osp::Ui::Controls::Button                       *__pButtonSend;\r
52         Osp::Ui::Controls::Label                        *__pLabelWait;\r
53         Osp::Ui::Controls::EditArea                     *__pEditAreaData;\r
54         Osp::Ui::Controls::EditField            *__pEditFieldtext;\r
55 \r
56         Osp::Net::Ip4Address                            *__pip_clientip;\r
57         int                                                             iport;\r
58         bool                                                            b_protocol; // true = tcp false = udp\r
59         bool                                                            b_server;\r
60         bool                                                            b_Connected;\r
61         Osp::Net::Sockets::Socket*                      __pSocket;\r
62         Osp::Net::Sockets::Socket*                      __pTcpOrgSocket;\r
63         Osp::Net::NetEndPoint*                          __pUdpEndpoint;\r
64         Osp::Ui::Controls::Form*                        __pPreviousForm;\r
65         Osp::Ui::Controls::Popup*                       __pPopup;\r
66         Osp::Ui::Controls::Footer*                      __pFooter;\r
67 public:\r
68         virtual result OnInitializing(void);\r
69         virtual result OnTerminating(void);\r
70         virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);\r
71         result StartChat();\r
72         void OnSocketAccept(Socket& socket);\r
73         void OnSocketClosed(Socket& socket1, NetSocketClosedReason reason);\r
74         void OnSocketConnected(Socket& socket1);\r
75         void OnSocketReadyToReceive(Socket& socket);\r
76         void OnSocketReadyToSend(Socket& socket1);\r
77         virtual void    OnFormBackRequested (Osp::Ui::Controls::Form &source);\r
78         void EnableControl(bool val);\r
79 private:\r
80         result SendData();\r
81         result ReceiveData();\r
82         void OnClose();\r
83 \r
84         result ReceiveDataUDP();\r
85         result ReceiveDataTCP();\r
86         result DisplayText(ByteBuffer &txBuffer,unsigned long buflen);\r
87         result SendDataCommand(String command);\r
88         result SocketServer();\r
89         result SocketClient();\r
90         result CreateSocket(NetSocketType type, NetSocketProtocol protocol);\r
91         void ShowPopup();\r
92         void HidePopup();\r
93         void WaitAndHidePopup();\r
94 \r
95 };\r
96 \r
97 #endif  //_CHATFRM_H_\r