Refactor AppRegistry to support multi-thread concurrency
[platform/framework/native/appfw.git] / src / io / FIoFileEventManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FIoFileiEventManager.cpp
19  * @brief       This is the implementation file for FileEventManager class.
20  */
21
22 #include <new>
23 #include <unique_ptr.h>
24
25 #include <FBaseSysLog.h>
26 #include <FIoFileEventManager.h>
27 #include <FIoIFileEventListener.h>
28
29 #include <FIo_FileEventManagerImpl.h>
30
31 using namespace Tizen::Base;
32
33 namespace Tizen { namespace Io
34 {
35 FileEventManager::FileEventManager(void)
36         : __pFileEventManagerImpl(null)
37 {
38 }
39
40 FileEventManager::~FileEventManager(void)
41 {
42         delete __pFileEventManagerImpl;
43 }
44
45 result
46 FileEventManager::Construct(IFileEventListener& listener)
47 {
48         SysAssertf(__pFileEventManagerImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
49
50         result r = E_SUCCESS;
51         std::unique_ptr<_FileEventManagerImpl> pFileEventManagerImpl(new (std::nothrow) _FileEventManagerImpl);
52         SysTryReturnResult(NID_IO, pFileEventManagerImpl, E_OUT_OF_MEMORY, "The memory is insufficient.");
53
54         r = pFileEventManagerImpl->Construct(listener);
55         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
56
57         __pFileEventManagerImpl = pFileEventManagerImpl.release();
58
59         return E_SUCCESS;
60 }
61
62 result
63 FileEventManager::AddPath(const String& path, unsigned long eventsToMonitor)
64 {
65         result r = E_SUCCESS;
66         SysAssertf(__pFileEventManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
67         r = __pFileEventManagerImpl->AddPath(path, eventsToMonitor);
68
69         if (r == E_FILE_NOT_FOUND)
70         {
71                 SysLogException(NID_IO, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] An entry for the specified path[%ls] could not be found.", path.GetPointer());
72         }
73         else if (r == E_ILLEGAL_ACCESS)
74         {
75                 SysLogException(NID_IO, E_ILLEGAL_ACCESS, "[E_ILLEGAL_ACCESS] The specified path is not permitted.");
76         }
77         else if (r == E_INVALID_ARG)
78         {
79                 SysLogException(NID_IO, E_INVALID_ARG, "[E_INVALID_ARG] The specified eventsToMonitor contains no valid events.");
80         }
81         else if (r == E_IO)
82         {
83                 SysLogException(NID_IO, E_IO, "[E_IO] I/O error is occurred.");
84         }
85         return r;
86 }
87
88 result
89 FileEventManager::RemovePath(const String& path)
90 {
91         result r = E_SUCCESS;
92         SysAssertf(__pFileEventManagerImpl != null, "Not yet constructed. Construct() should be called before use.\n");
93         r = __pFileEventManagerImpl->RemovePath(path);
94
95         if (r == E_IO)
96         {
97                 SysLogException(NID_IO, E_IO, "[E_IO] I/O error is occurred.");
98         }
99         return r;
100 }
101
102 }} // Tizen::Io
103