tizen 2.4 release
[framework/web/wrt-commons.git] / modules / widget_dao / dao / plugin_dao_read_only.cpp
@@ -23,7 +23,7 @@
 #include <dpl/wrt-dao-ro/plugin_dao_read_only.h>
 
 #include <sstream>
-#include <dpl/log/log.h>
+#include <dpl/log/wrt_log.h>
 #include <dpl/foreach.h>
 #include <dpl/wrt-dao-ro/webruntime_database.h>
 #include <dpl/db/orm.h>
@@ -36,7 +36,7 @@ typedef DPL::DB::ORM::wrt::PluginProperties::Row PluginRow;
 
 PluginRow getPluginRow(DbPluginHandle pluginHandle)
 {
-    LogDebug("Getting plugin row. Handle: " << pluginHandle);
+    WrtLogD("Getting plugin row. Handle: %i", pluginHandle);
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
@@ -62,16 +62,14 @@ PluginDAOReadOnly::PluginDAOReadOnly(DbPluginHandle pluginHandle) :
     m_pluginHandle(pluginHandle)
 {
     if (!isPluginInstalled(m_pluginHandle)) {
-        LogError("Plugin " << m_pluginHandle << " not installed.");
+        WrtLogE("Plugin %i not installed.", m_pluginHandle);
         Throw(PluginDAOReadOnly::Exception::PluginNotExist);
     }
-
-    checkInstallationCompleted();
 }
 
 PluginDAOReadOnly::PluginDAOReadOnly(const std::string &libraryName)
 {
-    LogDebug("PluginDAOReadOnly ( " << libraryName << " )");
+    WrtLogD("PluginDAOReadOnly ( %s )", libraryName.c_str());
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
@@ -86,9 +84,7 @@ PluginDAOReadOnly::PluginDAOReadOnly(const std::string &libraryName)
             ThrowMsg(PluginDAOReadOnly::Exception::PluginNotExist,
                      "Cannot find plugin: [" + libraryName + "]");
         }
-        LogDebug(" >> Handle for this plugin: " << m_pluginHandle);
-
-        checkInstallationCompleted();
+        WrtLogD(" >> Handle for this plugin: %i", m_pluginHandle);
     }
     Catch(DPL::DB::SqlConnection::Exception::Base) {
         ReThrowMsg(PluginDAOReadOnly::Exception::DatabaseError,
@@ -96,19 +92,10 @@ PluginDAOReadOnly::PluginDAOReadOnly(const std::string &libraryName)
     }
 }
 
-void PluginDAOReadOnly::checkInstallationCompleted()
-{
-    if (getInstallationStateForHandle(m_pluginHandle)
-        != PluginDAOReadOnly::INSTALLATION_COMPLETED)
-    {
-        LogError("Plugin " << m_pluginHandle << " installation not completed");
-        Throw(PluginDAOReadOnly::Exception::PluginInstallationNotCompleted);
-    }
-}
-
 bool PluginDAOReadOnly::isPluginInstalled(const std::string &libraryName)
 {
-    LogDebug("Check if Library is installed. LibraryName: " << libraryName);
+    WrtLogD("Check if Library is installed. LibraryName: %s",
+        libraryName.c_str());
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
@@ -119,7 +106,7 @@ bool PluginDAOReadOnly::isPluginInstalled(const std::string &libraryName)
         PluginProperties::Select::RowList rows = select->GetRowList();
 
         bool flag = !rows.empty();
-        LogDebug(" >> Plugin " << libraryName <<
+        WrtLogD(" >> Plugin %s %s", libraryName.c_str(),
                  (flag ? " found." : " not found."));
 
         return flag;
@@ -132,7 +119,7 @@ bool PluginDAOReadOnly::isPluginInstalled(const std::string &libraryName)
 
 PluginHandleList PluginDAOReadOnly::getPluginHandleList()
 {
-    LogDebug("Getting plugin handle list.");
+    WrtLogD("Getting plugin handle list.");
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
@@ -144,7 +131,7 @@ PluginHandleList PluginDAOReadOnly::getPluginHandleList()
         std::ostringstream handles;
         FOREACH(it, ret)
         handles << *it << " ";
-        LogDebug(" >> PluginHandle list retrieved: (" << handles << ")");
+        WrtLogD(" >> PluginHandle list retrieved: (%s)", handles.str().c_str());
 
         return ret;
     }
@@ -156,7 +143,7 @@ PluginHandleList PluginDAOReadOnly::getPluginHandleList()
 
 PluginHandleList PluginDAOReadOnly::getRootPluginHandleList()
 {
-    LogDebug("Getting root plugin handle list.");
+    WrtLogD("Getting root plugin handle list.");
     Try {
         using namespace DPL::DB::ORM;
         using namespace DPL::DB::ORM::wrt;
@@ -191,24 +178,24 @@ DbPluginHandle PluginDAOReadOnly::getPluginHandle() const
 //"value" cannot be null, as in registerPlugin it is always set
 #define RETURN_STD_STRING(in, what)                 \
     std::string ret = "";                           \
-    if (!in.IsNull()) {                             \
+    if (!!in) {                                       \
         ret = DPL::ToUTF8String(*in); }             \
-    LogDebug(" >> Plugin " << what << ": " << ret); \
+    WrtLogD(" >> Plugin %s: %s", what, ret.c_str()); \
     return ret;
 
 std::string PluginDAOReadOnly::getLibraryPath() const
 {
-    LogDebug("Getting plugin library path. Handle: " << m_pluginHandle);
+    WrtLogD("Getting plugin library path. Handle: %i", m_pluginHandle);
     PluginRow row = getPluginRow(m_pluginHandle);
     RETURN_STD_STRING(row.Get_PluginLibraryPath(), "library path")
 }
 
 std::string PluginDAOReadOnly::getLibraryName() const
 {
-    LogDebug("Getting plugin library name. Handle: " << m_pluginHandle);
+    WrtLogD("Getting plugin library name. Handle: %i", m_pluginHandle);
     PluginRow row = getPluginRow(m_pluginHandle);
     std::string ret = DPL::ToUTF8String(row.Get_PluginLibraryName());
-    LogDebug(" >> Plugin library name: " << ret);
+    WrtLogD(" >> Plugin library name: %s", ret.c_str());
     return ret;
 }
 
@@ -243,10 +230,39 @@ PluginHandleSetPtr PluginDAOReadOnly::getLibraryDependencies() const
     }
 }
 
+PluginHandleSetPtr PluginDAOReadOnly::getLibraryDependentPlugins() const
+{
+    Try
+    {
+        using namespace DPL::DB::ORM;
+        using namespace DPL::DB::ORM::wrt;
+        PluginHandleSetPtr dependencies(new PluginHandleSet);
+
+        WRT_DB_SELECT(select, PluginDependencies, &WrtDatabase::interface())
+        select->Where(
+            Equals<PluginDependencies::RequiredPluginPropertiesId>(m_pluginHandle));
+
+        PluginDependencies::Select::RowList rows = select->GetRowList();
+
+        if (!rows.empty()) {
+            FOREACH(it, rows)
+            {
+                dependencies->insert(it->Get_PluginPropertiesId());
+            }
+        }
+
+        return dependencies;
+    }
+    Catch(DPL::DB::SqlConnection::Exception::Base) {
+        ReThrowMsg(PluginDAOReadOnly::Exception::DatabaseError,
+                   "Failed in GetLibraryDependencies");
+    }
+}
+
 DbPluginHandle PluginDAOReadOnly::getPluginHandleForImplementedObject(
     const std::string& objectName)
 {
-    LogDebug("GetPluginHandle for object: " << objectName);
+    WrtLogD("GetPluginHandle for object: %s", objectName.c_str());
 
     Try
     {
@@ -265,7 +281,7 @@ DbPluginHandle PluginDAOReadOnly::getPluginHandleForImplementedObject(
         if (!rows.empty()) {
             pluginHandle = rows.front().Get_PluginPropertiesId();
         } else {
-            LogWarning("PluginHandle for object not found");
+            WrtLogW("PluginHandle for object not found");
         }
         return pluginHandle;
     }
@@ -277,7 +293,7 @@ DbPluginHandle PluginDAOReadOnly::getPluginHandleForImplementedObject(
 
 ImplementedObjectsList PluginDAOReadOnly::getImplementedObjects()
 {
-    LogDebug("getImplementedObjects");
+    WrtLogD("getImplementedObjects");
 
     Try
     {
@@ -294,7 +310,7 @@ ImplementedObjectsList PluginDAOReadOnly::getImplementedObjects()
                 objectList.push_back(DPL::ToUTF8String(*it));
             }
         } else {
-            LogWarning("PluginHandle for object not found");
+            WrtLogW("PluginHandle for object not found");
         }
         return objectList;
     }
@@ -307,7 +323,7 @@ ImplementedObjectsList PluginDAOReadOnly::getImplementedObjects()
 ImplementedObjectsList PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
     DbPluginHandle handle)
 {
-    LogDebug("getImplementedObjects for pluginHandle: " << handle);
+    WrtLogD("getImplementedObjects for pluginHandle: %i", handle);
 
     Try
     {
@@ -327,7 +343,7 @@ ImplementedObjectsList PluginDAOReadOnly::getImplementedObjectsForPluginHandle(
                 objectList.push_back(DPL::ToUTF8String(it->Get_PluginObject()));
             }
         } else {
-            LogWarning("PluginHandle for object not found");
+            WrtLogW("PluginHandle for object not found");
         }
         return objectList;
     }
@@ -426,7 +442,7 @@ PluginDAOReadOnly::PluginInstallationState PluginDAOReadOnly::
         if (!rows.empty()) {
             return ToState(rows.front().Get_InstallationState());
         }
-        LogError("Data in DB are invalid. Missing field");
+        WrtLogE("Data in DB are invalid. Missing field");
         return UNKNOWN_ERROR;
     }
     Catch(DPL::DB::SqlConnection::Exception::Base) {
@@ -435,6 +451,15 @@ PluginDAOReadOnly::PluginInstallationState PluginDAOReadOnly::
     }
 }
 
+std::time_t PluginDAOReadOnly::getLibraryTimestamp() const
+{
+    WrtLogD("Getting plugin library timestamp. Handle: %i", m_pluginHandle);
+    PluginRow row = getPluginRow(m_pluginHandle);
+    std::time_t ret = row.Get_LibraryTimestamp();
+    WrtLogD(" >> Plugin library timestamp: %li", ret);
+    return ret;
+}
+
 bool PluginDAOReadOnly::isPluginInstalled(DbPluginHandle pluginHandle)
 {
     Try {