sync with tizen_2.0
[platform/framework/native/appfw.git] / src / io / FIoSerialPort.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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.cpp
20  * @brief       This is the implementation file for SerialPort class.
21  */
22
23 #include <serial.h>
24
25 #include <FBaseSysLog.h>
26 #include <FIoSerialPort.h>
27 #include <FIoISerialPortEventListener.h>
28
29 #include <FBase_NativeError.h>
30
31 #include "FIo_SerialPortImpl.h"
32
33 using namespace Tizen::Base;
34
35 namespace Tizen { namespace Io
36 {
37
38 SerialPort::SerialPort(void)
39         : __pSerialPortImpl(null)
40 {
41 }
42
43 SerialPort::~SerialPort(void)
44 {
45 }
46
47 result
48 SerialPort::Construct(ISerialPortEventListener& listener)
49 {
50         SysAssertf(__pSerialPortImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
51
52         __pSerialPortImpl = new (std::nothrow) _SerialPortImpl(listener);
53         SysTryReturnResult(NID_IO, __pSerialPortImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
54
55         return E_SUCCESS;
56 }
57
58 result
59 SerialPort::Write(const ByteBuffer& byteBuffer)
60 {
61         SysAssertf(__pSerialPortImpl != null, "Not yet constructed. Construct() should be called before use.\n");
62
63         return __pSerialPortImpl->Write(byteBuffer);
64 }
65
66 int
67 SerialPort::GetWriteBufferSize(void) const
68 {
69         SysAssertf(__pSerialPortImpl != null, "Not yet constructed. Construct() should be called before use.\n");
70
71         return __pSerialPortImpl->GetWriteBufferSize();
72 }
73
74 } } // Tizen::Io