2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FIoSerialPort.cpp
20 * @brief This is the implementation file for SerialPort class.
25 #include <FBaseSysLog.h>
26 #include <FIoSerialPort.h>
27 #include <FIoISerialPortEventListener.h>
29 #include <FBase_NativeError.h>
31 #include "FIo_SerialPortImpl.h"
33 using namespace Tizen::Base;
35 namespace Tizen { namespace Io
38 SerialPort::SerialPort(void)
39 : __pSerialPortImpl(null)
43 SerialPort::~SerialPort(void)
46 if(__pSerialPortImpl != null)
48 if(__pSerialPortImpl->IsOpended() == true)
50 r = __pSerialPortImpl->SerialClose();
54 SysLogException(NID_SYS, E_SYSTEM, "SerialPort is not open.");
59 SysLogException(NID_SYS, E_SYSTEM, "SerialPort instance is not ready.");
64 SerialPort::Construct(ISerialPortEventListener& listener)
67 SysLog(NID_IO, "SerialPort Construct");
69 __pSerialPortImpl = _SerialPortImpl::GetInstance();
70 SysTryReturnResult(NID_IO, __pSerialPortImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
71 SysTryReturnResult(NID_IO, __pSerialPortImpl->IsOpended() == false, E_SYSTEM, "SerialPort is already opened.");
73 SysLog(NID_IO, "Try to open serialport");
74 r = __pSerialPortImpl->SerialOpen();
75 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_SYSTEM, "It is failed to open serial port.");
77 SysLog(NID_IO, "Try to register event");
78 r = __pSerialPortImpl->SetSerialPortEventListener(listener);
81 SysLogException(NID_IO, E_SYSTEM, "It is failed to register event listener.");
82 r = __pSerialPortImpl->SerialClose();
83 SysTryReturnResult(NID_IO, r == E_SUCCESS, E_SYSTEM, "It is failed to close serial port.");
92 SerialPort::Write(const ByteBuffer& byteBuffer)
94 SysAssertf(__pSerialPortImpl != null, "Not yet constructed. Construct() should be called before use.\n");
95 SysTryReturnResult(NID_IO, __pSerialPortImpl->IsOpended() == true, E_SYSTEM, "SerialPort is not open.");
97 return __pSerialPortImpl->Write(byteBuffer);
101 SerialPort::GetWriteBufferSize(void) const
103 SysAssertf(__pSerialPortImpl != null, "Not yet constructed. Construct() should be called before use.\n");
105 return __pSerialPortImpl->GetWriteBufferSize();