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