--- /dev/null
+Flora License
+
+Version 1.0, May, 2012
+
+http://floralicense.org/license/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction,
+and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by
+the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and
+all other entities that control, are controlled by, or are
+under common control with that entity. For the purposes of
+this definition, "control" means (i) the power, direct or indirect,
+to cause the direction or management of such entity,
+whether by contract or otherwise, or (ii) ownership of fifty percent (50%)
+or more of the outstanding shares, or (iii) beneficial ownership of
+such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity
+exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications,
+including but not limited to software source code, documentation source,
+and configuration files.
+
+"Object" form shall mean any form resulting from mechanical
+transformation or translation of a Source form, including but
+not limited to compiled object code, generated documentation,
+and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or Object form,
+made available under the License, as indicated by a copyright notice
+that is included in or attached to the work (an example is provided
+in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object form,
+that is based on (or derived from) the Work and for which the editorial
+revisions, annotations, elaborations, or other modifications represent,
+as a whole, an original work of authorship. For the purposes of this License,
+Derivative Works shall not include works that remain separable from,
+or merely link (or bind by name) to the interfaces of, the Work and
+Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including the original
+version of the Work and any modifications or additions to that Work or
+Derivative Works thereof, that is intentionally submitted to Licensor
+for inclusion in the Work by the copyright owner or by an individual or
+Legal Entity authorized to submit on behalf of the copyright owner.
+For the purposes of this definition, "submitted" means any form of
+electronic, verbal, or written communication sent to the Licensor or
+its representatives, including but not limited to communication on
+electronic mailing lists, source code control systems, and issue
+tracking systems that are managed by, or on behalf of, the Licensor
+for the purpose of discussing and improving the Work, but excluding
+communication that is conspicuously marked or otherwise designated
+in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity
+on behalf of whom a Contribution has been received by Licensor and
+subsequently incorporated within the Work.
+
+"Tizen Certified Platform" shall mean a software platform that complies
+with the standards set forth in the Compatibility Definition Document
+and passes the Compatibility Test Suite as defined from time to time
+by the Tizen Technical Steering Group and certified by the Tizen
+Association or its designated agent.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the
+Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+(except as stated in this section) patent license to make, have made,
+use, offer to sell, sell, import, and otherwise transfer the Work
+solely as incorporated into a Tizen Certified Platform, where such
+license applies only to those patent claims licensable by such
+Contributor that are necessarily infringed by their Contribution(s)
+alone or by combination of their Contribution(s) with the Work solely
+as incorporated into a Tizen Certified Platform to which such
+Contribution(s) was submitted. If You institute patent litigation
+against any entity (including a cross-claim or counterclaim
+in a lawsuit) alleging that the Work or a Contribution incorporated
+within the Work constitutes direct or contributory patent infringement,
+then any patent licenses granted to You under this License for that
+Work shall terminate as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+Work or Derivative Works thereof pursuant to the copyright license
+above, in any medium, with or without modifications, and in Source or
+Object form, provided that You meet the following conditions:
+
+ 1. You must give any other recipients of the Work or Derivative Works
+ a copy of this License; and
+ 2. You must cause any modified files to carry prominent notices stating
+ that You changed the files; and
+ 3. You must retain, in the Source form of any Derivative Works that
+ You distribute, all copyright, patent, trademark, and attribution
+ notices from the Source form of the Work, excluding those notices
+ that do not pertain to any part of the Derivative Works; and
+ 4. If the Work includes a "NOTICE" text file as part of its distribution,
+ then any Derivative Works that You distribute must include a readable
+ copy of the attribution notices contained within such NOTICE file,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works, in at least one of the following places:
+ within a NOTICE text file distributed as part of the Derivative Works;
+ within the Source form or documentation, if provided along with the
+ Derivative Works; or, within a display generated by the Derivative Works,
+ if and wherever such third-party notices normally appear.
+ The contents of the NOTICE file are for informational purposes only
+ and do not modify the License.
+
+You may add Your own attribution notices within Derivative Works
+that You distribute, alongside or as an addendum to the NOTICE text
+from the Work, provided that such additional attribution notices
+cannot be construed as modifying the License. You may add Your own
+copyright statement to Your modifications and may provide additional or
+different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works
+as a whole, provided Your use, reproduction, and distribution of
+the Work otherwise complies with the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+any Contribution intentionally submitted for inclusion in the Work
+by You to the Licensor shall be under the terms and conditions of
+this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify
+the terms of any separate license agreement you may have executed
+with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+names, trademarks, service marks, or product names of the Licensor,
+except as required for reasonable and customary use in describing the
+origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+agreed to in writing, Licensor provides the Work (and each
+Contributor provides its Contributions) on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+implied, including, without limitation, any warranties or conditions
+of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+PARTICULAR PURPOSE. You are solely responsible for determining the
+appropriateness of using or redistributing the Work and assume any
+risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+whether in tort (including negligence), contract, or otherwise,
+unless required by applicable law (such as deliberate and grossly
+negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special,
+incidental, or consequential damages of any character arising as a
+result of this License or out of the use or inability to use the
+Work (including but not limited to damages for loss of goodwill,
+work stoppage, computer failure or malfunction, or any and all
+other commercial damages or losses), even if such Contributor
+has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+the Work or Derivative Works thereof, You may choose to offer,
+and charge a fee for, acceptance of support, warranty, indemnity,
+or other liability obligations and/or rights consistent with this
+License. However, in accepting such obligations, You may act only
+on Your own behalf and on Your sole responsibility, not on behalf
+of any other Contributor, and only if You agree to indemnify,
+defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason
+of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Flora License to your work
+
+To apply the Flora License to your work, attach the following
+boilerplate notice, with the fields enclosed by brackets "[]"
+replaced with your own identifying information. (Don't include
+the brackets!) The text should be enclosed in the appropriate
+comment syntax for the file format. We also recommend that a
+file or class name and description of purpose be included on the
+same "printed page" as the copyright notice for easier
+identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Flora License, Version 1.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://floralicense.org/license/
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
--- /dev/null
+Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Flora License, Version 1.
+Please, see the LICENSE.Flora file for Flora License terms and conditions.
+
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/xsl" href="../../../../description.xsl"?>
+
+<Overview version="0.17.1">
+ <SampleName> SocketChat </SampleName>
+ <SampleVersion>1.0</SampleVersion>
+ <Preview>screenshot.png</Preview>
+ <Description>
+ The SocketChat sample application demonstrates how you can implement chat functionality between 2 devices using TCP and UDP protocols
+ </Description>
+</Overview>
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _CHAT_FRM_H_
+#define _CHAT_FRM_H_
+
+#include <new>
+#include <FBase.h>
+#include <FNet.h>
+#include <FApp.h>
+#include <FUi.h>
+
+using namespace Tizen::Net;
+using namespace Tizen::Net::Sockets;
+using namespace Tizen::Base;
+
+class ChatFrm
+ : public Tizen::Ui::Controls::Form
+ , public Tizen::Ui::IActionEventListener
+ , public Tizen::Net::Sockets::ISocketEventListener
+ , public Tizen::Ui::Controls::IFormBackEventListener
+ , public Tizen::Ui::Scenes::ISceneEventListener
+{
+public:
+ ChatFrm(void);
+ ChatFrm(Ip4Address* pAddress, int port, bool isServer, bool isTcp, Tizen::Ui::Controls::Form* pPreviousForm);
+ virtual ~ChatFrm(void);
+
+ bool Initialize(void);
+
+ virtual result OnInitializing(void);
+
+ virtual result OnTerminating(void);
+
+ virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
+
+ result StartChat(void);
+
+ virtual void OnFormBackRequested(Tizen::Ui::Controls::Form& source);
+
+ virtual void OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
+ const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs);
+
+ virtual void OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId);
+
+ void EnableControl(bool val);
+
+ virtual void OnSocketAccept(Socket& socket);
+
+ virtual void OnSocketClosed(Socket& socket1, NetSocketClosedReason reason);
+
+ virtual void OnSocketConnected(Socket& socket1);
+
+ virtual void OnSocketReadyToReceive(Socket& socket);
+
+ virtual void OnSocketReadyToSend(Socket& socket1);
+
+private:
+
+ result SendData(void);
+
+ result ReceiveData(void);
+
+ void OnClose(void);
+
+ result ReceiveDataUDP(void);
+
+ result ReceiveDataTCP(void);
+
+ result DisplayText(ByteBuffer& txBuffer, unsigned long buflen);
+
+ result SendDataCommand(String command);
+
+ result SocketServer(void);
+
+ result SocketClient(void);
+
+ result CreateSocket(NetSocketType type, NetSocketProtocol protocol);
+
+ void ShowPopup(void);
+
+ void HidePopup(void);
+
+ void WaitAndHidePopup(void);
+
+private:
+ Tizen::Ui::Controls::Form* __pForm;
+ Tizen::Ui::Controls::Label* __pLabelWait;
+ Tizen::Ui::Controls::EditArea* __pEditAreaData;
+ Tizen::Ui::Controls::EditField* __pEditFieldtext;
+
+ Tizen::Net::Ip4Address* __pClientIp;
+ int __port;
+ bool __isTcp; // true = tcp false = udp
+ bool __isServer;
+ bool __isConnected;
+ bool __isConstructed;
+ Tizen::Net::Sockets::Socket* __pSocket;
+ Tizen::Net::Sockets::Socket* __pTcpSocket;
+ Tizen::Net::NetEndPoint* __pUdpEndpoint;
+ Tizen::Ui::Controls::Form* __pPreviousForm;
+ Tizen::Ui::Controls::Popup* __pPopup;
+ Tizen::Ui::Controls::Footer* __pFooter;
+};
+
+#endif //_CHAT_FRM_H_
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _FORM_FACTORY_H_
+#define _FORM_FACTORY_H_
+
+#include <FUi.h>
+
+extern const wchar_t* FORM_MAIN_MENU;
+extern const wchar_t* FORM_CHAT_MENU;
+
+class FormFactory
+ : public Tizen::Ui::Scenes::IFormFactory
+{
+public:
+ FormFactory(void);
+ virtual ~FormFactory(void);
+
+ virtual Tizen::Ui::Controls::Form* CreateFormN(const Tizen::Base::String& formId, const Tizen::Ui::Scenes::SceneId& sceneId);
+};
+
+#endif // _FORM_FACTORY_H_
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _MAIN_FRM_H_
+#define _MAIN_FRM_H_
+
+#include <new>
+#include <FBase.h>
+#include <FNet.h>
+#include <FUi.h>
+#include "ChatFrm.h"
+
+class MainFrm
+ : public Tizen::Ui::Controls::Form
+ , public Tizen::Ui::IActionEventListener
+{
+public:
+ MainFrm(void);
+ virtual ~MainFrm(void);
+
+ bool Initialize(void);
+
+ virtual result OnInitializing(void);
+
+ virtual result OnTerminating(void);
+
+ virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
+
+ void StartChat(void);
+
+ void SetDefaultValues(void);
+
+private:
+ Tizen::Ui::Controls::CheckButton* __pButtonServer;
+ Tizen::Ui::Controls::CheckButton* __pButtonTcp;
+ Tizen::Ui::Controls::CheckButton* __pButtonUdp;
+ Tizen::Ui::Controls::EditField* __pEditIPAddress;
+ Tizen::Ui::Controls::EditField* __pEditPort;
+
+ Tizen::Net::Ip4Address* __pClientIp;
+ int __iport;
+ bool __isProtocol; // true = tcp false = udp
+ bool __isServer;
+ ChatFrm* __pChatForm;
+ Tizen::Ui::Controls::FooterItem __footerItem_Left;
+};
+
+#endif //_MAIN_FRM_H_
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef _SOCKET_CHAT_H_
+#define _SOCKET_CHAT_H_
+
+#include <FBase.h>
+#include <FSystem.h>
+#include <FApp.h>
+#include "MainFrm.h"
+
+extern const wchar_t* SCENE_MAIN_MENU;
+extern const wchar_t* SCENE_CHAT_MENU;
+
+/**
+ * [SocketChat] application must inherit from Application class
+ * which provides basic features necessary to define an application.
+ */
+class SocketChat
+ : public Tizen::App::Application
+ , public Tizen::System::IScreenEventListener
+{
+public:
+ SocketChat(void);
+ ~SocketChat(void);
+
+ /**
+ * [SocketChat] application must have a factory method that creates an instance of itself.
+ */
+ static Tizen::App::Application* CreateInstance(void);
+
+ // Called when the application is initializing.
+ virtual bool OnAppInitializing(Tizen::App::AppRegistry& appRegistry);
+
+ // Called when the application is terminating.
+ virtual bool OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
+
+ // Called when the application's frame moves to the top of the screen.
+ virtual void OnForeground(void);
+
+ // Called when this application's frame is moved from top of the screen to the background.
+ virtual void OnBackground(void);
+
+ // Called when the system memory is not sufficient to run the application any further.
+ virtual void OnLowMemory(void);
+
+ // Called when the battery level changes.
+ virtual void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
+
+ // Called when the screen turns on.
+ virtual void OnScreenOn(void);
+
+ // Called when the screen turns off.
+ virtual void OnScreenOff(void);
+
+private:
+ MainFrm* __pMainFrm;
+};
+
+#endif // _SOCKET_CHAT_H_
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<Manifest xmlns="http://schemas.tizen.org/2012/12/manifest">
+ <Id>$(manifestAppId)</Id>
+ <Version>1.0.0</Version>
+ <Type>C++App</Type>
+ <Author>Samsung</Author>
+ <Descriptions>
+ <Description Locale="eng-GB">Sample Socket Example</Description>
+ </Descriptions>
+ <Url/>
+ <DeviceProfile/>
+ <Apps>
+ <ApiVersion>2.0</ApiVersion>
+ <Privileges>
+ <Privilege>http://tizen.org/privilege/socket</Privilege>
+ </Privileges>
+ <UiApp Main="True" Name="$(projectName)" MenuIconVisible="True" >
+ <DisplayNames>
+ <DisplayName Locale="eng-GB">$(projectName)</DisplayName>
+ </DisplayNames>
+ <UiScalability CoordinateSystem="Logical" BaseScreenSize="Normal" LogicalCoordinate="480" />
+ <UiTheme SystemTheme="White"/>
+ <Icons>
+ <Icon Section="MainMenu" Type="Xhigh">mainmenu.png</Icon>
+ </Icons>
+ <LaunchConditions/>
+ <Notifications/>
+ </UiApp>
+ </Apps>
+</Manifest>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
+<!--\r
+ This XML file was automatically generated by UiBuilder - do not modify by hand.\r
+-->\r
+<string_table Bversion="2.0.0.v20110307" Dversion="20100701"/>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ This XML file was automatically generated by UiBuilder - do not modify by hand.
+-->
+<!DOCTYPE Scene SYSTEM "UIForm.dtd">
+
+<Scene Bversion="2.0.0.v20110307" Dversion="20100701">
+ <Form id="IDF_CHATFRM">
+ <property BGColor="" BGColorOpacity="0" Orientation="Portrait" softKey0NormalIcon="" softKey0PressedIcon="" softKey0Text="" softKey1NormalIcon="" softKey1PressedIcon="" softKey1Text="" title="" titleAlign="ALIGN_CENTER" titleIcon="" translucentFooter="FALSE" translucentHeader="FALSE" translucentIndicator="FALSE"/>
+ <layout mode="Portrait" style="FORM_STYLE_INDICATOR|FORM_STYLE_FOOTER|FORM_STYLE_HEADER"/>
+ <layout mode="Landscape" style="FORM_STYLE_INDICATOR|FORM_STYLE_FOOTER|FORM_STYLE_HEADER"/>
+ </Form>
+ <Footer>
+ <property BGBitmapPath="" color="" colorOpacity="0" disabledButtonColor="" disabledButtonColorOpacity="0" disabledButtonTextColor="" disabledItemColor="" disabledItemColorOpacity="0" disabledItemTextColor="" footerStyle="FOOTER_STYLE_TAB" highlightedButtonColor="" highlightedButtonColorOpacity="0" highlightedButtonTextColor="" highlightedItemColor="" highlightedItemColorOpacity="0" highlightedItemTextColor="" normalButtonColor="" normalButtonColorOpacity="0" normalButtonTextColor="" normalItemColor="" normalItemColorOpacity="0" normalItemTextColor="" pressedButtonColor="" pressedButtonColorOpacity="0" pressedButtonTextColor="" selectedItemColor="" selectedItemColorOpacity="0" selectedItemTextColor=""/>
+ </Footer>
+ <Header>
+ <property BGBitmapPath="" color="" colorOpacity="50" descriptionText="" descriptionTextColor="" disabledButtonColor="" disabledButtonColorOpacity="0" disabledButtonTextColor="" disabledItemColor="" disabledItemColorOpacity="0" disabledItemTextColor="" headerStyle="HEADER_STYLE_TITLE" highlightedButtonColor="" highlightedButtonColorOpacity="0" highlightedButtonTextColor="" highlightedItemColor="" highlightedItemColorOpacity="0" highlightedItemTextColor="" normalButtonColor="" normalButtonColorOpacity="0" normalButtonTextColor="" normalItemColor="" normalItemColorOpacity="0" normalItemTextColor="" pressedButtonColor="" pressedButtonColorOpacity="0" pressedButtonTextColor="" selectedItemColor="" selectedItemColorOpacity="0" selectedItemTextColor="" titleIconPath="" titleText="Chat" titleTextColor=""/>
+ </Header>
+ <EditField id="IDC_TEXT" parent="IDF_CHATFRM">
+ <property GroupStyle="GROUP_STYLE_NONE" InputStyle="INPUT_STYLE_FULLSCREEN" KeypadEnabled="TRUE" LimitLength="1000" bShowTitleText="FALSE" guideText="" text="" titleText=""/>
+ <layout height="80" mode="Portrait" style="EDIT_FIELD_STYLE_NORMAL" width="480" x="0" y="455"/>
+ <layout height="80" mode="Landscape" style="EDIT_FIELD_STYLE_NORMAL" width="218" x="16" y="396"/>
+ </EditField>
+ <EditArea id="IDC_DATA" parent="IDF_CHATFRM">
+ <property InputStyle="INPUT_STYLE_FULLSCREEN" LimitLength="1024" guideText="" text=""/>
+ <layout height="452" mode="Portrait" width="480" x="0" y="0"/>
+ <layout height="108" mode="Landscape" width="335" x="133" y="92"/>
+ </EditArea>
+ <Label id="IDC_Wait" parent="IDF_CHATFRM">
+ <property BGBitmapPath="" BGColor="" BGColorOpacity="0" hAlign="ALIGN_LEFT" text="Waiting for User to Connect..." textColor="#0000FF" textSize="22" textStyle="LABEL_TEXT_STYLE_NORMAL" vAlign="ALIGN_TOP"/>
+ <layout height="61" mode="Portrait" width="480" x="0" y="305"/>
+ <layout height="36" mode="Landscape" width="800" x="0" y="278"/>
+ </Label>
+</Scene>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+ This XML file was automatically generated by UiBuilder - do not modify by hand.
+-->
+<!DOCTYPE Scene SYSTEM "UIForm.dtd">
+
+<Scene Bversion="2.0.0.v20110603" Dversion="20100701">
+ <Form id="IDF_MAINFRM">
+ <property BGColor="" BGColorOpacity="0" Orientation="Portrait" softKey0NormalIcon="" softKey0PressedIcon="" softKey0Text="" softKey1NormalIcon="" softKey1PressedIcon="" softKey1Text="" title="" titleAlign="ALIGN_CENTER" titleIcon="" translucentFooter="FALSE" translucentHeader="FALSE" translucentIndicator="FALSE"/>
+ <layout mode="Portrait" style="FORM_STYLE_NORMAL |FORM_STYLE_INDICATOR||FORM_STYLE_FOOTER|FORM_STYLE_HEADER" type="NONE"/>
+ <layout mode="Landscape" style="FORM_STYLE_NORMAL |FORM_STYLE_INDICATOR||FORM_STYLE_FOOTER|FORM_STYLE_HEADER" type="NONE"/>
+ </Form>
+ <Footer>
+ <property BGBitmapPath="" color="" colorOpacity="0" disabledButtonColor="" disabledButtonColorOpacity="0" disabledButtonTextColor="" disabledItemColor="" disabledItemColorOpacity="0" disabledItemTextColor="" footerStyle="FOOTER_STYLE_TAB" highlightedButtonColor="" highlightedButtonColorOpacity="0" highlightedButtonTextColor="" highlightedItemColor="" highlightedItemColorOpacity="0" highlightedItemTextColor="" normalButtonColor="" normalButtonColorOpacity="0" normalButtonTextColor="" normalItemColor="" normalItemColorOpacity="0" normalItemTextColor="" pressedButtonColor="" pressedButtonColorOpacity="0" pressedButtonTextColor="" pressedItemColor="" pressedItemColorOpacity="0" pressedItemTextColor="" selectedItemColor="" selectedItemColorOpacity="0" selectedItemTextColor=""/>
+ <itemSet/>
+ </Footer>
+ <Header>
+ <property BGBitmapPath="" color="" colorOpacity="50" descriptionText="" descriptionTextColor="" disabledButtonColor="" disabledButtonColorOpacity="0" disabledButtonTextColor="" disabledItemColor="" disabledItemColorOpacity="0" disabledItemTextColor="" headerStyle="HEADER_STYLE_TITLE" highlightedButtonColor="" highlightedButtonColorOpacity="0" highlightedButtonTextColor="" highlightedItemColor="" highlightedItemColorOpacity="0" highlightedItemTextColor="" normalButtonColor="" normalButtonColorOpacity="0" normalButtonTextColor="" normalItemColor="" normalItemColorOpacity="0" normalItemTextColor="" pressedButtonColor="" pressedButtonColorOpacity="0" pressedButtonTextColor="" pressedItemColor="" pressedItemColorOpacity="0" pressedItemTextColor="" selectedItemColor="" selectedItemColorOpacity="0" selectedItemTextColor="" titleIconPath="" titleText="SocketChat" titleTextColor=""/>
+ <itemSet/>
+ </Header>
+ <CheckButton id="IDC_CHECKTCP" parent="IDF_MAINFRM">
+ <property BackgroundStyle="BACKGROUND_STYLE_DEFAULT" GroupID="0" GroupStyle="GROUP_STYLE_NONE" bShowtitleText="FALSE" colorOfText="" colorOfTitleText="" disabledColor="" disabledColorOpacity="0" disabledTextColor="" disabledTitleTextColor="" hAlign="ALIGN_LEFT" highlightedColor="" highlightedColorOpacity="0" highlightedTextColor="" highlightedTitleTextColor="" normalColor="" normalColorOpacity="0" pressedColor="" pressedColorOpacity="0" pressedTextColor="" pressedTitleTextColor="" text="TCP" titleText="" vAlign="ALIGN_MIDDLE"/>
+ <layout height="72" mode="Portrait" style="CHECK_BUTTON_STYLE_RADIO" width="461" x="10" y="8"/>
+ <layout height="72" mode="Landscape" style="CHECK_BUTTON_STYLE_RADIO" width="301" x="100" y="72"/>
+ </CheckButton>
+ <CheckButton id="IDC_CHECKUDP" parent="IDF_MAINFRM">
+ <property BackgroundStyle="BACKGROUND_STYLE_DEFAULT" GroupID="0" GroupStyle="GROUP_STYLE_BOTTOM" bShowtitleText="FALSE" colorOfText="" colorOfTitleText="" disabledColor="" disabledColorOpacity="0" disabledTextColor="" disabledTitleTextColor="" hAlign="ALIGN_LEFT" highlightedColor="" highlightedColorOpacity="0" highlightedTextColor="" highlightedTitleTextColor="" normalColor="" normalColorOpacity="0" pressedColor="" pressedColorOpacity="0" pressedTextColor="" pressedTitleTextColor="" text="UDP" titleText="" vAlign="ALIGN_MIDDLE"/>
+ <layout height="72" mode="Portrait" style="CHECK_BUTTON_STYLE_RADIO" width="461" x="10" y="80"/>
+ <layout height="72" mode="Landscape" style="CHECK_BUTTON_STYLE_RADIO" width="301" x="120" y="72"/>
+ </CheckButton>
+ <CheckButton id="IDC_CHECKServer" parent="IDF_MAINFRM">
+ <property BackgroundStyle="BACKGROUND_STYLE_DEFAULT" GroupID="0" GroupStyle="GROUP_STYLE_NONE" bShowtitleText="FALSE" colorOfText="" colorOfTitleText="" disabledColor="" disabledColorOpacity="0" disabledTextColor="" disabledTitleTextColor="" hAlign="ALIGN_LEFT" highlightedColor="" highlightedColorOpacity="0" highlightedTextColor="" highlightedTitleTextColor="" normalColor="" normalColorOpacity="0" pressedColor="" pressedColorOpacity="0" pressedTextColor="" pressedTitleTextColor="" text="Server" titleText="" vAlign="ALIGN_MIDDLE"/>
+ <layout height="72" mode="Portrait" style="CHECK_BUTTON_STYLE_ONOFF_SLIDING" width="461" x="10" y="154"/>
+ <layout height="72" mode="Landscape" style="CHECK_BUTTON_STYLE_ONOFF_SLIDING" width="735" x="33" y="72"/>
+ </CheckButton>
+ <EditField id="IDC_EDITIPaddress" parent="IDF_MAINFRM">
+ <property GroupStyle="GROUP_STYLE_NONE" InputStyle="INPUT_STYLE_FULLSCREEN" KeypadEnabled="TRUE" disabledBGBitmapPath="" disabledColor="" disabledTextColor="" ellipsisPosition="" enableClear="" guideText="" guideTextColor="" highlightedBGBitmapPath="" highlightedColor="" highlightedTextColor="" horizontalMargin="0" keypadAction="" limitLength="100" linkTextColor="" lowerCaseMode="" nomalBGBitmapPath="" normalColor="" normalTextColor="" pressedBGBitmapPath="" pressedColor="" text="" textHorizontalAlignment="" textSize="30" titleStyle="EDIT_FIELD_TITLE_STYLE_TOP" titleText="Server IPAddress " titleTextColor="" verticalMargin="0" viewMode="FALSE"/>
+ <layout height="106" mode="Portrait" style="EDIT_FIELD_STYLE_NORMAL" width="461" x="10" y="227"/>
+ <layout height="106" mode="Landscape" style="EDIT_FIELD_STYLE_NORMAL" width="768" x="16" y="114"/>
+ </EditField>
+ <EditField id="IDC_EDITPort" parent="IDF_MAINFRM">
+ <property GroupStyle="GROUP_STYLE_NONE" InputStyle="INPUT_STYLE_FULLSCREEN" KeypadEnabled="TRUE" disabledBGBitmapPath="" disabledColor="" disabledTextColor="" ellipsisPosition="" enableClear="" guideText="" guideTextColor="" highlightedBGBitmapPath="" highlightedColor="" highlightedTextColor="" horizontalMargin="0" keypadAction="" limitLength="100" linkTextColor="" lowerCaseMode="" nomalBGBitmapPath="" normalColor="" normalTextColor="" pressedBGBitmapPath="" pressedColor="" text="" textHorizontalAlignment="" textSize="30" titleStyle="EDIT_FIELD_TITLE_STYLE_TOP" titleText="Server Port" titleTextColor="" verticalMargin="0" viewMode="FALSE"/>
+ <layout height="106" mode="Portrait" style="EDIT_FIELD_STYLE_NUMBER" width="461" x="10" y="335"/>
+ <layout height="106" mode="Landscape" style="EDIT_FIELD_STYLE_NUMBER" width="701" x="16" y="168"/>
+ </EditField>
+</Scene>
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "SocketChat.h"
+#include "FormFactory.h"
+#include "ChatFrm.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Ui;
+using namespace Tizen::Ui::Controls;
+using namespace Tizen::Ui::Scenes;
+using namespace Tizen::Net;
+using namespace Tizen::Net::Sockets;
+using namespace Tizen::Graphics;
+
+static const int ID_BUTTON_SEND = 101;
+static const int ID_BUTTON_CLOSE_POPUP = 103;
+static const int DIMENSION_WIDTH = 400;
+static const int DIMENSION_HEIGHT = 500;
+static const int BUTTON_RECTANGLE_X = 150;
+static const int BUTTON_RECTANGLE_Y = 340;
+static const int BUTTON_RECTANGLE_WIDTH = 100;
+static const int BUTTON_RECTANGLE_HEIGHT = 60;
+static const int LABEL_RECTANGLE_X = 20;
+static const int LABEL_RECTANGLE_Y = 20;
+static const int LABEL_RECTANGLE_WIDTH = 340;
+static const int LABEL_RECTANGLE_HEIGHT = 300;
+static const int THREAD_TIMEOUT = 1000;
+
+#define COLOR_R 0xff
+#define COLOR_G 0xff
+#define COLOR_B 0xff
+#define COLOR_A 0x00
+
+ChatFrm::ChatFrm(void)
+ : __pForm(null)
+ , __pLabelWait(null)
+ , __pEditAreaData(null)
+ , __pEditFieldtext(null)
+ , __pClientIp(null)
+ , __port(0)
+ , __isTcp(true)
+ , __isServer(true)
+ , __isConnected(false)
+ , __isConstructed(false)
+ , __pSocket(null)
+ , __pTcpSocket(null)
+ , __pUdpEndpoint(null)
+ , __pPreviousForm(null)
+ , __pPopup(null)
+ , __pFooter(null)
+{
+}
+
+ChatFrm::~ChatFrm(void)
+{
+ delete __pClientIp;
+ __pClientIp = null;
+
+ EnableControl(false);
+}
+
+ChatFrm::ChatFrm(Ip4Address* pAddress, int port, bool isServer, bool isTcp, Tizen::Ui::Controls::Form* pPreviousForm)
+ : __pForm(null)
+ , __pLabelWait(null)
+ , __pEditAreaData(null)
+ , __pEditFieldtext(null)
+ , __port(port)
+ , __isTcp(isTcp)
+ , __isServer(isServer)
+ , __isConnected(false)
+ , __isConstructed(false)
+ , __pSocket(null)
+ , __pTcpSocket(null)
+ , __pUdpEndpoint(null)
+ , __pPreviousForm(pPreviousForm)
+ , __pPopup(null)
+ , __pFooter(null)
+{
+}
+
+bool
+ChatFrm::Initialize(void)
+{
+ // Construct an XML form
+ Construct(L"IDF_CHATFRM");
+
+ return true;
+}
+
+result
+ChatFrm::OnInitializing(void)
+{
+ result r = E_SUCCESS;
+
+ // Get a button via resource ID
+ __pForm = this;
+
+ __pFooter = GetFooter();
+ if (__pFooter != null)
+ {
+ __pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
+ FooterItem footerItem_Left;
+
+ footerItem_Left.Construct(ID_BUTTON_SEND);
+ footerItem_Left.SetText(L"Send");
+ __pFooter->AddItem(footerItem_Left);
+
+ if (__isTcp)
+ {
+ __pFooter->SetItemEnabled(0, false);
+ }
+ else
+ {
+ __pFooter->SetItemEnabled(0, true);
+ }
+
+ __pFooter->SetBackButton();
+ SetFormBackEventListener(this);
+
+ __pFooter->AddActionEventListener(*this);
+ }
+
+ __pLabelWait = static_cast< Label* >(GetControl(L"IDC_Wait"));
+ if (__pLabelWait == null)
+ {
+ AppLog("Can't get label Handle");
+ r = E_FAILURE;
+ }
+
+ __pEditAreaData = static_cast< EditArea* >(GetControl(L"IDC_DATA"));
+ if (__pEditAreaData == null)
+ {
+ AppLog("Can't get edit area Handle");
+ r = E_FAILURE;
+ }
+
+ __pEditFieldtext = static_cast< EditField* >(GetControl(L"IDC_TEXT"));
+ if (__pEditFieldtext == null)
+ {
+ AppLog("Can't get edit field Handle");
+ r = E_FAILURE;
+ }
+
+ __pPopup = new (std::nothrow) Popup();
+ if (__pPopup != null)
+ {
+ __pPopup->Construct(true, Dimension(DIMENSION_WIDTH, DIMENSION_HEIGHT));
+ __pPopup->SetTitleText(L"Send");
+
+ Button* pButtonClose = new (std::nothrow) Button();
+ pButtonClose->Construct(Rectangle(BUTTON_RECTANGLE_X, BUTTON_RECTANGLE_Y, BUTTON_RECTANGLE_WIDTH, BUTTON_RECTANGLE_HEIGHT), L"Close");
+ pButtonClose->SetActionId(ID_BUTTON_CLOSE_POPUP);
+ pButtonClose->AddActionEventListener(*this);
+ __pPopup->AddControl(*pButtonClose);
+
+ Label* pLabelText = new (std::nothrow) Label();
+
+ pLabelText->Construct(Rectangle(LABEL_RECTANGLE_X, LABEL_RECTANGLE_Y, LABEL_RECTANGLE_WIDTH, LABEL_RECTANGLE_HEIGHT), L"Data Send Error");
+ pLabelText->SetBackgroundColor(Color(COLOR_R, COLOR_G, COLOR_B, COLOR_A));
+ pLabelText->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
+
+ __pPopup->AddControl(*pLabelText);
+ }
+
+ EnableControl(false);
+
+ return r;
+}
+
+void
+ChatFrm::ShowPopup(void)
+{
+ if (__pPopup != null)
+ {
+ __pPopup->SetShowState(true);
+ __pPopup->Show();
+ }
+}
+
+void
+ChatFrm::HidePopup(void)
+{
+ if (__pPopup != null)
+ {
+ __pPopup->SetShowState(false);
+ }
+
+ Show();
+}
+
+void
+ChatFrm::WaitAndHidePopup(void)
+{
+ if (__pPopup != null)
+ {
+ if (__pPopup->IsVisible() == true)
+ {
+ AppLog("Wait for Popup to Get hidden");
+ Tizen::Base::Runtime::Thread::Sleep(THREAD_TIMEOUT);
+ __pPopup->SetShowState(false);
+ Show();
+ }
+ }
+}
+
+result
+ChatFrm::OnTerminating(void)
+{
+ result r = E_SUCCESS;
+
+ delete __pPopup;
+ __pPopup = null;
+
+ AppLog("ChatFrm::OnTerminating");
+ OnClose();
+ EnableControl(false);
+
+ return r;
+}
+
+void
+ChatFrm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
+{
+ AppLog("Close Button Pressed");
+
+ SceneManager* pSceneManager = SceneManager::GetInstance();
+ AppAssert(pSceneManager);
+
+ pSceneManager->GoBackward(BackwardSceneTransition(SCENE_MAIN_MENU));
+
+ OnClose();
+ EnableControl(false);
+}
+
+void
+ChatFrm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
+{
+ result res = E_SUCCESS;
+
+ switch (actionId)
+ {
+ case ID_BUTTON_SEND:
+ {
+ res = SendData();
+ if (IsFailed(res))
+ {
+ AppLog("Data Send Failed.");
+ ShowPopup();
+ }
+ }
+ break;
+
+ case ID_BUTTON_CLOSE_POPUP:
+ HidePopup();
+ break;
+
+ default:
+ AppLog("Someone action taken");
+ break;
+ }
+}
+
+result
+ChatFrm::CreateSocket(NetSocketType type, NetSocketProtocol protocol)
+{
+ unsigned long arg = 1;
+ result res = E_SUCCESS;
+
+ // Create socket
+ __pSocket = new (std::nothrow) Socket();
+ TryReturn(__pSocket != null, E_OUT_OF_MEMORY, "Failed to allocate Socket");
+
+ AppLog("Constructing Socket");
+ res = __pSocket->Construct(NET_SOCKET_AF_IPV4, type, protocol);
+ TryReturn(res == E_SUCCESS, res, "Socket Construction failed %d", res);
+
+ // Non-blocking mode = 1, blocking mode = 0
+ res = __pSocket->Ioctl(NET_SOCKET_FIONBIO, arg);
+ TryReturn(res == E_SUCCESS, res, "Socket Ioctl failed %d", res);
+
+ // Add Socket Listener to listen to socket event
+ res = __pSocket->AddSocketListener(*this);
+ TryReturn(res == E_SUCCESS, res, "Socket AddSocketListener failed %d", res);
+
+ res = __pSocket->SetSockOpt(NET_SOCKET_SOL_SOCKET, NET_SOCKET_SO_REUSEADDR, 1);
+ TryReturn(res == E_SUCCESS, res, "Socket SetSockOpt failed %d", res);
+
+ // Set the socket as select an interested event.
+ res = __pSocket->AsyncSelectByListener(NET_SOCKET_EVENT_CONNECT | NET_SOCKET_EVENT_WRITE | NET_SOCKET_EVENT_READ | NET_SOCKET_EVENT_CLOSE | NET_SOCKET_EVENT_ACCEPT);
+ TryReturn(res == E_SUCCESS, res, "Socket AsyncSelectByListener failed %d", res);
+
+ return res;
+}
+
+result
+ChatFrm::SocketServer(void)
+{
+ result res = E_SUCCESS;
+
+ // Create a NetEndPoint
+ Ip4Address peerAddr(NET_SOCKET_INADDR_ANY); // ADDR_ANY
+ unsigned short peerPort = __port; // Port
+
+ NetEndPoint* pPeerEndPoint = new (std::nothrow) NetEndPoint(peerAddr, peerPort);
+ TryReturn(pPeerEndPoint != null, E_OUT_OF_MEMORY, "Failed to allocate NetEndPoint");
+
+ // Bind socket to SERVER_PORT
+ res = __pSocket->Bind(*pPeerEndPoint);
+ delete pPeerEndPoint;
+ TryReturn(res == E_SUCCESS, res, "Socket Bind failed %d", res);
+
+ if (__isTcp)
+ {
+ // Start listening on tcp port
+ res = __pSocket->Listen(0); // No queue allowed
+ TryReturn(res == E_SUCCESS, res, "Socket Listen failed %ls", GetErrorMessage(res));
+ }
+
+ return res;
+}
+
+result
+ChatFrm::SocketClient(void)
+{
+ result res = E_SUCCESS;
+
+ if (__isTcp)
+ {
+ // Create server endpoint using serverip address and port
+ NetEndPoint* pPeerEndPoint = new (std::nothrow) NetEndPoint(*__pClientIp, __port);
+ TryReturn(pPeerEndPoint != null, E_OUT_OF_MEMORY, "Failed to allocate NetEndPoint");
+
+ // Connect to peer for tcp protocol
+ res = __pSocket->Connect(*pPeerEndPoint);
+ AppLog("Socket Return %ls", GetErrorMessage(res));
+ delete pPeerEndPoint;
+ return res;
+ }
+ else
+ {
+ // Send hello message to peer using udp protocol
+ EnableControl(true);
+ SendDataCommand(L"__HELLO__");
+ __isConnected = true;
+ }
+
+ return res;
+}
+
+result
+ChatFrm::StartChat(void)
+{
+ result res = E_SUCCESS;
+
+ if (__isTcp)
+ {
+ res = CreateSocket(NET_SOCKET_TYPE_STREAM, NET_SOCKET_PROTOCOL_TCP);
+ }
+ else
+ {
+ res = CreateSocket(NET_SOCKET_TYPE_DATAGRAM, NET_SOCKET_PROTOCOL_UDP);
+ }
+
+ TryReturn(res == E_SUCCESS, res, "Error in creating Socket %d", res);
+
+ __isConstructed = true;
+
+ if (__isServer)
+ {
+ res = SocketServer();
+ }
+ else
+ {
+ res = SocketClient();
+ }
+
+ return res;
+}
+
+void
+ChatFrm::OnSocketAccept(Socket& socket)
+{
+ result res = E_SUCCESS;
+ AppLog("OnSocketAccept");
+
+ if (__pTcpSocket != null)
+ {
+ socket.Close();
+ AppLog("Already Connected with one Client");
+ return;
+ }
+
+ EnableControl(true);
+ __isConnected = true;
+ __pFooter->SetItemEnabled(0, true);
+
+ Socket* pSocket = const_cast< Socket* >(&socket);
+ __pTcpSocket = __pSocket;
+
+ // Accept the connection attempt.
+ __pSocket = pSocket->AcceptN();
+ if (__pSocket == null)
+ {
+ AppLog("Socket Accept Failed");
+ return;
+ }
+
+ // Add Socket Listener to listen to socket event.
+ res = __pSocket->AddSocketListener(*this);
+ if (IsFailed(res))
+ {
+ AppLog("Socket AddSocketListener failed %d", res);
+ }
+
+ // Set the socket as select an interested event.
+ res = __pSocket->AsyncSelectByListener(NET_SOCKET_EVENT_WRITE | NET_SOCKET_EVENT_READ | NET_SOCKET_EVENT_CLOSE);
+ if (IsFailed(res))
+ {
+ AppLog("Socket AsyncSelectByListener failed %d", res);
+ }
+}
+
+void
+ChatFrm::OnSocketClosed(Socket& socket, NetSocketClosedReason reason)
+{
+ AppLog("OnSocketClosed");
+ AppLog(GetErrorMessage(GetLastResult()));
+ AppLog("Reasoning %d", reason);
+
+ OnClose();
+ AppLog("Close Socket");
+
+ EnableControl(false);
+
+ WaitAndHidePopup();
+
+ SceneManager* pSceneManager = SceneManager::GetInstance();
+ AppAssert(pSceneManager);
+
+ pSceneManager->GoBackward(BackwardSceneTransition(SCENE_MAIN_MENU));
+}
+
+void
+ChatFrm::OnSocketConnected(Socket& socket)
+{
+ AppLog("OnSocketConnected");
+ EnableControl(true);
+ __isConnected = true;
+ __pFooter->SetItemEnabled(0, true);
+}
+
+void
+ChatFrm::OnSocketReadyToReceive(Socket& socket)
+{
+ AppLog("OnSocketReadyToReceive");
+ ReceiveData();
+}
+
+void
+ChatFrm::OnSocketReadyToSend(Socket& socket)
+{
+ AppLog("OnSocketReadyToSend");
+}
+
+result
+ChatFrm::SendDataCommand(String command)
+{
+ ByteBuffer* pTxBuffer = null;
+ ByteBuffer buffer;
+ result res = E_SUCCESS;
+
+ TryReturn(__isTcp == false, E_SYSTEM, "Sending Command not required for TCP connection");
+
+ pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(command);
+ TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer");
+
+ buffer.Construct(1024);
+ buffer.CopyFrom(*pTxBuffer);
+ delete pTxBuffer;
+
+ buffer.Flip();
+ do
+ {
+ if (!__isServer)
+ {
+ // Create a peer end point
+ if (__pClientIp != null)
+ {
+ NetEndPoint peerEndPoint(*__pClientIp, __port);
+ res = __pSocket->SendTo(buffer, peerEndPoint);
+ }
+ }
+ else
+ {
+ if (__pUdpEndpoint != null)
+ {
+ // Create socket
+ res = __pSocket->SendTo(buffer, *__pUdpEndpoint);
+ }
+ }
+
+ if (res == E_WOULD_BLOCK)
+ {
+ AppLog("Would block for data sending will try to retransmit");
+ Tizen::Base::Runtime::Thread::Sleep(500);
+ }
+ else if (res != E_SUCCESS)
+ {
+ AppLog("Error sending data");
+ break;
+ }
+ else
+ {
+ AppLog("Command successfully sent");
+ break;
+ }
+ }
+ while (1);
+
+ AppLog("Loop completed");
+ buffer.Clear();
+
+ return res;
+}
+
+result
+ChatFrm::SendData(void)
+{
+ String data;
+ ByteBuffer* pTxBuffer = null;
+ ByteBuffer buffer;
+ result res = E_SUCCESS;
+
+ data = __pEditFieldtext->GetText();
+ AppLog("String length is %d", data.GetCapacity());
+ if (data.IsEmpty())
+ {
+ AppLog("There is no data to send");
+ return E_SUCCESS;
+ }
+
+ pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(data);
+ TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer");
+
+ AppLog("Text Length %d", pTxBuffer->GetLimit());
+
+ buffer.Construct(pTxBuffer->GetLimit());
+ buffer.CopyFrom(*pTxBuffer);
+ buffer.Flip();
+ delete pTxBuffer;
+
+ if (__isTcp)
+ {
+ res = __pSocket->Send(buffer);
+ }
+ else if (!__isTcp)
+ {
+ if (!__isServer)
+ {
+ // Create a peer end point
+ NetEndPoint peerEndPoint(*__pClientIp, __port);
+ res = __pSocket->SendTo(buffer, peerEndPoint);
+ }
+ else
+ {
+ if (__pUdpEndpoint != null)
+ {
+ res = __pSocket->SendTo(buffer, *__pUdpEndpoint);
+ }
+ }
+ }
+
+ if (res == E_SUCCESS || res == E_WOULD_BLOCK)
+ {
+ data.Append(L"\n");
+ __pEditAreaData->AppendText(data);
+ __pEditAreaData->RequestRedraw();
+ __pEditFieldtext->SetText(L"");
+ __pEditFieldtext->RequestRedraw();
+ }
+ else
+ {
+ AppLog("Error sending data");
+ }
+
+ buffer.Clear();
+
+ return res;
+}
+
+result
+ChatFrm::DisplayText(ByteBuffer& txBuffer, unsigned long buflen)
+{
+ String data;
+ char* pBuffer = null;
+ result res = E_SUCCESS;
+
+ txBuffer.Flip();
+ pBuffer = (char*) (txBuffer.GetPointer());
+ data.SetCapacity(buflen + 2);
+
+ res = data.Append(pBuffer);
+ TryReturn(res == E_SUCCESS, res, "Append Failed");
+
+ txBuffer.Clear();
+
+ if (data == L"__HELLO__")
+ {
+ EnableControl(true);
+ __isConnected = true;
+ return res;
+ }
+
+ if (__isConnected == false)
+ {
+ AppLog("Server hasn't received Initial message so all incoming content is discarded");
+ // Remove created NetEndPoint
+ delete __pUdpEndpoint;
+ __pUdpEndpoint = null;
+ return res;
+ }
+
+ if (data == L"__CLOSE__")
+ {
+ SceneManager* pSceneManager = SceneManager::GetInstance();
+ AppAssert(pSceneManager);
+
+ pSceneManager->GoBackward(BackwardSceneTransition(SCENE_MAIN_MENU));
+
+ OnClose();
+ return res;
+ }
+
+ data.Append(L"\n");
+ res = __pEditAreaData->AppendText(data);
+ TryReturn(res == E_SUCCESS, res, "AppendText Failed");
+
+ __pEditAreaData->RequestRedraw();
+
+ return res;
+}
+
+result
+ChatFrm::ReceiveDataUDP(void)
+{
+ result res = E_SUCCESS;
+ ByteBuffer txBuffer;
+ unsigned long buflen = 0;
+
+ // Get the size of data received
+ __pSocket->Ioctl(NET_SOCKET_FIONREAD, buflen);
+
+ txBuffer.Construct(buflen + 1);
+
+ Ip4Address peerAddr1(NET_SOCKET_INADDR_ANY);
+ unsigned short port = 0;
+ NetEndPoint point(peerAddr1, port);
+
+ res = __pSocket->ReceiveFrom(txBuffer, point);
+ if (__pUdpEndpoint == null)
+ {
+ __pUdpEndpoint = new (std::nothrow) NetEndPoint(point);
+ }
+ else
+ {
+ if (__pUdpEndpoint->GetNetEndPoint() != point.GetNetEndPoint())
+ {
+ AppLog("It's a data from other endpoint so discard");
+ return res;
+ }
+ }
+
+ TryReturn(res == E_SUCCESS, res, "Receive Failed %d", res);
+
+ res = DisplayText(txBuffer, buflen);
+ txBuffer.Clear();
+
+ return res;
+}
+
+result
+ChatFrm::ReceiveDataTCP(void)
+{
+ result res = E_SUCCESS;
+ ByteBuffer txBuffer;
+ String data;
+ unsigned long buflen = 0;
+
+ // Get the size of data received
+ __pSocket->Ioctl(NET_SOCKET_FIONREAD, buflen);
+
+ txBuffer.Construct(buflen + 1);
+
+ res = __pSocket->Receive(txBuffer);
+ TryReturn(res == E_SUCCESS, res, "Receive Failed");
+
+ res = DisplayText(txBuffer, buflen);
+ txBuffer.Clear();
+
+ return res;
+}
+
+result
+ChatFrm::ReceiveData(void)
+{
+ result res = E_SUCCESS;
+
+ if (__isTcp)
+ {
+ res = ReceiveDataTCP();
+ }
+ else
+ {
+ res = ReceiveDataUDP();
+ }
+
+ return res;
+}
+
+void
+ChatFrm::OnClose(void)
+{
+ result res = E_SUCCESS;
+ AppLog("Socket Close Received");
+
+ if (__isConstructed)
+ {
+ if (__pSocket != null)
+ {
+ SendDataCommand(L"__CLOSE__");
+
+ res = __pSocket->RemoveSocketListener(*this);
+ if (IsFailed(res))
+ {
+ AppLog("RemoveSocketListener failed %d", res);
+ }
+
+ __pSocket->Close();
+ }
+
+ if (__pTcpSocket != null)
+ {
+ __pTcpSocket->Close();
+ }
+ }
+
+ delete __pSocket;
+ delete __pTcpSocket;
+ delete __pUdpEndpoint;
+
+ __pUdpEndpoint = null;
+ __pSocket = null;
+ __pTcpSocket = null;
+ __isConnected = false;
+ __isConstructed = false;
+}
+
+void
+ChatFrm::EnableControl(bool val)
+{
+ if (val)
+ {
+ __pLabelWait->SetShowState(false);
+ __pEditAreaData->SetEnabled(true);
+ __pEditAreaData->SetShowState(true);
+ __pLabelWait->RequestRedraw(true);
+ }
+ else
+ {
+ __pLabelWait->SetShowState(true);
+ __pEditAreaData->SetEnabled(false);
+ __pEditAreaData->SetShowState(false);
+ __pLabelWait->RequestRedraw(true);
+ }
+
+ __pEditFieldtext->SetEnabled(val);
+
+ __pForm->RequestRedraw();
+ __pEditFieldtext->RequestRedraw();
+ __pEditAreaData->SetKeypadEnabled(false);
+ __pEditAreaData->RequestRedraw();
+}
+
+void
+ChatFrm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
+ const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
+{
+ AppLog("ChatFrm::OnSceneActivatedN");
+
+ Ip4Address* pAddress = null;
+
+ if (pArgs != null)
+ {
+ if (pArgs->GetCount())
+ {
+ Boolean* pServer = dynamic_cast<Boolean*>(pArgs->GetAt(0));
+ TryCatch(pServer != null, , "Failed to retrieve the client/server from the Array list.");
+
+ __isServer = pServer->ToBool();
+
+ if (__isServer)
+ {
+ Integer* pPort = dynamic_cast<Integer*>(pArgs->GetAt(1));
+ TryCatch(pPort != null, , "Failed to retrieve the port number from the Array list.");
+
+ __port = pPort->ToInt();
+
+ Boolean* pProtocol = dynamic_cast<Boolean*>(pArgs->GetAt(2));
+ TryCatch(pProtocol != null, , "Failed to retrieve the protocol type from the Array list.");
+
+ __isTcp = pProtocol->ToBool();
+ }
+ else
+ {
+ pAddress = dynamic_cast<Ip4Address*>(pArgs->GetAt(1));
+ TryCatch(pAddress !=null, , "Failed to retrieve the Ipaddress from the Array list.");
+
+ Integer* pPort = dynamic_cast<Integer*>(pArgs->GetAt(2));
+ TryCatch(pPort != null, , "Failed to retrieve the port number from the Array list.");
+
+ __port = pPort->ToInt();
+
+ Boolean* pProtocol = dynamic_cast<Boolean*>(pArgs->GetAt(3));
+ TryCatch(pProtocol != null, , "Failed to retrieve the protocol type from the Array list.");
+
+ __isTcp = pProtocol->ToBool();
+ }
+ }
+
+ if (!__isTcp)
+ {
+ __pFooter = GetFooter();
+
+ __pFooter->SetItemEnabled(0, true);
+ }
+
+ if (!__isServer)
+ {
+ __pClientIp = new (std::nothrow) Ip4Address(*pAddress);
+ }
+ else
+ {
+ __pClientIp = null;
+ }
+
+ StartChat();
+ }
+
+CATCH:
+ pArgs->RemoveAll(true);
+ delete pArgs;
+}
+
+void
+ChatFrm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
+ const Tizen::Ui::Scenes::SceneId& nextSceneId)
+{
+ AppLog("ChatFrm::OnSceneDeactivated");
+}
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include <new>
+#include "FormFactory.h"
+#include "MainFrm.h"
+#include "ChatFrm.h"
+
+using namespace Tizen::Ui;
+using namespace Tizen::Ui::Controls;
+using namespace Tizen::Ui::Scenes;
+
+const wchar_t* FORM_MAIN_MENU = L"FormMainMenu";
+const wchar_t* FORM_CHAT_MENU = L"FormChatMenu";
+
+FormFactory::FormFactory(void)
+{
+}
+
+FormFactory::~FormFactory(void)
+{
+}
+
+Tizen::Ui::Controls::Form*
+FormFactory::CreateFormN(const Tizen::Base::String& formId, const Tizen::Ui::Scenes::SceneId& sceneId)
+{
+ Tizen::Ui::Controls::Form* pNewForm = null;
+ SceneManager* pSceneManager = SceneManager::GetInstance();
+ AppAssert(pSceneManager);
+
+ if (formId == FORM_MAIN_MENU)
+ {
+ MainFrm* pMainFrm = new (std::nothrow) MainFrm();
+ pMainFrm->Initialize();
+ pNewForm = pMainFrm;
+ }
+ else if (formId == FORM_CHAT_MENU)
+ {
+ ChatFrm* pChatForm = new (std::nothrow) ChatFrm();
+ if (pChatForm == null)
+ {
+ int result;
+ MessageBox* pMsgBox = new (std::nothrow) MessageBox();
+ pMsgBox->Construct(L"Error", L"Error in allocating Memory", MSGBOX_STYLE_OK);
+ pMsgBox->ShowAndWait(result);
+ delete pMsgBox;
+ }
+
+ pChatForm->Initialize();
+ AppLog("Initialize :Exit");
+ pSceneManager->AddSceneEventListener(sceneId, *pChatForm);
+ pNewForm = pChatForm;
+ }
+ return pNewForm;
+}
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "SocketChat.h"
+#include "FormFactory.h"
+#include "MainFrm.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Ui;
+using namespace Tizen::Ui::Controls;
+using namespace Tizen::Ui::Scenes;
+using namespace Tizen::Net;
+using namespace Tizen::System;
+
+static const int IDC_CHECKServer_SEL = 102;
+static const int IDC_CHECKServer_UNSEL = 103;
+static const int ID_START = 104;
+static const int ID_BUTTON_CLOSE = 107;
+static const int PORT_MIN = 1024;
+static const int PORT_MAX = 49151;
+
+MainFrm::MainFrm(void)
+ : __pButtonServer(null)
+ , __pButtonTcp(null)
+ , __pButtonUdp(null)
+ , __pEditIPAddress(null)
+ , __pEditPort(null)
+ , __pClientIp(null)
+ , __iport(0)
+ , __isProtocol(null)
+ , __isServer(null)
+ , __pChatForm(null)
+{
+}
+
+MainFrm::~MainFrm(void)
+{
+}
+
+bool
+MainFrm::Initialize(void)
+{
+ // Construct an XML form
+ Construct(L"IDF_MAINFRM");
+
+ return true;
+}
+
+result
+MainFrm::OnInitializing(void)
+{
+ result r = E_SUCCESS;
+
+ // Get a button via resource ID
+ __pButtonServer = static_cast< CheckButton* >(GetControl(L"IDC_CHECKServer"));
+
+ if (__pButtonServer != null)
+ {
+ __pButtonServer->SetActionId(IDC_CHECKServer_SEL, IDC_CHECKServer_UNSEL);
+ __pButtonServer->AddActionEventListener(*this);
+ }
+
+ __pButtonTcp = static_cast< CheckButton* >(GetControl(L"IDC_CHECKTCP"));
+ __pButtonUdp = static_cast< CheckButton* >(GetControl(L"IDC_CHECKUDP"));
+
+ __pEditIPAddress = static_cast< EditField* >(GetControl(L"IDC_EDITIPaddress"));
+ if (__pEditIPAddress == null)
+ {
+ r = E_FAILURE;
+ }
+
+ __pEditPort = static_cast< EditField* >(GetControl(L"IDC_EDITPort"));
+
+ Footer* pFooter = GetFooter();
+ if (pFooter != null)
+ {
+ pFooter->SetStyle(FOOTER_STYLE_BUTTON_TEXT);
+
+ __footerItem_Left.Construct(ID_START);
+ __footerItem_Left.SetText(L"Connect");
+ pFooter->AddItem(__footerItem_Left);
+ pFooter->AddActionEventListener(*this);
+ }
+
+ SetDefaultValues();
+
+ return r;
+}
+
+void
+MainFrm::SetDefaultValues(void)
+{
+ if (__pButtonTcp != null)
+ {
+ __pButtonTcp->SetSelected(true);
+ }
+}
+
+result
+MainFrm::OnTerminating(void)
+{
+ result r = E_SUCCESS;
+
+ AppLog("MainFrm::OnTerminating");
+
+ return r;
+}
+
+void
+MainFrm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
+{
+ switch (actionId)
+ {
+ case IDC_CHECKServer_UNSEL:
+ {
+ AppLog("Server Button unselected");
+ __pEditIPAddress->SetEnabled(true);
+ __pEditIPAddress->RequestRedraw(true);
+ Footer* pFooter = GetFooter();
+ pFooter->RemoveItemAt(0);
+ __footerItem_Left.SetText(L"Connect");
+ pFooter->InsertItemAt(0, __footerItem_Left);
+ Draw();
+ }
+ break;
+
+ case IDC_CHECKServer_SEL:
+ {
+ AppLog("Server button selected");
+
+ __pEditIPAddress->SetEnabled(false);
+ __pEditIPAddress->RequestRedraw(true);
+ this->SetFocus();
+ Footer* pFooter = GetFooter();
+ pFooter->RemoveItemAt(0);
+ __footerItem_Left.SetText(L"Listen");
+ pFooter->InsertItemAt(0, __footerItem_Left);
+ Draw();
+ }
+ break;
+
+ case ID_START:
+ {
+ AppLog("Start Button is clicked! \n");
+ StartChat();
+ }
+ break;
+
+ case ID_BUTTON_CLOSE:
+ {
+ AppLog("Back Button pressed, close application now");
+ Application::GetInstance()->Terminate();
+ }
+ break;
+
+ default:
+ AppLog("default");
+ break;
+ }
+}
+
+void
+MainFrm::StartChat(void)
+{
+ result r = E_SUCCESS;
+
+ String port;
+ // Get protocol type
+ __isProtocol = __pButtonTcp->IsSelected();
+
+ // Get connection type
+ __isServer = __pButtonServer->IsSelected();
+
+ if (!__isServer)
+ {
+ // Get ipAddress and port
+ String ipAddress;
+ ipAddress = __pEditIPAddress->GetText();
+
+ if (ipAddress.IsEmpty() == true)
+ {
+ int result;
+ MessageBox* pMsgBox = new (std::nothrow) MessageBox();
+ pMsgBox->Construct(L"IP Address", L"Please enter IP address", MSGBOX_STYLE_OK);
+ pMsgBox->ShowAndWait(result);
+ delete pMsgBox;
+ return;
+ }
+ else
+ {
+ __pClientIp = new (std::nothrow) Ip4Address(ipAddress);
+
+ r = GetLastResult();
+ if (IsFailed(r) || __pClientIp == null)
+ {
+ int result;
+ MessageBox* pMsgBox = new (std::nothrow) MessageBox();
+ pMsgBox->Construct(L"IP Address", L"Invalid IP address", MSGBOX_STYLE_OK);
+ pMsgBox->ShowAndWait(result);
+ delete pMsgBox;
+ return;
+ }
+ }
+ }
+
+ port = __pEditPort->GetText();
+ if (port.IsEmpty())
+ {
+ int result;
+ MessageBox* pMsgBox = new (std::nothrow) MessageBox();
+ pMsgBox->Construct(L"Port", L"Enter Valid User Port Number", MSGBOX_STYLE_OK);
+ pMsgBox->ShowAndWait(result);
+ delete pMsgBox;
+ return;
+ }
+ else
+ {
+ int result;
+ __iport = -1;
+ r = Tizen::Base::Integer::Decode(port, __iport);
+ AppLog("Port No is %d", __iport);
+ if (__iport < PORT_MIN || __iport > PORT_MAX || r != E_SUCCESS)
+ {
+ MessageBox* pMsgBox = new (std::nothrow) MessageBox();
+ pMsgBox->Construct(L"Port", L"Enter Valid User Port Number", MSGBOX_STYLE_OK);
+ pMsgBox->ShowAndWait(result);
+ delete pMsgBox;
+ return;
+ }
+ }
+
+ if (__pChatForm != null)
+ {
+ delete __pChatForm;
+ __pChatForm = null;
+ }
+
+ SceneManager* pSceneManager = SceneManager::GetInstance();
+ AppAssert(pSceneManager);
+
+ ArrayList* pList = new (std::nothrow) ArrayList;
+ AppAssert(pList);
+
+ r = pList->Construct();
+ TryCatch(r == E_SUCCESS, , "Failed to construct the Array list.");
+
+ r = pList->Add(*(new (std::nothrow) Boolean(__isServer)));
+ TryCatch(r == E_SUCCESS, , "Failed to add the client/server to the Array list.");
+
+ if (!__isServer)
+ {
+ r = pList->Add(*(new (std::nothrow) Ip4Address(*__pClientIp)));
+ TryCatch(r == E_SUCCESS, , "Failed to add ipAddress to the Array list.");
+ }
+
+ r = pList->Add(*(new (std::nothrow) Integer(__iport)));
+ TryCatch(r == E_SUCCESS, , "Failed to add port number to the Array list.");
+
+ r = pList->Add(*(new (std::nothrow) Boolean(__isProtocol)));
+ TryCatch(r == E_SUCCESS, , "Failed to add the protocol to the Array list.");
+
+ pSceneManager->GoForward(ForwardSceneTransition(SCENE_CHAT_MENU), pList);
+
+
+CATCH:
+ if (__pClientIp != null)
+ {
+ delete __pClientIp;
+ __pClientIp = null;
+ }
+}
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#include "SocketChat.h"
+#include "FormFactory.h"
+#include "MainFrm.h"
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::System;
+using namespace Tizen::Ui::Controls;
+using namespace Tizen::Ui::Scenes;
+
+const wchar_t* SCENE_MAIN_MENU = L"MainScene";
+const wchar_t* SCENE_CHAT_MENU = L"ChatScene";
+
+SocketChat::SocketChat(void)
+{
+}
+
+SocketChat::~SocketChat(void)
+{
+}
+
+Application*
+SocketChat::CreateInstance(void)
+{
+ // Create the instance through the constructor.
+ return new (std::nothrow) SocketChat();
+}
+
+bool
+SocketChat::OnAppInitializing(AppRegistry& appRegistry)
+{
+ static const wchar_t* PANEL_BLANK = L"";
+ static FormFactory formFactory;
+
+ Frame* pAppFrame = new (std::nothrow) Frame();
+
+ pAppFrame->Construct();
+ AddFrame(*pAppFrame);
+
+ // SceneManagement initializing
+ SceneManager* pSceneManager = SceneManager::GetInstance();
+ AppAssert(pSceneManager);
+
+ pSceneManager->RegisterFormFactory(formFactory);
+
+ pSceneManager->RegisterScene(SCENE_MAIN_MENU, FORM_MAIN_MENU, PANEL_BLANK);
+
+ pSceneManager->RegisterScene(SCENE_CHAT_MENU, FORM_CHAT_MENU, PANEL_BLANK);
+
+ // Go to the scene.
+ if (pSceneManager->GoForward(ForwardSceneTransition(SCENE_MAIN_MENU)) != E_SUCCESS)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool
+SocketChat::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
+{
+ return true;
+}
+
+void
+SocketChat::OnForeground(void)
+{
+}
+
+void
+SocketChat::OnBackground(void)
+{
+}
+
+void
+SocketChat::OnLowMemory(void)
+{
+}
+
+void
+SocketChat::OnBatteryLevelChanged(BatteryLevel batteryLevel)
+{
+}
+
+void
+SocketChat::OnScreenOn(void)
+{
+}
+
+void
+SocketChat::OnScreenOff(void)
+{
+}
--- /dev/null
+//
+// Tizen Native SDK
+// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * This file contains the Tizen application entry point.
+ */
+#include <new>
+#include "SocketChat.h"
+
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+_EXPORT_ int OspMain(int argc, char* pArgv[]);
+
+/**
+ * The entry function of Tizen application called by the operating system.
+ */
+int
+OspMain(int argc, char* pArgv[])
+{
+ AppLog("Application started.");
+ ArrayList args;
+ args.Construct();
+ for (int i = 0; i < argc; i++)
+ {
+ args.Add(*(new (std::nothrow) String(pArgv[i])));
+ }
+
+ result r = Tizen::App::Application::Execute(SocketChat::CreateInstance, &args);
+ TryLog(r == E_SUCCESS, "[%s] Application execution failed", GetErrorMessage(r));
+
+ args.RemoveAll(true);
+ AppLog("Application finished.");
+
+ return static_cast<int>(r);
+}
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<template>
+
+ <slp-property>
+ <property-group>
+ <sample-name>SocketChat</sample-name>
+ <category>Sample</category>
+ <sdk-version>1.00</sdk-version>
+ <project-type>org.tizen.nativecpp.buildArtefactType.app</project-type>
+ <sample-description>description.xml</sample-description>
+ </property-group>
+ </slp-property>
+
+ <process type="org.tizen.nativeappcommon.TizenCopyFolder">
+ <simple name="projectName" value="$(projectName)"/>
+ <simple name="folderPath" value="project"/>
+ <complex-array name="replaceableFiles">
+ <element>
+ <simple name="sourcePath" value="manifest.xml"/>
+ <simple name="targetPath" value="manifest.xml"/>
+ <simple name="replaceable" value = "true"/>
+ </element>
+ </complex-array>
+ </process>
+ <process type="org.tizen.nativecpp.SetDefaultFrameworks">
+ <simple name="projectName" value="$(projectName)"/>
+ <complex-array name="frameworkList">
+ <element>
+ <simple name="framework" value="osp"/>
+ </element>
+ </complex-array>
+ </process>
+
+</template>