Change not to construct classes in global
[platform/core/security/ode.git] / server / secure-erase.cpp
index fe72e10..e8b66ad 100644 (file)
 #include <klay/filesystem.h>
 #include <klay/audit/logger.h>
 
-#include "rmi/secure-erase.h"
-#include "progress-bar.h"
-#include "progress-vconf-backend.h"
-#include "block-device.h"
 #include "ext4-tool.h"
+#include "block-device.h"
+#include "progress-bar.h"
+#include "rmi/secure-erase.h"
+
+#define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
 
 namespace ode {
 
 namespace {
-VConfBackend vconfBackend(VCONFKEY_ODE_ERASE_PROGRESS);
-ProgressBar progressBar(std::bind(&VConfBackend::update, &vconfBackend, std::placeholders::_1));
+
+std::unique_ptr<ProgressBar> progressBar;
 
 static int totalFileCount = 0;
 static int erasedFileCount = 0;
@@ -70,8 +71,12 @@ static int getTotalFileCount(const std::string &name)
 SecureErase::SecureErase(ODEControlContext &ctx) :
        context(ctx), devicePath("")
 {
-       context.registerParametricMethod(this, "", (int)(SecureErase::erase)(std::string));
-       context.registerParametricMethod(this, "", (int)(SecureErase::clean)(std::string));
+       context.expose(this, PRIVILEGE_PLATFORM, (int)(SecureErase::erase)(std::string));
+       context.expose(this, PRIVILEGE_PLATFORM, (int)(SecureErase::clean)(std::string));
+
+       progressBar.reset(new ProgressBar([](int v) {
+               ::vconf_set_str(VCONFKEY_ODE_ERASE_PROGRESS, std::to_string(v).c_str());
+       }));
 }
 
 SecureErase::~SecureErase()
@@ -102,11 +107,11 @@ int SecureErase::erase(const std::string &name)
                                for (unsigned int i = 0; i < totalBlock; i++) {
                                        Block block(i * blockSize, blockSize);
                                        blockDevice.discard(block);
-                                       progressBar.update(i, totalBlock, 1);
+                                       progressBar->update(i, totalBlock, 1);
                                }
                        }
                        dropCachePage();
-                       progressBar.done();
+                       progressBar->done();
                } catch (runtime::Exception &e) {}
        };
 
@@ -139,10 +144,10 @@ int SecureErase::clean(const std::string &name)
                                        blockDevice.discard(block);
                                }
 
-                               progressBar.update(i, totalBlock, 1);
+                               progressBar->update(i, totalBlock, 1);
                        }
                        dropCachePage();
-                       progressBar.done();
+                       progressBar->done();
                } catch (runtime::Exception &e) {}
        };
 
@@ -195,7 +200,7 @@ int SecureErase::fileErase(const std::string &name)
                }
 
                if (totalFileCount == 1) {
-                       progressBar.update(i, extentBlockCount, 1);
+                       progressBar->update(i, extentBlockCount, 1);
                }
        }
 
@@ -216,7 +221,7 @@ int SecureErase::directoryErase(const std::string &name)
                        fileErase(next);
                        ::remove(next.c_str());
                        erasedFileCount++;
-                       progressBar.update(erasedFileCount, totalFileCount, 1);
+                       progressBar->update(erasedFileCount, totalFileCount, 1);
                } else if (file.isDirectory()) {
                        directoryErase(next);
                }