312524fa3a7625c41cf9ff5f6872a94ffddf0884
[platform/framework/native/appfw.git] / inc / FIoSerialPort.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FIoSerialPort.h
19  * @brief               This is the header file for the %SerialPort class.
20  *
21  * This header file contains the declarations of the %SerialPort class.
22  */
23
24 #ifndef _FIO_SERIAL_PORT_H_
25 #define _FIO_SERIAL_PORT_H_
26
27 #include <FIo.h>
28
29 namespace Tizen { namespace Io
30 {
31
32 class ISerialPortEventListener;
33
34 /**
35  * @class       SerialPort
36  * @brief       This class provides an interface for controlling a serial port resource.
37  *
38  * @since 2.0
39  *
40  * @final       This class is not intended for extension.
41  *
42  * @remarks The serial communication feature is reset when the USB connection is broken or a host device sends the
43  * deactivate command. Any serial port options are not supported by the current version.
44  *
45  * The %SerialPort class provides an interface for controlling a serial port resource. @n
46  *
47  *  For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/io/serial_port_comm.htm">Serial Port Communication</a>.
48  *
49  *
50  * @see ISerialPortEventListener
51  *
52  * The following example demonstrates how to use the %SerialPort class.
53  *
54  * @code
55  * #include <FIo.h>
56  * #include <FBase.h>
57  *
58  * using namespace Tizen::Base;
59  * using namespace Tizen::Io;
60  *
61  * class SerialRecv
62  *      : public Tizen::Io::ISerialPortEventListener
63  * {
64  *      void OnSerialPortDataReceivedN(Tizen::Base::ByteBuffer& byteBuffer)
65  *      {
66  *            //Read data.
67  *      }
68  *
69  *      void OnSerialPortErrorOccured(result r)
70  *      {
71  *            //Check error status.
72  *      }
73  * }
74  * void
75  * MyClass::SerialPortSample(void)
76  * {
77  *      SerialPort serialPort;
78  *      ByteBuffer buf;
79  *      String szMessage = L"Hello";
80  *      SerialRecv listener;
81  *
82  *      buf.Construct(1024);
83  *      buf.SetArray(szMessage.GetPointer(), 0, 6);
84  *      buf.Flip();
85  *
86  *      //Construct serial port.
87  *      serialPort.Construct(listener);
88  *
89  *      //Write buf on output buffer.
90  *      serialPort.Write(buf);
91  *
92  * }
93  * @endcode
94  *
95  *
96  *
97  */
98 class _OSP_EXPORT_ SerialPort
99         : public Tizen::Base::Object
100 {
101
102 public:
103         /**
104           * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
105           *
106           * @since 2.0
107           */
108         SerialPort(void);
109
110         /**
111           * This destructor overrides Tizen::Base::Object::~Object().
112           *
113           * @since 2.0
114           */
115         virtual ~SerialPort(void);
116
117         /**
118          * Constructs a new serial port connection. @n
119          * If the specified port is open, E_SYSTEM is returned.
120          *
121          * @since       2.0
122          *
123          * @return                      An error code
124          * @param[in]   listener                The serial port event listener
125          * @exception   E_SUCCESS               The method is successful.
126          * @exception   E_SYSTEM        A system error has occurred.
127          */
128         result Construct(ISerialPortEventListener& listener);
129
130         /**
131          * Writes data to the output buffer synchronously.
132          *
133          * @since       2.0
134          *
135          * @return              An error code
136          * @param[in]   byteBuffer                                      A reference to the buffer that contains the string data to write
137          * @exception   E_SUCCESS                                       The method is successful.
138          * @exception   E_MAX_EXCEEDED   The buffer size has exceeded the maximum limit of the current device.
139          * @exception   E_SYSTEM                                A system error has occurred.
140          * @see GetWriteBufferSize()
141          */
142         result Write(const Tizen::Base::ByteBuffer& byteBuffer);
143
144         /**
145          * Gets the size of the write buffer.
146          *
147          * @since   2.0
148          *
149          * @return  The size of the write buffer
150          * @remarks     The size of the write buffer depends on the device.
151          */
152         int GetWriteBufferSize(void) const;
153
154 private:
155         /**
156         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
157         */
158         SerialPort(const SerialPort& serialPort);
159
160         /**
161         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
162         */
163         SerialPort& operator =(const SerialPort& serialPort);
164
165 private:
166         class _SerialPortImpl* __pSerialPortImpl;
167
168         friend class _SerialPortImpl;
169
170 }; // SerialPort
171
172 }} // Tizen::Io
173
174 #endif // _FIO_SERIAL_PORT_H_
175