2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (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
8 // http://floralicense.org/license/
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.
18 * @file FIoSerialPort.cpp
19 * @brief This is the implementation file for SerialPort class.
24 #include <FBaseSysLog.h>
25 #include <FIoSerialPort.h>
26 #include <FIoISerialPortEventListener.h>
28 #include <FBase_NativeError.h>
30 #include "FIo_SerialPortImpl.h"
32 using namespace Tizen::Base;
34 namespace Tizen { namespace Io
37 SerialPort::SerialPort(void)
38 : __pSerialPortImpl(null)
42 SerialPort::~SerialPort(void)
45 if(__pSerialPortImpl != null)
47 if(__pSerialPortImpl->IsOpended() == true)
49 r = __pSerialPortImpl->SerialClose();
53 SysLogException(NID_SYS, E_SYSTEM, "SerialPort is not open.");
58 SysLogException(NID_SYS, E_SYSTEM, "SerialPort instance is not ready.");
63 SerialPort::Construct(ISerialPortEventListener& listener)
66 SysLog(NID_IO, "SerialPort Construct");
68 __pSerialPortImpl = _SerialPortImpl::GetInstance();
69 SysTryReturnResult(NID_IO, __pSerialPortImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
70 SysTryCatch(NID_IO, __pSerialPortImpl->IsOpended() == false, r = E_SYSTEM, r, "SerialPort is already opened.");
72 SysLog(NID_IO, "Try to open serialport");
73 r = __pSerialPortImpl->SerialOpen();
74 SysTryCatch(NID_IO, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to open serial port.");
76 SysLog(NID_IO, "Try to register event");
77 r = __pSerialPortImpl->SetSerialPortEventListener(listener);
80 SysLogException(NID_IO, E_SYSTEM, "It is failed to register event listener.");
81 r = __pSerialPortImpl->SerialClose();
82 SysTryCatch(NID_IO, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to close serial port.");
89 __pSerialPortImpl = null;
96 SerialPort::Write(const ByteBuffer& byteBuffer)
98 SysAssertf(__pSerialPortImpl != null, "Not yet constructed. Construct() should be called before use.\n");
99 SysTryReturnResult(NID_IO, __pSerialPortImpl->IsOpended() == true, E_SYSTEM, "SerialPort is not open.");
101 return __pSerialPortImpl->Write(byteBuffer);
105 SerialPort::GetWriteBufferSize(void) const
107 SysAssertf(__pSerialPortImpl != null, "Not yet constructed. Construct() should be called before use.\n");
108 return __pSerialPortImpl->GetWriteBufferSize();