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://www.apache.org/licenses/LICENSE-2.0
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 FIoMemoryMappedFile.cpp
20 * @brief This is the implementation file for MemoryMappedFile class.
24 #include <unique_ptr.h>
26 #include <FBaseSysLog.h>
28 #include <FIoMemoryMappedFile.h>
30 #include "FIo_MemoryMappedFileImpl.h"
32 namespace Tizen { namespace Io
35 MemoryMappedFile::MemoryMappedFile(void)
36 : __pMemoryMappedFileImpl(null)
40 MemoryMappedFile::~MemoryMappedFile(void)
42 delete __pMemoryMappedFileImpl;
46 MemoryMappedFile::Construct(const File& file)
50 SysAssertf(__pMemoryMappedFileImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
52 std::unique_ptr<_MemoryMappedFileImpl> pMemoryMappedFileImpl(new (std::nothrow) _MemoryMappedFileImpl);
53 SysTryReturnResult(NID_IO, pMemoryMappedFileImpl != null, E_OUT_OF_MEMORY,
54 "The memory is insufficient.");
56 r = pMemoryMappedFileImpl->Construct(file);
57 SysTryReturn(NID_IO, !(IsFailed(r)), r, r, "[%s] Propagated.", GetErrorMessage(r));
59 __pMemoryMappedFileImpl = pMemoryMappedFileImpl.release();
65 MemoryMappedFile::Map(void* address, long long length, unsigned long protection, unsigned long flag, long long offset)
67 SysAssertf(__pMemoryMappedFileImpl != null, "Not yet constructed. Construct() should be called before use.\n");
68 SysTryReturn(NID_IO, length > 0, null, E_INVALID_ARG,
69 "[E_INVALID_ARG] The specified length parameter is not positive.");
70 SysTryReturn(NID_IO, flag != (MEMORY_MAPPED_FILE_FLAG_PRIVATE | MEMORY_MAPPED_FILE_FLAG_SHARED), null, E_INVALID_ARG,
71 "[E_INVALID_ARG] The specified flag parameter is invalid.");
73 if ((address == null) && (flag & MEMORY_MAPPED_FILE_FLAG_FIXED) == MEMORY_MAPPED_FILE_FLAG_FIXED)
75 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified address or flag parameter is invalid.");
78 else if ((address != null) && (flag & MEMORY_MAPPED_FILE_FLAG_FIXED) == 0x0)
80 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified address or flag parameter is invalid.");
84 return __pMemoryMappedFileImpl->Map(address, length, protection, flag, offset);
88 MemoryMappedFile::Unmap(void* address, long long length)
90 SysAssertf(__pMemoryMappedFileImpl != null, "Not yet constructed. Construct() should be called before use.\n");
91 SysTryReturnResult(NID_IO, length > 0, E_INVALID_ARG,
92 "The specified length parameter is not positive.");
93 return __pMemoryMappedFileImpl->Unmap(address, length);
97 MemoryMappedFile::Sync(void* address, long long length, MemoryMappedFileSyncFlag syncFlag)
99 SysAssertf(__pMemoryMappedFileImpl != null, "Not yet constructed. Construct() should be called before use.\n");
100 SysTryReturnResult(NID_IO, length > 0, E_INVALID_ARG,
101 "The specified length parameter is not positive.");
102 SysTryReturnResult(NID_IO, (syncFlag == MEMORY_MAPPED_FILE_SYNC_FLAG_SYNC || syncFlag == MEMORY_MAPPED_FILE_SYNC_FLAG_ASYNC),
103 E_INVALID_ARG, "The specified syncFlag parameter is invalid.");
105 return __pMemoryMappedFileImpl->Sync(address, length, syncFlag);