Merge "Update deprecated libprivilege-control API functions." into tizen
[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. @n
105           * 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 with the specified serial port event listener. @n
120          * If the specified port is open, @c 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 the specified data 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