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