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://www.apache.org/licenses/LICENSE-2.0
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 FBaseRt_LibraryImpl.cpp
19 * @brief This is the implementation file for the _LibraryImpl class.
26 #include <FBaseUtilStringUtil.h>
27 #include <FBaseSysLog.h>
28 #include "FBase_StringConverter.h"
29 #include "FBaseRt_LibraryImpl.h"
32 namespace Tizen { namespace Base { namespace Runtime
35 _LibraryImpl::_LibraryImpl(void)
40 _LibraryImpl::~_LibraryImpl(void)
42 if (__pHandle != null)
49 _LibraryImpl::Construct(const Tizen::Base::String& dllPath, unsigned long option)
52 char* pLibPath = null;
55 SysTryReturnResult(NID_BASE_RT, __pHandle == null, E_INVALID_STATE,
56 "Library has already has been loaded.");
58 SysTryReturnResult(NID_BASE_RT, !dllPath.IsEmpty(), E_INVALID_ARG, "Specified path is null string.");
60 if (option & _LIBRARY_LOAD_OPTION_LAZY)
65 if (option & _LIBRARY_LOAD_OPTION_NOW)
67 SysTryReturnResult(NID_BASE_RT, flag != RTLD_LAZY, E_INVALID_ARG,
68 "_LIBRARY_LOAD_OPTION_LAZY and _LIBRARY_LOAD_OPTION_NOW must be included exclusively.");
73 SysTryReturnResult(NID_BASE_RT, flag != -1, E_INVALID_ARG,
74 "One of _LIBRARY_LOAD_OPTION_LAZY or _LIBRARY_LOAD_OPTION_NOW must be included.");
76 if (option & _LIBRARY_LOAD_OPTION_GLOBAL)
81 if (option & _LIBRARY_LOAD_OPTION_LOCAL)
83 SysTryReturnResult(NID_BASE_RT, (option & _LIBRARY_LOAD_OPTION_GLOBAL) == 0, E_INVALID_ARG,
84 "_LIBRARY_LOAD_OPTION_LAZY and _LIBRARY_LOAD_OPTION_NOW must be included exclusively.");
89 if (option & _LIBRARY_LOAD_OPTION_NODELETE)
91 flag |= RTLD_NODELETE;
94 pLibPath = _StringConverter::CopyToCharArrayN(dllPath);
95 SysTryReturnResult(NID_BASE_RT, pLibPath != null, E_OUT_OF_MEMORY, "Not enough memroy.");
97 __pHandle = dlopen(pLibPath, flag);
98 SysTryCatch(NID_BASE_RT, __pHandle != null, r = E_LIBRARY_NOT_FOUND, E_LIBRARY_NOT_FOUND,
99 "[E_LIBRARY_NOT_FOUND] Failed to load the library with reason: %s",
113 _LibraryImpl::GetProcAddress(const Tizen::Base::String& symbol)
115 result r = E_SUCCESS;
116 char* pSymName = null;
117 void* pSymAddr = null;
119 SysTryReturn(NID_BASE_RT, __pHandle != null, null, E_INVALID_ARG, "[E_INVALID_ARG] Library is not loaded.");
120 SysTryReturn(NID_BASE_RT, !symbol.IsEmpty(), null, E_INVALID_ARG,
121 "[E_INVALID_ARG] Specified path is null.");
123 pSymName = _StringConverter::CopyToCharArrayN(symbol);
124 SysTryCatch(NID_BASE_RT, pSymName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
126 pSymAddr = dlsym(__pHandle, pSymName);
127 SysTryCatch(NID_BASE_RT, pSymAddr != null, , E_SYMBOL_NOT_FOUND,
128 "[E_SYMBOL_NOT_FOUND] Failed to get a symbol address with reason : %s",
143 } } } // Tizen::Runtime