change data names(req, actionSchema)
authorYoungjae Shin <yj99.shin@samsung.com>
Tue, 9 Jul 2019 05:18:19 +0000 (14:18 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
actionSchema -> (action)Rule, req -> action

45 files changed:
Definitions.cmake
common/definitions.h
example/tizen_action_rule.xml [moved from example/tizen_action_schema.xml with 70% similarity]
example/tizen_action_rule.xsd [moved from example/tizen_action_schema.xsd with 96% similarity]
example/tizen_btAudioConnect_mode.xml
example/tizen_btOff_mode.xml
example/tizen_btOn_mode.xml
example/tizen_ex1_mode.xml
example/tizen_ex2_mode.xml
example/tizen_mode.xsd
example/tizen_powerSave_mode.xml
example/tizen_wifiOn_mode.xml
packaging/modes.spec
supervisor/Action.cpp [moved from supervisor/Req.cpp with 59% similarity]
supervisor/Action.h [moved from supervisor/Req.h with 77% similarity]
supervisor/ActionRule.cpp [moved from supervisor/ActionSchema.cpp with 81% similarity]
supervisor/ActionRule.h [moved from supervisor/ActionSchema.h with 89% similarity]
supervisor/ActionSchemaManager.cpp [deleted file]
supervisor/ArgumentParser.cpp
supervisor/ArgumentParser.h
supervisor/Mode.cpp
supervisor/Mode.h
supervisor/ModeManager.cpp
supervisor/ModeManager.h
supervisor/ModeParser.h
supervisor/ModeTag.cpp
supervisor/ModeTag.h
supervisor/ModeXMLParser.cpp
supervisor/ModeXMLParser.h
supervisor/ModesConfig.h
supervisor/RequestHandler.cpp
supervisor/RequestHandler.h
supervisor/RuleManager.cpp [new file with mode: 0644]
supervisor/RuleManager.h [moved from supervisor/ActionSchemaManager.h with 57% similarity]
supervisor/Supervisor.cpp
supervisor/Supervisor.h
supervisor/TAction.h [moved from supervisor/TReq.h with 85% similarity]
supervisor/TActionRule.h [moved from supervisor/TActionSchema.h with 81% similarity]
supervisor/XMLGenerator.cpp
unittest/CMakeLists.txt
unittest/modes-gtest-run.sh
unittest/modes_test_generator.cpp
unittest/modes_test_modemgr.cpp
unittest/modes_test_parser.cpp
unittest/modes_test_plugin.cpp

index 4a4eb4d..3268279 100644 (file)
@@ -22,11 +22,11 @@ IF(NOT DEFINED MODES_CUSTOM_MODE_DEFAULT_DIR)
 ENDIF(NOT DEFINED MODES_CUSTOM_MODE_DEFAULT_DIR)
 ADD_DEFINITIONS("-DMODES_CUSTOM_MODE_DEFAULT_DIR=\"${MODES_CUSTOM_MODE_DEFAULT_DIR}\"")
 
-IF(NOT DEFINED MODES_ACTIONSCHEMA_DEFAULT_DIR)
-       MESSAGE("No MODES_ACTIONSCHEMA_DEFAULT_DIR. Check build system")
-       SET(MODES_ACTIONSCHEMA_DEFAULT_DIR "/usr/share/modes/action")
-ENDIF(NOT DEFINED MODES_ACTIONSCHEMA_DEFAULT_DIR)
-ADD_DEFINITIONS("-DMODES_ACTIONSCHEMA_DEFAULT_DIR=\"${MODES_ACTIONSCHEMA_DEFAULT_DIR}\"")
+IF(NOT DEFINED MODES_ACTIONRULE_DEFAULT_DIR)
+       MESSAGE("No MODES_ACTIONRULE_DEFAULT_DIR. Check build system")
+       SET(MODES_ACTIONRULE_DEFAULT_DIR "/usr/share/modes/rule")
+ENDIF(NOT DEFINED MODES_ACTIONRULE_DEFAULT_DIR)
+ADD_DEFINITIONS("-DMODES_ACTIONRULE_DEFAULT_DIR=\"${MODES_ACTIONRULE_DEFAULT_DIR}\"")
 
 IF(NOT DEFINED MODES_XSD_DEFAULT_DIR)
        MESSAGE("No MODES_XSD_DEFAULT_DIR. Check build system")
index 9e7fe2b..c2a1e49 100644 (file)
@@ -39,9 +39,9 @@
 #warning "MODES_CUSTOM_MODE_DEFAULT_DIR is redefined"
 #endif
 
-#ifndef MODES_ACTIONSCHEMA_DEFAULT_DIR
-#define MODES_ACTIONSCHEMA_DEFAULT_DIR "/usr/share/modes/action"
-#warning "MODES_ACTIONSCHEMA_DEFAULT_DIR is redefined"
+#ifndef MODES_ACTIONRULE_DEFAULT_DIR
+#define MODES_ACTIONRULE_DEFAULT_DIR "/usr/share/modes/rule"
+#warning "MODES_ACTIONRULE_DEFAULT_DIR is redefined"
 #endif
 
 #ifndef MODES_PLUGIN_DEFAULT_DIR
 #endif
 
 #define MODES_MODE_DEFAULT_XSD_FILE "tizen_mode.xsd"
-#define MODES_ACTIONSCHEMA_DEFAULT_XSD_FILE "tizen_action_schema.xsd"
+#define MODES_ACTIONRULE_DEFAULT_XSD_FILE "tizen_action_rule.xsd"
 #define MODES_MODE_DEFAULT_XSD MODES_XSD_DEFAULT_DIR "/" MODES_MODE_DEFAULT_XSD_FILE
-#define MODES_ACTIONSCHEMA_DEFAULT_XSD MODES_XSD_DEFAULT_DIR "/" MODES_ACTIONSCHEMA_DEFAULT_XSD_FILE
+#define MODES_ACTIONRULE_DEFAULT_XSD MODES_XSD_DEFAULT_DIR "/" MODES_ACTIONRULE_DEFAULT_XSD_FILE
 
 #define MODES_PLUGIN_LIB_PREFIX "libmodes-plugin"
-#define MODES_ACTIONSCHEMA_FILE_SUFFIX "_schema.xml"
+#define MODES_ACTIONRULE_FILE_SUFFIX "_rule.xml"
 #define MODES_MODE_FILE_SUFFIX "_mode.xml"
similarity index 70%
rename from example/tizen_action_schema.xml
rename to example/tizen_action_rule.xml
index 0c020c1..a43b9db 100644 (file)
@@ -1,38 +1,38 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
-  <actionSchema>
-    <action name="wifi.power" type="bool" since="5.5" plugin="wifi-manager">
+  <actionRule>
+    <rule name="wifi.power" type="bool" since="5.5" plugin="wifi-manager">
       <alias name="on">1</alias>
       <alias name="off">0</alias>
       <defaultVal>0</defaultVal>
       <desc>wifi On/Off</desc>
       <domain>Network &amp; Connectivity</domain>
-    </action>
-    <action name="bluetooth.power" type="bool" since="5.5" plugin="bluetooth">
+    </rule>
+    <rule name="bluetooth.power" type="bool" since="5.5" plugin="bluetooth">
       <alias name="on">1</alias>
       <alias name="off">0</alias>
       <defaultVal>0</defaultVal>
       <desc>bluetooth On/Off</desc>
       <domain>Network &amp; Connectivity</domain>
-    </action>
-    <action name="bluetooth.audioConnect" type="string" since="5.5" plugin="bluetooth">
+    </rule>
+    <rule name="bluetooth.audioConnect" type="string" since="5.5" plugin="bluetooth">
       <defaultVal>0:0:0:0:0:0</defaultVal>
       <desc>bluetooth Audio Connect</desc>
       <domain>Network &amp; Connectivity</domain>
-    </action>
-    <action name="sensord.changeAccuracy" type="int" since="5.5" plugin="sensor-fw">
+    </rule>
+    <rule name="sensord.changeAccuracy" type="int" since="5.5" plugin="sensor-fw">
       <defaultVal>100</defaultVal>
       <conflict>sensord.exactness</conflict>
       <desc>Sensor Accuracy</desc>
       <domain>System</domain>
-    </action>
-    <action name="sensord.exactness" type="int" since="5.5" plugin="sensor-fw">
+    </rule>
+    <rule name="sensord.exactness" type="int" since="5.5" plugin="sensor-fw">
       <defaultVal>100</defaultVal>
       <conflict>sensord.changeAccuracy</conflict>
       <desc>Sensor Exactness</desc>
       <domain>System</domain>
-    </action>
-    <action name="vconf.db.setting.psmode" type="int" since="5.5" plugin="vconf">
+    </rule>
+    <rule name="vconf.db.setting.psmode" type="int" since="5.5" plugin="vconf">
       <alias name="SETTING_PSMODE_NORMAL">0</alias>
       <alias name="SETTING_PSMODE_POWERFUL">1</alias>
       <alias name="SETTING_PSMODE_ADVISOR">1</alias>
@@ -45,8 +45,8 @@
       <conflict>sensord.changeAccuracy</conflict>
       <desc>test</desc>
       <domain>System</domain>
-    </action>
-    <action name="vconf.db.bluetooth.status" type="int" since="5.5" plugin="vconf">
+    </rule>
+    <rule name="vconf.db.bluetooth.status" type="int" since="5.5" plugin="vconf">
       <alias name="VCONFKEY_BT_STATUS_OFF">0</alias>
       <alias name="VCONFKEY_BT_STATUS_ON">1</alias>
       <alias name="VCONFKEY_BT_STATUS_BT_VISIBLE">2</alias>
       <defaultVal>0</defaultVal>
       <desc>test</desc>
       <domain>Network &amp; Connectivity</domain>
-    </action>
-    <action name="browser.url" type="string" since="5.5" plugin="web">
+    </rule>
+    <rule name="browser.url" type="string" since="5.5" plugin="web">
       <defaultVal>about:blank</defaultVal>
       <desc>browser</desc>
       <domain>Web Framework</domain>
-    </action>
-    <action name="display.nightLight" type="int" since="5.5" plugin="display">
+    </rule>
+    <rule name="display.nightLight" type="int" since="5.5" plugin="display">
       <defaultVal>70</defaultVal>
       <conflict>display.autoLight</conflict>
       <desc>It makes the screen color warmer.</desc>
       <domain>System</domain>
-    </action>
-  </actionSchema>
+    </rule>
+  </actionRule>
 </tizenModes>
similarity index 96%
rename from example/tizen_action_schema.xsd
rename to example/tizen_action_rule.xsd
index c903c8a..beff553 100644 (file)
@@ -4,10 +4,10 @@
   <xs:element name="tizenModes">
     <xs:complexType>
       <xs:sequence>
-        <xs:element maxOccurs="1" name="actionSchema">
+        <xs:element maxOccurs="1" name="actionRule">
           <xs:complexType>
             <xs:sequence>
-              <xs:element maxOccurs="unbounded" name="action">
+              <xs:element maxOccurs="unbounded" name="rule">
                 <xs:complexType>
                   <xs:sequence>
                     <xs:element minOccurs="0" maxOccurs="unbounded" name="alias">
index 1020584..9740431 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="btAudioConnect" type="exclusive">
-    <req action="bluetooth.power">on</req>
-    <req action="bluetooth.audioConnect">08:AE:D6:5E:AE:16</req>
+    <action rule="bluetooth.power">on</action>
+    <action rule="bluetooth.audioConnect">08:AE:D6:5E:AE:16</action>
   </mode>
 </tizenModes>
index df4da79..fcb1c3f 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="btOff" type="exclusive">
-    <req action="bluetooth.power">off</req>
+    <action rule="bluetooth.power">off</action>
   </mode>
 </tizenModes>
index c0395b7..e1cf681 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="btOn" type="exclusive">
-    <req action="bluetooth.power">on</req>
+    <action rule="bluetooth.power">on</action>
   </mode>
 </tizenModes>
index ff795c4..0583f84 100644 (file)
@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="ex1" type="normal">
-    <req ID="wifiOn" action="wifi.power" restrict="lock" type="sync" priority="-100">on</req>
-    <req action="notification.donotdisturb">on</req>
-    <req action="application.launch" before="GoPbsKids">com.vpn.usa123</req>
-    <req ID="GoPbsKids" action="browser.url" after="wifiOn">https://pbskids.org/</req>
-    <req ID="BMJ" action="bluetooth.connet" type="sync">Modes-JBL</req>
-    <req action="media.music.player" type="async" after="BMJ">beatles-yesterday.mp3</req>
-    <req ID="1" action="vconf.db.setting.psmode" type="async" priority="-100"
-         >SETTING_PSMODE_NORMAL</req>
+    <action ID="wifiOn" rule="wifi.power" restrict="lock" type="sync" priority="-100">on</action>
+    <action rule="notification.donotdisturb">on</action>
+    <action rule="application.launch" before="GoPbsKids">com.vpn.usa123</action>
+    <action ID="GoPbsKids" rule="browser.url" after="wifiOn">https://pbskids.org/</action>
+    <action ID="BMJ" rule="bluetooth.connet" type="sync">Modes-JBL</action>
+    <action rule="media.music.player" type="async" after="BMJ">beatles-yesterday.mp3</action>
+    <action ID="1" rule="vconf.db.setting.psmode" type="async" priority="-100"
+         >SETTING_PSMODE_NORMAL</action>
   </mode>
 </tizenModes>
index 64dd064..6c39ee1 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="ex2" type="exclusive">
-    <req ID="1" action="vconf.db.setting.psmode" type="async" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</req>
-    <req ID="wifiOff" action="wifi.power" restrict="lock" type="sync" priority="-100">off</req>
+    <action ID="1" rule="vconf.db.setting.psmode" type="async" restrict="lock" priority="-100">SETTING_PSMODE_WEARABLE</action>
+    <action ID="wifiOff" rule="wifi.power" restrict="lock" type="sync" priority="-100">off</action>
   </mode>
 </tizenModes>
index f19a242..be9ec33 100644 (file)
@@ -7,12 +7,12 @@
         <xs:element name="mode">
           <xs:complexType>
             <xs:sequence>
-              <xs:element maxOccurs="unbounded" name="req">
+              <xs:element maxOccurs="unbounded" name="action">
                 <xs:complexType>
                   <xs:simpleContent>
                     <xs:extension base="o:valueT">
                       <xs:attribute name="ID" type="xs:string" use="optional" />
-                      <xs:attribute name="action" type="xs:string" use="required" />
+                      <xs:attribute name="rule" type="xs:string" use="required" />
                       <xs:attribute name="type" use="optional">
                         <xs:simpleType>
                           <xs:restriction base="xs:string">
index a5df75c..423488b 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="powerSave" type="exclusive">
-    <req action="vconf.db.setting.psmode">SETTING_PSMODE_WEARABLE_ENHANCED</req>
-    <req action="vconf.db.bluetooth.status">VCONFKEY_BT_STATUS_OFF</req>
+    <action rule="vconf.db.setting.psmode">SETTING_PSMODE_WEARABLE_ENHANCED</action>
+    <action rule="vconf.db.bluetooth.status">VCONFKEY_BT_STATUS_OFF</action>
   </mode>
 </tizenModes>
index 56b4205..0856629 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="5.5">
   <mode name="wifiOn" type="exclusive">
-    <req action="wifi.power">on</req>
+    <action rule="wifi.power">on</action>
   </mode>
 </tizenModes>
index 3fd79aa..d185b41 100644 (file)
@@ -84,7 +84,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
        -DSYSCONF_DIR:PATH=%{_sysconfdir} \
        -DMODES_MODE_DEFAULT_DIR:PATH=%{modes_data_dir}/mode \
        -DMODES_CUSTOM_MODE_DEFAULT_DIR:PATH=%{modes_data_dir}/custom-mode \
-       -DMODES_ACTIONSCHEMA_DEFAULT_DIR:PATH=%{modes_data_dir}/action \
+       -DMODES_ACTIONRULE_DEFAULT_DIR:PATH=%{modes_data_dir}/rule \
        -DMODES_XSD_DEFAULT_DIR:PATH=%{modes_data_dir}/xsd \
        -DMODES_PLUGIN_DEFAULT_DIR:PATH=%{modes_plugin_dir} \
        -DDBUS_INTERFACE=%{_dbus_interface} \
@@ -96,16 +96,16 @@ make %{?_smp_mflags}
 %make_install
 install -d -m 755 %{buildroot}%{modes_data_dir}/mode
 install -d -m 755 %{buildroot}%{modes_data_dir}/custom-mode
-install -d -m 755 %{buildroot}%{modes_data_dir}/action
+install -d -m 755 %{buildroot}%{modes_data_dir}/rule
 install -d -m 755 %{buildroot}%{modes_data_dir}/xsd
 install -m 0644 example/*_mode.xml %{buildroot}%{modes_data_dir}/mode/
-install -m 0644 example/*_schema.xml %{buildroot}%{modes_data_dir}/action/
+install -m 0644 example/*_rule.xml %{buildroot}%{modes_data_dir}/rule/
 install -m 0644 example/*.xsd %{buildroot}%{modes_data_dir}/xsd/
 install -m 0755 unittest/modes-gtest-run.sh %{buildroot}%{modes_test_dir}/
 
 %check
 pushd example
-xmllint --noout --schema tizen_action_schema.xsd tizen_action_schema.xml
+xmllint --noout --schema tizen_action_rule.xsd tizen_action_rule.xml
 xmllint --noout --schema tizen_mode.xsd tizen_*_mode.xml
 
 bash ../unittest/modes-gtest-run.sh ./ ../unittest
similarity index 59%
rename from supervisor/Req.cpp
rename to supervisor/Action.cpp
index 2ef9050..39039b2 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "Req.h"
+#include "Action.h"
 
 #include "mdss.h"
 #include "ModesEx.h"
 
 MODES_NAMESPACE_USE;
 
-Req::Req()
+Action::Action()
        :plugin(nullptr), restriction(REQ_NONE)
 {
 }
 
-Req::Req(const std::string &name)
-       :actionName(name), plugin(nullptr), restriction(REQ_NONE)
+Action::Action(const std::string &name)
+       :ruleName(name), plugin(nullptr), restriction(REQ_NONE)
 {
 }
 
-void Req::printInfo()
+void Action::printInfo()
 {
-       DBG("Req(%s):ID(%s), Restrict(%d)", getName().c_str(), getID().c_str(), getRestrict());
+       DBG("Action(%s):ID(%s), Restrict(%d)", getRuleName().c_str(), getID().c_str(), getRestrict());
 }
 
-void Req::setName(const std::string &data)
+void Action::setRuleName(const std::string &data)
 {
-       actionName = data;
+       ruleName = data;
 }
 
-std::string Req::getName()
+std::string Action::getRuleName()
 {
-       return actionName;
+       return ruleName;
 }
 
-void Req::setID(const std::string &actionId)
+void Action::setID(const std::string &actionId)
 {
        id = actionId;
 }
 
-std::string Req::getID()
+std::string Action::getID()
 {
        return id;
 }
 
-void Req::setRestrict(const ReqRestrict &data)
+void Action::setRestrict(const ActionRestrict &data)
 {
        restriction = data;
 }
 
-Req::ReqRestrict Req::getRestrict()
+Action::ActionRestrict Action::getRestrict()
 {
        return restriction;
 }
 
-void Req::setPlugin(Plugin *pi)
+void Action::setPlugin(Plugin *pi)
 {
        plugin = pi;
 }
similarity index 77%
rename from supervisor/Req.h
rename to supervisor/Action.h
index 036d6d4..bb6750e 100644 (file)
 
 MODES_NAMESPACE_BEGIN
 
-class Req {
+class Action {
 public:
        typedef enum {
                REQ_NONE,
                REQ_LOCK
-       }ReqRestrict;
+       }ActionRestrict;
 
-       virtual ~Req() = default;
-       Req();
-       Req(const std::string &actionName);
+       virtual ~Action() = default;
+       Action();
+       Action(const std::string &ruleName);
 
        void printInfo();
-       void setName(const std::string &data);
-       std::string getName();
+       void setRuleName(const std::string &data);
+       std::string getRuleName();
        void setID(const std::string &actionId);
        std::string getID();
-       void setRestrict(const ReqRestrict &data);
-       ReqRestrict getRestrict();
+       void setRestrict(const ActionRestrict &data);
+       ActionRestrict getRestrict();
        void setPlugin(Plugin *pi);
        virtual void setValue(const std::string &val) = 0;
        virtual std::string getStringOfValue() = 0;
        virtual void apply() = 0;
 
 protected:
-       std::string actionName;
+       std::string ruleName;
        Plugin *plugin;
 
 private:
        std::string id;
-       ReqRestrict restriction;
+       ActionRestrict restriction;
 };
 
 MODES_NAMESPACE_END
similarity index 81%
rename from supervisor/ActionSchema.cpp
rename to supervisor/ActionRule.cpp
index 574d25a..07444c6 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "ActionSchema.h"
+#include "ActionRule.h"
 
 #include <string>
 #include "mdss.h"
 
 MODES_NAMESPACE_USE;
 
-std::string ActionSchema::getName()
+std::string ActionRule::getName()
 {
-       return actionName;
+       return ruleName;
 }
 
-void ActionSchema::setPlugin(const std::string &pi)
+void ActionRule::setPlugin(const std::string &pi)
 {
        plugin = pi;
 }
 
-std::string ActionSchema::getPlugin()
+std::string ActionRule::getPlugin()
 {
        return plugin;
 }
similarity index 89%
rename from supervisor/ActionSchema.h
rename to supervisor/ActionRule.h
index dfaf846..6c29133 100644 (file)
 
 #include <string>
 #include "mdss.h"
-#include "Req.h"
+#include "Action.h"
 
 MODES_NAMESPACE_BEGIN
 
-class ActionSchema {
+class ActionRule {
 public:
-       virtual ~ActionSchema() = default;
+       virtual ~ActionRule() = default;
 
        std::string getName();
        std::string getPlugin();
        void setPlugin(const std::string &pi);
-       virtual Req* makeRequirement() = 0;
+       virtual Action* makeAction() = 0;
        virtual void addDefaultValue(const std::string &val) = 0;
        virtual void addAlias(const std::string &alias, const std::string &value) = 0;
 protected:
-       std::string actionName;
+       std::string ruleName;
 private:
        std::string plugin;
        // TODO:: handle conflict List, since, description, version
diff --git a/supervisor/ActionSchemaManager.cpp b/supervisor/ActionSchemaManager.cpp
deleted file mode 100644 (file)
index bf04877..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ActionSchemaManager.h"
-
-#include <dirent.h>
-#include <cstring>
-#include "mdss.h"
-#include "TActionSchema.h"
-#include "ModesEx.h"
-
-using std::string;
-MODES_NAMESPACE_USE;
-
-const xmlChar* const ActionSchemaManager::ACTION_SCHEMA_TAG = (xmlChar*)"actionSchema";
-const xmlChar* const ActionSchemaManager::ACTION_SCHEMA_TAG_ACTION = (xmlChar*)"action";
-const xmlChar* const ActionSchemaManager::ACTION_TAGS[] = {
-       (xmlChar*)"name",
-       (xmlChar*)"type",
-       (xmlChar*)"plugin",
-       (xmlChar*)"alias",
-       (xmlChar*)"conflict",
-       (xmlChar*)"defaultVal"
-};
-
-void ActionSchemaManager::makeActionSchemaMap()
-{
-       if (actSchemaDir.empty()) {
-               ERR("No actSchemaDir");
-               actSchemaDir = MODES_ACTIONSCHEMA_DEFAULT_DIR;
-       }
-
-       DIR *dir;
-       if ((dir = opendir(actSchemaDir.c_str())) == NULL)
-               ERR("opendir(%s) Fail(%s)", actSchemaDir.c_str(), strerror(errno));
-
-       struct dirent *entry;
-       while ((entry = readdir(dir)) != NULL) {
-               string file(entry->d_name);
-               size_t pos = file.find_last_of("_");
-               if (string::npos == pos
-                       || file.compare(pos, sizeof(MODES_ACTIONSCHEMA_FILE_SUFFIX) - 1, MODES_ACTIONSCHEMA_FILE_SUFFIX)) {
-                       continue;
-               }
-
-               string fileFullPath = actSchemaDir + "/" + string(entry->d_name);
-               try {
-                       parseActionSchema(fileFullPath);
-                       DBG("Action Schema(size=%d) Load", schemaMap.size());
-               }
-               catch (ModesEx &e) {
-                       ERR("parseActionSchema(%s) Fail(%s)", fileFullPath.c_str(), e.what());
-               }
-       }
-       closedir(dir);
-}
-
-void ActionSchemaManager::freeActionSchemaMap()
-{
-       for (auto it = schemaMap.begin(); it != schemaMap.end(); ++it)
-               delete it->second;
-}
-
-
-void ActionSchemaManager::parseElement(xmlNodePtr cur, ActionSchema *actionSchema)
-{
-       RET_IF(NULL == actionSchema);
-
-       if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_TAGS[TagElemAlias])) {
-               char *alias = (char*)xmlGetProp(cur, ACTION_TAGS[TagAttName]);
-               if (NULL == alias) {
-                       ERR("%s : No %s", ACTION_TAGS[TagElemAlias], ACTION_TAGS[TagAttName]);
-                       return;
-               }
-
-               char *value = (char*)xmlNodeGetContent(cur);
-               if (NULL == value) {
-                       ERR("%s(%s) : No value", ACTION_TAGS[TagElemAlias], alias);
-                       xmlFree(alias);
-                       return;
-               }
-
-               actionSchema->addAlias(alias, value);
-               xmlFree(value);
-               xmlFree(alias);
-       } else if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_TAGS[TagElemDefValue])) {
-               char *value = (char*)xmlNodeGetContent(cur);
-               if (NULL == value) {
-                       ERR("%s : No value", ACTION_TAGS[TagElemDefValue]);
-                       return;
-               }
-               actionSchema->addDefaultValue(value);
-       } else if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_TAGS[TagElemConflict])) {
-               // TODO: enhanced feature
-               DBG("TBD(%s)", cur->name);
-       } else {
-               DBG("Invalid node(%s)", cur->name);
-       }
-}
-
-Req* ActionSchemaManager::createAction(const string &actionName)
-{
-       std::map<std::string, ActionSchema*>::iterator it = schemaMap.find(actionName);
-       if (schemaMap.end() != it) {
-               ActionSchema *schema = it->second;
-               return schema->makeRequirement();
-       } else {
-               ERR("No schema(%s)", actionName.c_str());
-               return nullptr;
-       }
-}
-
-void ActionSchemaManager::setOptions(const string &actionSchemaDir, const string &actionSchemaXsd)
-{
-       actSchemaDir = actionSchemaDir;
-       actSchemaXsd = actionSchemaXsd;
-}
-
-string ActionSchemaManager::getProp(xmlNodePtr node, int att)
-{
-       char *tmp;
-       string returnStr;
-
-       tmp = (char*)xmlGetProp(node, ACTION_TAGS[att]);
-       if (tmp) {
-               returnStr = tmp;
-               xmlFree(tmp);
-       } else {
-               ERR("Action : No %s", ACTION_TAGS[att]);
-               throw ModesEx(ModesEx::NO_DATA);
-       }
-
-       return returnStr;
-}
-
-ActionSchema* ActionSchemaManager::makeActionSchema(xmlNodePtr node)
-{
-       string type, name, plugin;
-       ActionSchema *actionSchema = NULL;
-
-       try {
-               name = getProp(node, TagAttName);
-               type = getProp(node, TagAttType);
-               plugin = getProp(node, TagAttPlugin);
-       }
-       catch (ModesEx &e) {
-               ERR("getProp() Fail(%s)", e.what());
-               return nullptr;
-       }
-
-       DBG("Action(%s, %s) Added", name.c_str(), type.c_str());
-
-       if (MDS_EQUAL == type.compare("int"))
-               actionSchema = new TActionSchema<int>(name);
-       else if (MDS_EQUAL == type.compare("float"))
-               actionSchema = new TActionSchema<float>(name);
-       else if (MDS_EQUAL == type.compare("bool"))
-               actionSchema = new TActionSchema<bool>(name);
-       else
-               actionSchema = new TActionSchema<string>(name);
-
-       actionSchema->setPlugin(plugin);
-       for (xmlNode *cur = node->children; cur; cur = cur->next) {
-               if (xmlIsBlankNode(cur))
-                       continue;
-               parseElement(cur, actionSchema);
-       }
-
-       return actionSchema;
-}
-
-void ActionSchemaManager::parseAction(xmlNodePtr node)
-{
-       for (xmlNodePtr cur = node; cur; cur = cur->next) {
-               if (xmlIsBlankNode(cur))
-                       continue;
-
-               if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_SCHEMA_TAG_ACTION)) {
-                       ActionSchema *schema = makeActionSchema(cur);
-                       schemaMap.insert(std::pair<string, ActionSchema*>(schema->getName(), schema));
-               } else {
-                       DBG("Invalid node(%s)", cur->name);
-                       parseAction(cur->children);
-               }
-       }
-}
-
-void ActionSchemaManager::parseActionSchema(const string &xmlFile)
-{
-       if (actSchemaXsd.empty()) {
-               ERR("No actSchemaXsd");
-               actSchemaXsd = MODES_ACTIONSCHEMA_DEFAULT_XSD;
-       }
-
-       try {
-               XMLParser parser(xmlFile);
-               parser.validate(actSchemaXsd);
-
-               xmlNodePtr root = parser.getRoot();
-               if (MDS_EQUAL != xmlStrcmp(root->name, (xmlChar*)MODES_XML_ROOT)) {
-                       ERR("Invalid root element(%s, %s)", root->name, xmlFile.c_str());
-                       throw ModesEx(ModesEx::PARSER_ERROR, "Invalid file");
-               }
-
-               parseAction(root);
-       }
-       catch (ModesEx &e) {
-               ERR("parser Fail(%s)", e.what());
-       }
-}
index 747f757..f3bcf22 100644 (file)
@@ -27,14 +27,14 @@ char ArgumentParser::argp_doc[] =
 
 char ArgumentParser::args_doc[] =
        "modeXMLDirPath1 [modeXMLDirPath2] [--pluginDir=../plugin]"
-       " [--modeXsdFilePath=..example/tizen_mode.xsd] [--actionXsdFilePath=..example/tizen_schema.xsd]"
-       " [--actionSchema=../example] [--[--help]";
+       " [--modeXsdFilePath=..example/tizen_mode.xsd] [--ruleXsdFilePath=..example/tizen_rule.xsd]"
+       " [--ruleDir=../example] [--[--help]";
 
 struct argp_option ArgumentParser::options[] = {
        {"pluginDir", 'p',      "pluginDirPath", OPTION_ARG_OPTIONAL, "Set directory of plugin"},
        {"modeXsdFilePath", 'm', "modeXsdFilePath", OPTION_ARG_OPTIONAL, "Set mode xsd(schema) file path"},
-       {"actionXsdFilePath", 'a', "actionXsdFilePath", OPTION_ARG_OPTIONAL, "Set action xsd(schema) file path"},
-       {"actionSchema", 's', "actionSchemaDirPath", OPTION_ARG_OPTIONAL, "Set directory of Action schema file"},
+       {"ruleXsdFilePath", 'a', "actionRuleXsdFilePath", OPTION_ARG_OPTIONAL, "Set action rule xsd(schema) file path"},
+       {"ruleDir", 's', "actionRuleDirPath", OPTION_ARG_OPTIONAL, "Set directory of Action Rule file"},
        { 0 }
 };
 
@@ -61,14 +61,14 @@ error_t ArgumentParser::parse_opt(int key, char *arg, struct argp_state *state)
        case 'a':
                nextArg = state->argv[state->next];
                if (nextArg && *nextArg != '-') {
-                       parser->actionSchemaXsdFile = nextArg;
+                       parser->actionRuleXsdFile = nextArg;
                        state->next++;
                }
                break;
        case 's':
                nextArg = state->argv[state->next];
                if (nextArg && *nextArg != '-') {
-                       parser->actionSchemaDir = nextArg;
+                       parser->actionRuleDir = nextArg;
                        state->next++;
                }
                break;
@@ -92,7 +92,7 @@ struct argp ArgumentParser::argp_input = {options, parse_opt, args_doc, argp_doc
 
 ArgumentParser::ArgumentParser()
        :modeDirCount(0), modeXMLDirList(NULL), modeXsdFile(NULL),
-       actionSchemaDir(NULL), actionSchemaXsdFile(NULL), pluginDir(NULL)
+       actionRuleDir(NULL), actionRuleXsdFile(NULL), pluginDir(NULL)
 {
 }
 
@@ -111,11 +111,11 @@ ModesConfig ArgumentParser::parse(int argc, char **argv)
                config.modeXMLDirs.insert(MODES_MODE_DEFAULT_DIR);
        }
 
-       if (this->actionSchemaDir) {
-               DBG("action schema dir path: %s", this->actionSchemaDir);
-               config.actionSchemaDir = this->actionSchemaDir;
+       if (this->actionRuleDir) {
+               DBG("Action Rule dir path: %s", this->actionRuleDir);
+               config.actionRuleDir = this->actionRuleDir;
        } else {
-               config.actionSchemaDir = MODES_ACTIONSCHEMA_DEFAULT_DIR;
+               config.actionRuleDir = MODES_ACTIONRULE_DEFAULT_DIR;
        }
 
        if (this->modeXsdFile) {
@@ -125,11 +125,11 @@ ModesConfig ArgumentParser::parse(int argc, char **argv)
                config.modeXsdFile = MODES_MODE_DEFAULT_XSD;
        }
 
-       if (this->actionSchemaXsdFile) {
-               DBG("action schema xsd file path: %s", this->actionSchemaXsdFile);
-               config.actionSchemaXsdFile = this->actionSchemaXsdFile;
+       if (this->actionRuleXsdFile) {
+               DBG("Action Rule xsd file path: %s", this->actionRuleXsdFile);
+               config.actionRuleXsdFile = this->actionRuleXsdFile;
        } else {
-               config.actionSchemaXsdFile = MODES_ACTIONSCHEMA_DEFAULT_XSD;
+               config.actionRuleXsdFile = MODES_ACTIONRULE_DEFAULT_XSD;
        }
 
        if (this->pluginDir) {
index fd2be92..9c78288 100644 (file)
@@ -30,8 +30,8 @@ private:
        int modeDirCount;
        char **modeXMLDirList;
        char *modeXsdFile;
-       char *actionSchemaDir;
-       char *actionSchemaXsdFile;
+       char *actionRuleDir;
+       char *actionRuleXsdFile;
        char *pluginDir;
 
        static char argp_doc[];
index d4b152c..5c362c2 100644 (file)
@@ -26,9 +26,9 @@ Mode::~Mode()
 {
 }
 
-void Mode::addRequirement(Req *req)
+void Mode::addAction(Action *action)
 {
-       reqList.push_back(std::shared_ptr<Req>(req));
+       actionList.push_back(std::shared_ptr<Action>(action));
 }
 
 void Mode::setName(const std::string &data)
@@ -63,12 +63,12 @@ bool Mode::getCustomized() const
 
 void Mode::apply()
 {
-       std::list<std::shared_ptr<Req>>::iterator it;
-       for (it = reqList.begin(); it != reqList.end(); it++)
+       std::list<std::shared_ptr<Action>>::iterator it;
+       for (it = actionList.begin(); it != actionList.end(); it++)
                (*it)->apply();
 }
 
-std::list<std::shared_ptr<Req>> Mode::getReqList() const
+std::list<std::shared_ptr<Action>> Mode::getActionList() const
 {
-       return reqList;
+       return actionList;
 }
index 91d8914..b3cbfbd 100644 (file)
@@ -19,7 +19,7 @@
 #include <string>
 #include <memory>
 #include "mdss.h"
-#include "Req.h"
+#include "Action.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -36,15 +36,15 @@ public:
        void setCustomized(bool data);
        bool getCustomized() const;
 
-       void addRequirement(Req *req);
-       std::list<std::shared_ptr<Req>> getReqList() const;
+       void addAction(Action *action);
+       std::list<std::shared_ptr<Action>> getActionList() const;
        void apply();
 
 private:
        bool customized;
        std::string name;
        std::string type;
-       std::list<std::shared_ptr<Req>> reqList;
+       std::list<std::shared_ptr<Action>> actionList;
 #ifdef MDS_TEST
        friend class TestParser;
 #endif
index 7a75faf..55cfe19 100644 (file)
@@ -27,8 +27,8 @@
 using std::string;
 MODES_NAMESPACE_USE;
 
-ModeManager::ModeManager(ActionSchemaManager &asMgr, PluginManager &piMgr)
-       : actSchemaMgr(asMgr), pluginMgr(piMgr)
+ModeManager::ModeManager(RuleManager &rMgr, PluginManager &pMgr)
+       : ruleMgr(rMgr), pluginMgr(pMgr)
 {
 }
 
@@ -48,7 +48,7 @@ ModeParser* ModeManager::getModeParser(const string &path)
 {
        int pos = path.find_last_of(".");
        if (MDS_EQUAL == path.substr(pos + 1).compare("xml")) {
-               return new ModeXMLParser(path, actSchemaMgr, pluginMgr);
+               return new ModeXMLParser(path, ruleMgr, pluginMgr);
        } else {
                ERR("Wrong path(%s)", path.c_str());
                throw std::invalid_argument("Wrong path");
index 64c925a..0ea716b 100644 (file)
@@ -20,7 +20,7 @@
 #include "mdss.h"
 #include "ModeParser.h"
 #include "PluginManager.h"
-#include "ActionSchemaManager.h"
+#include "RuleManager.h"
 
 #ifndef MODES_MODE_DEFAULT_DIR
 #define MODES_MODE_DEFAULT_DIR "/usr/share/modes/mode"
@@ -31,7 +31,7 @@ MODES_NAMESPACE_BEGIN
 
 class ModeManager {
 public:
-       ModeManager(ActionSchemaManager &asMgr, PluginManager &piMgr);
+       ModeManager(RuleManager &rMgr, PluginManager &pMgr);
 
        void setOptions(const std::set<std::string> &modeDirs, const std::string &xsdFile);
        void init();
@@ -46,7 +46,7 @@ private:
        std::map<std::string, std::string> modeMap;
        std::set<std::string> modeDirList;
        std::string modeSyntaxFile;
-       ActionSchemaManager &actSchemaMgr;
+       RuleManager &ruleMgr;
        PluginManager &pluginMgr;
 
 #ifdef MDS_TEST
index 8db78e5..43e59b6 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "mdss.h"
 #include "Mode.h"
-#include "ActionSchemaManager.h"
+#include "RuleManager.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -29,10 +29,10 @@ public:
        virtual std::string getModeName() = 0;
        virtual void validateMode(const std::string &syntaxFile) = 0;
 protected:
-       ModeParser(ActionSchemaManager &mgr) :schemaMgr(mgr)
+       ModeParser(RuleManager &rMgr) :ruleMgr(rMgr)
        {
        }
-       ActionSchemaManager &schemaMgr;
+       RuleManager &ruleMgr;
 };
 
 MODES_NAMESPACE_END
index da49577..1d019d6 100644 (file)
@@ -29,11 +29,8 @@ const xmlChar* const ModeTag::MODE = (xmlChar*)"mode";
 const xmlChar* const ModeTag::NAME = (xmlChar*)"name";
 const xmlChar* const ModeTag::TYPE = (xmlChar*)"type";
 const xmlChar* const ModeTag::CUSTOM = (xmlChar*)"custom";
-const xmlChar* const ModeTag::REQ = (xmlChar*)"req";
 const xmlChar* const ModeTag::ACTION = (xmlChar*)"action";
+const xmlChar* const ModeTag::RULE = (xmlChar*)"rule";
 const xmlChar* const ModeTag::RESTICT = (xmlChar*)"restrict";
 const xmlChar* const ModeTag::ID = (xmlChar*)"ID";
-const xmlChar* const ModeTag::PRIORITY = (xmlChar*)"priority";
-const xmlChar* const ModeTag::BEFORE = (xmlChar*)"before";
-const xmlChar* const ModeTag::AFTER = (xmlChar*)"after";
 const char* const ModeTag::RESTICT_LOCK = "lock";
index 4f2d46a..c8a63ca 100644 (file)
@@ -32,8 +32,8 @@ struct ModeTag {
        static const xmlChar* const NAME;
        static const xmlChar* const TYPE;
        static const xmlChar* const CUSTOM;
-       static const xmlChar* const REQ;
        static const xmlChar* const ACTION;
+       static const xmlChar* const RULE;
        static const xmlChar* const RESTICT;
        static const xmlChar* const ID;
        static const xmlChar* const PRIORITY;
index c8a33c1..a8dd922 100644 (file)
 #include "mdss.h"
 #include "Mode.h"
 #include "ModesEx.h"
-#include "TReq.h"
+#include "TAction.h"
 #include "XMLParser.h"
 #include "ModeTag.h"
 
 MODES_NAMESPACE_USE;
 
-ModeXMLParser::ModeXMLParser(const std::string &modeFile, ActionSchemaManager &asMgr, PluginManager &piMgr)
-       : ModeParser(asMgr), pluginManager(piMgr)
+ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr, PluginManager &pMgr)
+       : ModeParser(rMgr), pluginManager(pMgr)
 {
        this->modeFile = modeFile;
 }
@@ -94,8 +94,8 @@ void ModeXMLParser::getDatafromNode(xmlNodePtr node)
 {
        if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::MODE)) {
                parseMode(node);
-       } else if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::REQ)) {
-               parseReq(node);
+       } else if (MDS_EQUAL == xmlStrcmp(node->name, ModeTag::ACTION)) {
+               parseAction(node);
        } else {
                DBG("Unhandled node : %s", node->name);
        }
@@ -131,7 +131,7 @@ std::string ModeXMLParser::getXmlTagStringValue(xmlNodePtr node, const xmlChar*
 
        xmlTagValue = (char*)xmlGetProp(node, tag);
        if (xmlTagValue == NULL) {
-               ERR("XML Value is NULL. Tag[%s]", tag);
+               ERR("attribute(%s) is NULL. ", tag);
                xmlTagString = "";
                return xmlTagString;
        }
@@ -141,32 +141,32 @@ std::string ModeXMLParser::getXmlTagStringValue(xmlNodePtr node, const xmlChar*
        return xmlTagString;
 }
 
-void ModeXMLParser::parseReq(xmlNodePtr node)
+void ModeXMLParser::parseAction(xmlNodePtr node)
 {
-       char *actionProp = (char*)xmlGetProp(node, ModeTag::ACTION);
-       if (actionProp == NULL) {
-               ERR("ACTION TAG Value is null! [%s]", ModeTag::ACTION);
-               throw ModesEx(ModesEx::PARSER_ERROR, "ACTION TAG Value is null!");
+       char *ruleProp = (char*)xmlGetProp(node, ModeTag::RULE);
+       if (ruleProp == NULL) {
+               ERR("rule attribute is null! [%s]", ModeTag::RULE);
+               throw ModesEx(ModesEx::PARSER_ERROR, "rule attribute is null!");
        }
 
-       Req *req = schemaMgr.createAction(actionProp);
-       if (req == nullptr) {
-               WARN("schemaMgr createAction(%s) Fail", actionProp);
-               req = new TReq<std::string>(actionProp);
-               if (req == NULL) {
-                       ERR("Req is null");
-                       throw ModesEx(ModesEx::PARSER_ERROR, "Req is null!");
+       Action *action = ruleMgr.createAction(ruleProp);
+       if (action == nullptr) {
+               WARN("ruleMgr createAction(%s) Fail", ruleProp);
+               action = new TAction<std::string>(ruleProp);
+               if (action == NULL) {
+                       ERR("Action is null");
+                       throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
                }
        }
 
-       bindPlugin(actionProp, req);
-       xmlFree(actionProp);
+       bindPlugin(ruleProp, action);
+       xmlFree(ruleProp);
 
        char *restictProp = (char*)xmlGetProp(node, ModeTag::RESTICT);
        if (restictProp && MDS_EQUAL == strcmp(restictProp, ModeTag::RESTICT_LOCK)) {
-               req->setRestrict(Req::REQ_LOCK);
+               action->setRestrict(Action::REQ_LOCK);
        } else {
-               req->setRestrict(Req::REQ_NONE);
+               action->setRestrict(Action::REQ_NONE);
        }
        xmlFree(restictProp);
 
@@ -175,19 +175,19 @@ void ModeXMLParser::parseReq(xmlNodePtr node)
                ERR("Node Content is null!");
        }
 
-       req->setValue(nodeContent ? nodeContent : "");
+       action->setValue(nodeContent ? nodeContent : "");
        xmlFree(nodeContent);
 
-       req->printInfo();
+       action->printInfo();
 
-       mode.addRequirement(req);
+       mode.addAction(action);
 }
 
-void ModeXMLParser::bindPlugin(const std::string &name, Req *req)
+void ModeXMLParser::bindPlugin(const std::string &name, Action *action)
 {
        std::string pluginName;
        int pos = name.find_first_of(".");
        pluginName = name.substr(0, pos);
-       req->setPlugin(pluginManager.getPlugin(pluginName));
+       action->setPlugin(pluginManager.getPlugin(pluginName));
 }
 
index 0e2df19..9a2d84e 100644 (file)
@@ -24,7 +24,7 @@ MODES_NAMESPACE_BEGIN
 
 class ModeXMLParser : public ModeParser {
 public:
-       ModeXMLParser(const std::string &modeFile, ActionSchemaManager &mgr, PluginManager &pluginMgr);
+       ModeXMLParser(const std::string &modeFile, RuleManager &mgr, PluginManager &pluginMgr);
        ~ModeXMLParser();
 
        Mode getMode() override;
@@ -39,8 +39,8 @@ private:
        std::string getModeType(xmlNodePtr node);
        bool getModeCustom(xmlNodePtr node);
        std::string getXmlTagStringValue(xmlNodePtr node, const xmlChar *tag);
-       void parseReq(xmlNodePtr node);
-       void bindPlugin(const std::string &name, Req *req);
+       void parseAction(xmlNodePtr node);
+       void bindPlugin(const std::string &name, Action *action);
 
        PluginManager &pluginManager;
        Mode mode;
index a82e920..b42ce05 100644 (file)
@@ -25,8 +25,8 @@ struct ModesConfig {
        std::string pluginDir;
        std::set<std::string> modeXMLDirs;
        std::string modeXsdFile;
-       std::string actionSchemaXsdFile;
-       std::string actionSchemaDir;
+       std::string actionRuleXsdFile;
+       std::string actionRuleDir;
 };
 
 MODES_NAMESPACE_END
index 17168f4..bfe6787 100644 (file)
@@ -20,7 +20,7 @@
 MODES_NAMESPACE_USE;
 
 ModeManager* RequestHandler::modeMgr = NULL;
-ActionSchemaManager *RequestHandler::actSchemaMgr = NULL;
+RuleManager *RequestHandler::ruleMgr = NULL;
 PluginManager *RequestHandler::pluginMgr = NULL;
 
 void RequestHandler::setModeManager(ModeManager *mgr)
@@ -28,9 +28,9 @@ void RequestHandler::setModeManager(ModeManager *mgr)
        modeMgr = mgr;
 }
 
-void RequestHandler::setActionSchemaManager(ActionSchemaManager *mgr)
+void RequestHandler::setRuleManager(RuleManager *mgr)
 {
-       actSchemaMgr = mgr;
+       ruleMgr = mgr;
 }
 
 void RequestHandler::setPluginManager(PluginManager *mgr)
@@ -96,15 +96,15 @@ Mode RequestHandler::getModefromData(GVariant *inData)
                        DBG("id : %s action_name : %s value : %s restiction : %d",
                                        id[0] != '\0' ? id : "NULL", act_name, value, restriction);
 
-                       Req *req = createReq(id, act_name, value, restriction);
+                       Action *action = createAction(id, act_name, value, restriction);
 
-                       mode.addRequirement(req);
+                       mode.addAction(action);
                }
        } catch (ModesEx &e) {
-               ERR("createReq(%s, %s, %s, %d) Fail(%s)", id, act_name, value, restriction, e.what());
+               ERR("createAction(%s, %s, %s, %d) Fail(%s)", id, act_name, value, restriction, e.what());
                g_variant_iter_free(iter);
                g_variant_unref(actionList);
-               throw ModesEx(ModesEx::INVALID_ARG, "Req is null!");
+               throw ModesEx(ModesEx::INVALID_ARG, "Action is null!");
        }
        g_variant_iter_free(iter);
        g_variant_unref(actionList);
@@ -112,29 +112,29 @@ Mode RequestHandler::getModefromData(GVariant *inData)
        return mode;
 }
 
-Req *RequestHandler::createReq(char *id, char *act_name, char *contents, int restriction)
+Action* RequestHandler::createAction(char *id, char *ruleName, char *contents, int restriction)
 {
        std::string pluginName;
 
-       Req *req = actSchemaMgr->createAction(act_name);
-       if (req == nullptr) {
-               ERR("Req is null");
-               throw ModesEx(ModesEx::PARSER_ERROR, "Req is null!");
+       Action *action = ruleMgr->createAction(ruleName);
+       if (action == nullptr) {
+               ERR("Action is null");
+               throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
        }
 
-       std::string actionName = act_name;
+       std::string actionName = ruleName;
        int pos = actionName.find_first_of(".");
        pluginName = actionName.substr(0, pos);
-       req->setPlugin(pluginMgr->getPlugin(pluginName));
+       action->setPlugin(pluginMgr->getPlugin(pluginName));
 
        if (restriction)
-               req->setRestrict(Req::REQ_LOCK);
+               action->setRestrict(Action::REQ_LOCK);
        else
-               req->setRestrict(Req::REQ_NONE);
+               action->setRestrict(Action::REQ_NONE);
 
-       req->setID(id);
-       req->setValue(contents);
-       req->printInfo();
+       action->setID(id);
+       action->setValue(contents);
+       action->printInfo();
 
-       return req;
+       return action;
 }
index 61d498e..b42f72c 100644 (file)
@@ -19,7 +19,7 @@
 #include "common/dbus.h"
 #include "ModeManager.h"
 #include "PluginManager.h"
-#include "ActionSchemaManager.h"
+#include "RuleManager.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -31,15 +31,15 @@ public:
                GVariant *arg_modeData, gpointer userData);
 
        static void setModeManager(ModeManager *mgr);
-       static void setActionSchemaManager(ActionSchemaManager *mgr);
+       static void setRuleManager(RuleManager *mgr);
        static void setPluginManager(PluginManager *mgr);
 
 private:
        static Mode getModefromData(GVariant *inData);
-       static Req *createReq(char *id, char *act_name, char *contents, int restriction);
+       static Action* createAction(char *id, char *act_name, char *contents, int restriction);
 
        static ModeManager *modeMgr;
-       static ActionSchemaManager *actSchemaMgr;
+       static RuleManager *ruleMgr;
        static PluginManager *pluginMgr;
 };
 
diff --git a/supervisor/RuleManager.cpp b/supervisor/RuleManager.cpp
new file mode 100644 (file)
index 0000000..272bfae
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "RuleManager.h"
+
+#include <dirent.h>
+#include <cstring>
+#include "mdss.h"
+#include "TActionRule.h"
+#include "ModesEx.h"
+
+using std::string;
+MODES_NAMESPACE_USE;
+
+const xmlChar* const RuleManager::ACTION_RULE_TAG = (xmlChar*)"actionRule";
+const xmlChar* const RuleManager::ACTION_RULE_TAG_RULE = (xmlChar*)"rule";
+const xmlChar* const RuleManager::RULE_TAGS[] = {
+       (xmlChar*)"name",
+       (xmlChar*)"type",
+       (xmlChar*)"plugin",
+       (xmlChar*)"alias",
+       (xmlChar*)"conflict",
+       (xmlChar*)"defaultVal"
+};
+
+void RuleManager::makeRuleMap()
+{
+       if (ruleDir.empty()) {
+               ERR("No ruleDir");
+               ruleDir = MODES_ACTIONRULE_DEFAULT_DIR;
+       }
+
+       DIR *dir;
+       if ((dir = opendir(ruleDir.c_str())) == NULL)
+               ERR("opendir(%s) Fail(%s)", ruleDir.c_str(), strerror(errno));
+
+       struct dirent *entry;
+       while ((entry = readdir(dir)) != NULL) {
+               string file(entry->d_name);
+               size_t pos = file.find_last_of("_");
+               if (string::npos == pos
+                       || file.compare(pos, sizeof(MODES_ACTIONRULE_FILE_SUFFIX) - 1, MODES_ACTIONRULE_FILE_SUFFIX)) {
+                       continue;
+               }
+
+               string fileFullPath = ruleDir + "/" + string(entry->d_name);
+               try {
+                       parseActionRule(fileFullPath);
+                       DBG("Action Rule(size=%d) Load", ruleMap.size());
+               }
+               catch (ModesEx &e) {
+                       ERR("parseActionRule(%s) Fail(%s)", fileFullPath.c_str(), e.what());
+               }
+       }
+       closedir(dir);
+}
+
+void RuleManager::freeRuleMap()
+{
+       for (auto it = ruleMap.begin(); it != ruleMap.end(); ++it)
+               delete it->second;
+}
+
+
+void RuleManager::parseElement(xmlNodePtr cur, ActionRule *actionRule)
+{
+       RET_IF(NULL == actionRule);
+
+       if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemAlias])) {
+               char *alias = (char*)xmlGetProp(cur, RULE_TAGS[TagAttName]);
+               if (NULL == alias) {
+                       ERR("%s : No %s", RULE_TAGS[TagElemAlias], RULE_TAGS[TagAttName]);
+                       return;
+               }
+
+               char *value = (char*)xmlNodeGetContent(cur);
+               if (NULL == value) {
+                       ERR("%s(%s) : No value", RULE_TAGS[TagElemAlias], alias);
+                       xmlFree(alias);
+                       return;
+               }
+
+               actionRule->addAlias(alias, value);
+               xmlFree(value);
+               xmlFree(alias);
+       } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemDefValue])) {
+               char *value = (char*)xmlNodeGetContent(cur);
+               if (NULL == value) {
+                       ERR("%s : No value", RULE_TAGS[TagElemDefValue]);
+                       return;
+               }
+               actionRule->addDefaultValue(value);
+       } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemConflict])) {
+               // TODO: enhanced feature
+               DBG("TBD(%s)", cur->name);
+       } else {
+               DBG("Invalid node(%s)", cur->name);
+       }
+}
+
+Action* RuleManager::createAction(const string &ruleName)
+{
+       std::map<std::string, ActionRule*>::iterator it = ruleMap.find(ruleName);
+       if (ruleMap.end() != it) {
+               ActionRule *rule = it->second;
+               return rule->makeAction();
+       } else {
+               ERR("No rule(%s)", ruleName.c_str());
+               return nullptr;
+       }
+}
+
+void RuleManager::setOptions(const string &actionRuleDir, const string &actionRuleXsd)
+{
+       ruleDir = actionRuleDir;
+       ruleXsd = actionRuleXsd;
+}
+
+string RuleManager::getProp(xmlNodePtr node, int att)
+{
+       char *tmp;
+       string returnStr;
+
+       tmp = (char*)xmlGetProp(node, RULE_TAGS[att]);
+       if (tmp) {
+               returnStr = tmp;
+               xmlFree(tmp);
+       } else {
+               ERR("Rule : No %s", RULE_TAGS[att]);
+               throw ModesEx(ModesEx::NO_DATA);
+       }
+
+       return returnStr;
+}
+
+ActionRule* RuleManager::makeRule(xmlNodePtr node)
+{
+       string type, name, plugin;
+       ActionRule *actionRule = NULL;
+
+       try {
+               name = getProp(node, TagAttName);
+               type = getProp(node, TagAttType);
+               plugin = getProp(node, TagAttPlugin);
+       }
+       catch (ModesEx &e) {
+               ERR("getProp() Fail(%s)", e.what());
+               return nullptr;
+       }
+
+       DBG("Action(%s, %s) Added", name.c_str(), type.c_str());
+
+       if (MDS_EQUAL == type.compare("int"))
+               actionRule = new TActionRule<int>(name);
+       else if (MDS_EQUAL == type.compare("float"))
+               actionRule = new TActionRule<float>(name);
+       else if (MDS_EQUAL == type.compare("bool"))
+               actionRule = new TActionRule<bool>(name);
+       else
+               actionRule = new TActionRule<string>(name);
+
+       actionRule->setPlugin(plugin);
+       for (xmlNode *cur = node->children; cur; cur = cur->next) {
+               if (xmlIsBlankNode(cur))
+                       continue;
+               parseElement(cur, actionRule);
+       }
+
+       return actionRule;
+}
+
+void RuleManager::parseRule(xmlNodePtr node)
+{
+       for (xmlNodePtr cur = node; cur; cur = cur->next) {
+               if (xmlIsBlankNode(cur))
+                       continue;
+
+               if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_RULE_TAG_RULE)) {
+                       ActionRule *rule = makeRule(cur);
+                       ruleMap.insert(std::pair<string, ActionRule*>(rule->getName(), rule));
+               } else {
+                       DBG("Invalid node(%s)", cur->name);
+                       parseRule(cur->children);
+               }
+       }
+}
+
+void RuleManager::parseActionRule(const string &xmlFile)
+{
+       if (ruleXsd.empty()) {
+               ERR("No ruleXsd");
+               ruleXsd = MODES_ACTIONRULE_DEFAULT_XSD;
+       }
+
+       try {
+               XMLParser parser(xmlFile);
+               parser.validate(ruleXsd);
+
+               xmlNodePtr root = parser.getRoot();
+               if (MDS_EQUAL != xmlStrcmp(root->name, (xmlChar*)MODES_XML_ROOT)) {
+                       ERR("Invalid root element(%s, %s)", root->name, xmlFile.c_str());
+                       throw ModesEx(ModesEx::PARSER_ERROR, "Invalid file");
+               }
+
+               parseRule(root);
+       }
+       catch (ModesEx &e) {
+               ERR("parser Fail(%s)", e.what());
+       }
+}
similarity index 57%
rename from supervisor/ActionSchemaManager.h
rename to supervisor/RuleManager.h
index c848b04..9b6a4d8 100644 (file)
 #include <string>
 #include <libxml/tree.h>
 #include "mdss.h"
-#include "ActionSchema.h"
-#include "Req.h"
+#include "ActionRule.h"
+#include "Action.h"
 #include "XMLParser.h"
 
 MODES_NAMESPACE_BEGIN
 
-class ActionSchemaManager {
+class RuleManager {
 public:
        enum {
                TagAttName,
@@ -37,24 +37,24 @@ public:
                TagMax
        };
 
-       void setOptions(const std::string &actionSchemaDir, const std::string &actionSchemaXsd);
-       void makeActionSchemaMap();
-       void freeActionSchemaMap();
-       Req* createAction(const std::string &actionName);
+       void setOptions(const std::string &actionRuleDir, const std::string &actionRuleXsd);
+       void makeRuleMap();
+       void freeRuleMap();
+       Action* createAction(const std::string &actionName);
 private:
-       static const xmlChar* const ACTION_SCHEMA_TAG;
-       static const xmlChar* const ACTION_SCHEMA_TAG_ACTION;
-       static const xmlChar* const ACTION_TAGS[];
+       static const xmlChar* const ACTION_RULE_TAG;
+       static const xmlChar* const ACTION_RULE_TAG_RULE;
+       static const xmlChar* const RULE_TAGS[];
 
-       ActionSchema* makeActionSchema(xmlNodePtr node);
-       void parseAction(xmlNodePtr node);
+       ActionRule* makeRule(xmlNodePtr node);
+       void parseRule(xmlNodePtr node);
        std::string getProp(xmlNodePtr node, int att);
-       void parseActionSchema(const std::string &xmlFile);
-       void parseElement(xmlNodePtr node, ActionSchema *actionSchema);
+       void parseActionRule(const std::string &xmlFile);
+       void parseElement(xmlNodePtr node, ActionRule *actionRule);
 
-       std::map<std::string, ActionSchema*> schemaMap;
-       std::string actSchemaDir;
-       std::string actSchemaXsd;
+       std::map<std::string, ActionRule*> ruleMap;
+       std::string ruleDir;
+       std::string ruleXsd;
 };
 
 MODES_NAMESPACE_END
index 56f7bc7..7d3e552 100644 (file)
 MODES_NAMESPACE_USE;
 
 ModeSupervisorNamespace::Supervisor::Supervisor()
-       :modeMgr(actSchemaMgr, pluginMgr)
+       :modeMgr(ruleMgr, pluginMgr)
 {
 }
 
 void Supervisor::init()
 {
        RequestHandler::setModeManager(&modeMgr);
-       RequestHandler::setActionSchemaManager(&actSchemaMgr);
+       RequestHandler::setRuleManager(&ruleMgr);
        RequestHandler::setPluginManager(&pluginMgr);
 
        try {
                clientConn.startDbus();
-               actSchemaMgr.makeActionSchemaMap();
+               ruleMgr.makeRuleMap();
                pluginMgr.loadPlugins();
                modeMgr.init();
        }
@@ -48,10 +48,10 @@ void Supervisor::init()
 void Supervisor::deInit()
 {
        pluginMgr.unloadPlugins();
-       actSchemaMgr.freeActionSchemaMap();
+       ruleMgr.freeRuleMap();
        clientConn.stopDbus();
        RequestHandler::setModeManager(NULL);
-       RequestHandler::setActionSchemaManager(NULL);
+       RequestHandler::setRuleManager(NULL);
        RequestHandler::setPluginManager(NULL);
 }
 
@@ -59,7 +59,7 @@ void Supervisor::setOptions(const ModesConfig &config)
 {
        modeMgr.setOptions(config.modeXMLDirs, config.modeXsdFile);
        pluginMgr.setPluginDir(config.pluginDir);
-       actSchemaMgr.setOptions(config.actionSchemaDir, config.actionSchemaXsdFile);
+       ruleMgr.setOptions(config.actionRuleDir, config.actionRuleXsdFile);
 }
 
 void Supervisor::registerHandler()
index 9530cbe..75dd23d 100644 (file)
@@ -21,7 +21,7 @@
 #include "ModesConfig.h"
 #include "PluginManager.h"
 #include "ClientConnection.h"
-#include "ActionSchemaManager.h"
+#include "RuleManager.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -35,7 +35,7 @@ public:
        void registerHandler();
 private:
        ClientConnection clientConn;
-       ActionSchemaManager actSchemaMgr;
+       RuleManager ruleMgr;
        PluginManager pluginMgr;
        ModeManager modeMgr;
 };
similarity index 85%
rename from supervisor/TReq.h
rename to supervisor/TAction.h
index 4527e10..5f228fb 100644 (file)
 #include <string>
 #include <sstream>
 #include "mdss.h"
-#include "Req.h"
+#include "Action.h"
 
 MODES_NAMESPACE_BEGIN
 
 template <typename T>
-class TReq : public Req {
+class TAction : public Action {
 public:
-       TReq(const std::string &name)
-               :Req(name)
+       TAction(const std::string &name)
+               :Action(name)
        {
        }
 
@@ -64,11 +64,11 @@ public:
 
        void apply() override
        {
-               int pos = actionName.find_first_of(".");
+               int pos = ruleName.find_first_of(".");
                if (plugin) {
-                       plugin->set(actionName.substr(pos + 1), value);
+                       plugin->set(ruleName.substr(pos + 1), value);
                } else {
-                       ERR("Action(%s) : No plugin", actionName.c_str());
+                       ERR("Action(%s) : No plugin", ruleName.c_str());
                }
        }
 private:
similarity index 81%
rename from supervisor/TActionSchema.h
rename to supervisor/TActionRule.h
index df4cedc..314dfa5 100644 (file)
 #include <string>
 #include <sstream>
 #include "mdss.h"
-#include "TReq.h"
-#include "ActionSchema.h"
+#include "TAction.h"
+#include "ActionRule.h"
 
 MODES_NAMESPACE_BEGIN
 
 template <typename T>
-class TActionSchema : public ActionSchema {
+class TActionRule : public ActionRule {
 public:
-       TActionSchema(const std::string &name)
+       TActionRule(const std::string &name)
        {
-               actionName = name;
+               ruleName = name;
        }
 
-       Req* makeRequirement() override
+       Action* makeAction() override
        {
-               TReq<T> *req = new TReq<T>(actionName);
-               req->setValueAliases(valueAliasList);
+               TAction<T> *action = new TAction<T>(ruleName);
+               action->setValueAliases(valueAliasList);
 
-               return req;
+               return action;
        }
 
        void addDefaultValue(const std::string &val) override
index 3ac08c1..b982a7e 100644 (file)
@@ -15,7 +15,7 @@
  */
 #include <libxml/tree.h>
 #include <libxml/xmlschemas.h>
-#include "Req.h"
+#include "Action.h"
 #include "ModeTag.h"
 #include "ModesEx.h"
 #include "XMLGenerator.h"
@@ -74,20 +74,20 @@ void XMLGenerator::makeModeXML(const std::string &filename, const Mode &mode)
        xmlSetProp(modeNode, ModeTag::CUSTOM, (xmlChar*)((mode.getCustomized())? "yes": "no"));
        xmlAddChild(rootNode, modeNode);
 
-       std::list<std::shared_ptr<Req>> reqList = mode.getReqList();
-       std::list<std::shared_ptr<Req>>::iterator it;
-       for (it = reqList.begin(); it != reqList.end(); it++) {
+       std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+       std::list<std::shared_ptr<Action>>::iterator it;
+       for (it = actionList.begin(); it != actionList.end(); it++) {
                xmlNodePtr reqNode;
-               Req::ReqRestrict restriction = (*it)->getRestrict();
+               Action::ActionRestrict restriction = (*it)->getRestrict();
 
-               reqNode = xmlNewNode(NULL, ModeTag::REQ);
+               reqNode = xmlNewNode(NULL, ModeTag::ACTION);
 
                if (!(*it)->getID().empty())
                        xmlSetProp(reqNode, ModeTag::ID, (xmlChar*)(*it)->getID().c_str());
 
-               xmlSetProp(reqNode, ModeTag::ACTION, (xmlChar*)(*it)->getName().c_str());
+               xmlSetProp(reqNode, ModeTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
 
-               if (restriction == Req::ReqRestrict::REQ_LOCK)
+               if (restriction == Action::ActionRestrict::REQ_LOCK)
                        xmlSetProp(reqNode, ModeTag::RESTICT, (xmlChar*)ModeTag::RESTICT_LOCK);
 
                xmlNodeSetContent(reqNode, (xmlChar*)(*it)->getStringOfValue().c_str());
index 1b76a87..3f565c0 100644 (file)
@@ -20,9 +20,9 @@ FILE(GLOB GTEST_MODEMGR_SRCS
                ${SUPERVISOR_DIR}/XMLGenerator.cpp
                ${SUPERVISOR_DIR}/ModeManager.cpp
                ${SUPERVISOR_DIR}/ModeXMLParser.cpp
-               ${SUPERVISOR_DIR}/Req.cpp
-               ${SUPERVISOR_DIR}/ActionSchema.cpp
-               ${SUPERVISOR_DIR}/ActionSchemaManager.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
                ${SUPERVISOR_DIR}/Mode.cpp
                ${SUPERVISOR_DIR}/ModesEx.cpp
                ${SUPERVISOR_DIR}/PluginManager.cpp
@@ -48,12 +48,11 @@ SET(GTEST_PARSER "modes-gtest-parser")
 FILE(GLOB GTEST_PARSER_SRCS
                ${SUPERVISOR_DIR}/XMLParser.cpp
                ${SUPERVISOR_DIR}/PluginManager.cpp
-               ${SUPERVISOR_DIR}/Req.cpp
-               ${SUPERVISOR_DIR}/ActionSchema.cpp
-               ${SUPERVISOR_DIR}/ActionSchemaManager.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
                ${SUPERVISOR_DIR}/ModeXMLParser.cpp
                ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
                ${SUPERVISOR_DIR}/Mode.cpp
                ${SUPERVISOR_DIR}/ModeTag.cpp
                "modes_test_parser.cpp"
@@ -82,12 +81,11 @@ FILE(GLOB GTEST_PARSER_SRCS
                ${SUPERVISOR_DIR}/ModeTag.cpp
                ${SUPERVISOR_DIR}/XMLParser.cpp
                ${SUPERVISOR_DIR}/PluginManager.cpp
-               ${SUPERVISOR_DIR}/Req.cpp
-               ${SUPERVISOR_DIR}/ActionSchema.cpp
-               ${SUPERVISOR_DIR}/ActionSchemaManager.cpp
+               ${SUPERVISOR_DIR}/Action.cpp
+               ${SUPERVISOR_DIR}/ActionRule.cpp
+               ${SUPERVISOR_DIR}/RuleManager.cpp
                ${SUPERVISOR_DIR}/ModeXMLParser.cpp
                ${SUPERVISOR_DIR}/ModesEx.cpp
-               ${SUPERVISOR_DIR}/Action.cpp
                ${SUPERVISOR_DIR}/Mode.cpp
                ${SUPERVISOR_DIR}/XMLGenerator.cpp
                "modes_test_generator.cpp"
index 0adcc17..981e825 100755 (executable)
@@ -24,7 +24,7 @@ then
        $WORKING_DIR/modes-gtest-generator
 else
        cp $DATA_DIR/mode/*_mode.xml $WORKING_DIR
-       cp $DATA_DIR/action/*_schema.xml $WORKING_DIR
+       cp $DATA_DIR/rule/*_rule.xml $WORKING_DIR
        cp $DATA_DIR/xsd/*.xsd $WORKING_DIR
        mkdir -p $WORKING_DIR/extra
        sed s/ex1/ex3/g $WORKING_DIR/tizen_ex1_mode.xml > $WORKING_DIR/extra/tizen_ex3_mode.xml
index 2dec3e5..d7c26a9 100644 (file)
@@ -20,7 +20,7 @@
 #include "supervisor/ModesEx.h"
 #include "supervisor/ModeXMLParser.h"
 #include "supervisor/XMLGenerator.h"
-#include "supervisor/ActionSchemaManager.h"
+#include "supervisor/RuleManager.h"
 
 MODES_NAMESPACE_USE;
 using namespace std;
@@ -28,9 +28,9 @@ using namespace std;
 TEST(XMLGenerator, makeModeXML)
 {
        PluginManager pluginManager;
-       ActionSchemaManager schemaMgr;
+       RuleManager ruleMgr;
 
-       ModeXMLParser modeparser("tizen_ex1_mode.xml", schemaMgr, pluginManager);
+       ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, pluginManager);
        Mode mode = modeparser.getMode();
 
        try {
@@ -41,15 +41,15 @@ TEST(XMLGenerator, makeModeXML)
                FAIL();
        }
 
-       ModeXMLParser genmodeparser("tizen_gen_ex1_mode.xml", schemaMgr, pluginManager);
+       ModeXMLParser genmodeparser("tizen_gen_ex1_mode.xml", ruleMgr, pluginManager);
        Mode genMode = genmodeparser.getMode();
 
        EXPECT_EQ("ex1", genmodeparser.getModeName());
-       std::list<std::shared_ptr<Req>> reqList = mode.getReqList();
-       EXPECT_FALSE(reqList.empty());
+       std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+       EXPECT_FALSE(actionList.empty());
 
-       for (std::list<std::shared_ptr<Req>>::iterator it = reqList.begin(); it != reqList.end(); ++it) {
-               cout << "* Req : " << (*it)->getName() << endl;
+       for (std::list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
+               cout << "* Action : " << (*it)->getRuleName() << endl;
                cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
                cout << "\t\t- Content : " << (*it)->getStringOfValue() << endl;
        }
@@ -59,9 +59,9 @@ TEST(XMLGenerator, exFileName)
 {
        EXPECT_THROW({
                PluginManager pluginManager;
-               ActionSchemaManager schemaMgr;
+               RuleManager ruleMgr;
 
-               ModeXMLParser modeparser("tizen_ex1_mode.xml", schemaMgr, pluginManager);
+               ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, pluginManager);
                Mode mode = modeparser.getMode();
 
                XMLGenerator xmlGenerator;
index c60ca10..4dddf9f 100644 (file)
@@ -24,8 +24,8 @@ MODES_NAMESPACE_BEGIN
 class ModeManagerTest {
 public:
        ModeManagerTest();
-       ActionSchemaManager asMgr;
-       PluginManager piMgr;
+       RuleManager rMgr;
+       PluginManager pMgr;
        ModeManager mdMgr;
 
        set<string> getDirectories();
@@ -37,7 +37,7 @@ MODES_NAMESPACE_END
 MODES_NAMESPACE_USE;
 
 ModeManagerTest::ModeManagerTest()
-       :mdMgr(asMgr, piMgr)
+       :mdMgr(rMgr, pMgr)
 {
        std::set<std::string> modeDirs;
        modeDirs.insert(".");
index 081e84b..c9290f8 100644 (file)
@@ -18,7 +18,7 @@
 #include <gtest/gtest.h>
 #include "supervisor/Mode.h"
 #include "supervisor/ModeXMLParser.h"
-#include "supervisor/ActionSchemaManager.h"
+#include "supervisor/RuleManager.h"
 
 MODES_NAMESPACE_USE;
 using namespace std;
@@ -27,21 +27,21 @@ MODES_NAMESPACE_BEGIN
 class TestParser {
 public:
        void parserTest(const string &fileName);
-       list<std::shared_ptr<Req>> getActionList(Mode& m);
+       list<std::shared_ptr<Action>> getActionList(Mode& m);
 private:
 };
 MODES_NAMESPACE_END
 
-list<std::shared_ptr<Req>> TestParser::getActionList(Mode& m)
+list<std::shared_ptr<Action>> TestParser::getActionList(Mode& m)
 {
-       return m.reqList;
+       return m.actionList;
 }
 
 TEST(XMLParser, getModeName)
 {
        PluginManager pluginManager;
-       ActionSchemaManager schemaMgr;
-       ModeXMLParser modeparser("tizen_ex1_mode.xml", schemaMgr, pluginManager);
+       RuleManager ruleMgr;
+       ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, pluginManager);
        string modename = modeparser.getModeName();
 
        EXPECT_EQ("ex1", modeparser.getModeName());
@@ -50,8 +50,8 @@ TEST(XMLParser, getModeName)
 TEST(XMLParser, getMode)
 {
        PluginManager pluginManager;
-       ActionSchemaManager schemaMgr;
-       ModeXMLParser modeparser("tizen_ex2_mode.xml", schemaMgr, pluginManager);
+       RuleManager ruleMgr;
+       ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr, pluginManager);
        Mode mode = modeparser.getMode();
 
        //EXPECT_TRUE(mode.empty());
@@ -60,8 +60,8 @@ TEST(XMLParser, getMode)
 TEST(Mode, getModeName)
 {
        PluginManager pluginManager;
-       ActionSchemaManager schemaMgr;
-       ModeXMLParser modeparser("tizen_ex2_mode.xml", schemaMgr, pluginManager);
+       RuleManager ruleMgr;
+       ModeXMLParser modeparser("tizen_ex2_mode.xml", ruleMgr, pluginManager);
        Mode mode = modeparser.getMode();
        EXPECT_EQ("ex2", mode.getName());
 }
@@ -69,8 +69,8 @@ TEST(Mode, getModeName)
 TEST(Mode, getModeType)
 {
        PluginManager pluginManager;
-       ActionSchemaManager schemaMgr;
-       ModeXMLParser modeparser("tizen_ex1_mode.xml", schemaMgr, pluginManager);
+       RuleManager ruleMgr;
+       ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, pluginManager);
        Mode mode = modeparser.getMode();
        EXPECT_EQ("normal", mode.getModeType());
 }
@@ -78,16 +78,16 @@ TEST(Mode, getModeType)
 TEST(Mode, printAction)
 {
        PluginManager pluginManager;
-       ActionSchemaManager schemaMgr;
-       ModeXMLParser modeparser("tizen_ex1_mode.xml", schemaMgr, pluginManager);
+       RuleManager ruleMgr;
+       ModeXMLParser modeparser("tizen_ex1_mode.xml", ruleMgr, pluginManager);
        Mode mode = modeparser.getMode();
        TestParser parserT;
 
-       list<std::shared_ptr<Req>> reqList = parserT.getActionList(mode);
-       EXPECT_FALSE(reqList.empty());
+       list<std::shared_ptr<Action>> actionList = parserT.getActionList(mode);
+       EXPECT_FALSE(actionList.empty());
 
-       for (list<std::shared_ptr<Req>>::iterator it = reqList.begin(); it != reqList.end(); ++it) {
-               cout << "* Req : " << (*it)->getName() << endl;
+       for (list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
+               cout << "* Action : " << (*it)->getRuleName() << endl;
                cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
                //cout << "\t\t- Content : " << (*it)->getValue() << endl;
        }
index 0e36f41..7800aee 100644 (file)
@@ -26,7 +26,7 @@ public:
        bool emptyPluginMap();
        string getpluginDir();
 
-       PluginManager piMgr;
+       PluginManager pMgr;
 };
 MODES_NAMESPACE_END
 
@@ -34,30 +34,30 @@ MODES_NAMESPACE_USE;
 
 bool TestPluginBroker::emptyPluginMap()
 {
-       return piMgr.pluginMap.empty();
+       return pMgr.pluginMap.empty();
 }
 
 string TestPluginBroker::getpluginDir()
 {
-       return piMgr.pluginDir;
+       return pMgr.pluginDir;
 }
 
 TEST(PluginManager, readLibraryList)
 {
        TestPluginBroker broker;
 
-       broker.piMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
+       broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
        try {
-               broker.piMgr.loadPlugins();
+               broker.pMgr.loadPlugins();
        }
        catch (ModesEx &e) {
-               broker.piMgr.setPluginDir("../plugin");
-               EXPECT_NO_THROW(broker.piMgr.loadPlugins());
+               broker.pMgr.setPluginDir("../plugin");
+               EXPECT_NO_THROW(broker.pMgr.loadPlugins());
        }
 
        EXPECT_FALSE(broker.emptyPluginMap());
 
-       list<string> pluginList = broker.piMgr.getPluginList();
+       list<string> pluginList = broker.pMgr.getPluginList();
        if (pluginList.empty()) {
                FAIL() << "getPluginList() Fail:This should never be reached";
        } else {
@@ -71,7 +71,7 @@ TEST(PluginManager, setPluginDir)
        TestPluginBroker broker;
 
        string path = "../plugin";
-       broker.piMgr.setPluginDir(path);
+       broker.pMgr.setPluginDir(path);
 
        EXPECT_EQ(path, broker.getpluginDir());
 }
@@ -80,7 +80,7 @@ TEST(PluginManager, unloadClassMap)
 {
        TestPluginBroker broker;
 
-       int ret = broker.piMgr.unloadPlugins();
+       int ret = broker.pMgr.unloadPlugins();
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        EXPECT_TRUE(broker.emptyPluginMap());
 }
@@ -90,18 +90,18 @@ TEST(PluginManager, getPluginTest)
        int ret;
        TestPluginBroker broker;
 
-       broker.piMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
+       broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
        try {
-               broker.piMgr.loadPlugins();
+               broker.pMgr.loadPlugins();
        }
        catch (ModesEx &e) {
-               broker.piMgr.setPluginDir("../plugin");
-               EXPECT_NO_THROW(broker.piMgr.loadPlugins());
+               broker.pMgr.setPluginDir("../plugin");
+               EXPECT_NO_THROW(broker.pMgr.loadPlugins());
        }
 
        EXPECT_FALSE(broker.emptyPluginMap());
 
-       Plugin *plugin = broker.piMgr.getPlugin("test");
+       Plugin *plugin = broker.pMgr.getPlugin("test");
        ASSERT_TRUE(plugin != NULL);
 
        ret = plugin->set("testSetInt", 0);
@@ -128,7 +128,7 @@ TEST(PluginManager, getPluginTest)
        string strVal = plugin->getString("testGetString");
        EXPECT_EQ(strVal, "test");
 
-       ret = broker.piMgr.unloadPlugins();
+       ret = broker.pMgr.unloadPlugins();
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        EXPECT_TRUE(broker.emptyPluginMap());
 }
@@ -138,22 +138,22 @@ TEST(PluginManager, getPluginWifi)
        int ret;
        TestPluginBroker broker;
 
-       broker.piMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
+       broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
        try {
-               broker.piMgr.loadPlugins();
+               broker.pMgr.loadPlugins();
        }
        catch (ModesEx &e) {
-               broker.piMgr.setPluginDir("../plugin");
-               EXPECT_NO_THROW(broker.piMgr.loadPlugins());
+               broker.pMgr.setPluginDir("../plugin");
+               EXPECT_NO_THROW(broker.pMgr.loadPlugins());
 
-               ret = broker.piMgr.unloadPlugins();
+               ret = broker.pMgr.unloadPlugins();
                EXPECT_EQ(ret, MODES_ERROR_NONE);
                return;
        }
 
        EXPECT_FALSE(broker.emptyPluginMap());
 
-       Plugin *plugin = broker.piMgr.getPlugin("wifi");
+       Plugin *plugin = broker.pMgr.getPlugin("wifi");
        ASSERT_TRUE(plugin != NULL);
 
        ret = plugin->set("power", false);
@@ -183,7 +183,7 @@ TEST(PluginManager, getPluginWifi)
        ret = plugin->set("abcdefg", true);
        EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
 
-       ret = broker.piMgr.unloadPlugins();
+       ret = broker.pMgr.unloadPlugins();
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        EXPECT_TRUE(broker.emptyPluginMap());
 }
@@ -193,15 +193,15 @@ TEST(PluginManager, getPluginVconf)
        int ret;
        TestPluginBroker broker;
 
-       broker.piMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
+       broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
        try {
-               broker.piMgr.loadPlugins();
+               broker.pMgr.loadPlugins();
        }
        catch (ModesEx &e) {
-               broker.piMgr.setPluginDir("../plugin");
-               EXPECT_NO_THROW(broker.piMgr.loadPlugins());
+               broker.pMgr.setPluginDir("../plugin");
+               EXPECT_NO_THROW(broker.pMgr.loadPlugins());
 
-               ret = broker.piMgr.unloadPlugins();
+               ret = broker.pMgr.unloadPlugins();
                EXPECT_EQ(ret, MODES_ERROR_NONE);
                return;
        }
@@ -210,7 +210,7 @@ TEST(PluginManager, getPluginVconf)
 
        bool boolRet;
 
-       Plugin *plugin = broker.piMgr.getPlugin("vconf");
+       Plugin *plugin = broker.pMgr.getPlugin("vconf");
        ASSERT_TRUE(plugin != NULL);
 
        ret = plugin->set("db/setting/auto_display_adjustment", true);
@@ -225,7 +225,7 @@ TEST(PluginManager, getPluginVconf)
        ret = plugin->getInt("db/setting/lcd_backlight_normal");
        EXPECT_EQ(ret, 11);
 
-       ret = broker.piMgr.unloadPlugins();
+       ret = broker.pMgr.unloadPlugins();
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        EXPECT_TRUE(broker.emptyPluginMap());
 }
@@ -235,22 +235,22 @@ TEST(PluginManager, getPluginBluetooth)
        int ret;
        TestPluginBroker broker;
 
-       broker.piMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
+       broker.pMgr.setPluginDir(MODES_PLUGIN_DEFAULT_DIR);
        try {
-               broker.piMgr.loadPlugins();
+               broker.pMgr.loadPlugins();
        }
        catch (ModesEx &e) {
-               broker.piMgr.setPluginDir("../plugin");
-               EXPECT_NO_THROW(broker.piMgr.loadPlugins());
+               broker.pMgr.setPluginDir("../plugin");
+               EXPECT_NO_THROW(broker.pMgr.loadPlugins());
 
-               ret = broker.piMgr.unloadPlugins();
+               ret = broker.pMgr.unloadPlugins();
                EXPECT_EQ(ret, MODES_ERROR_NONE);
                return;
        }
 
        EXPECT_FALSE(broker.emptyPluginMap());
 
-       Plugin *plugin = broker.piMgr.getPlugin("bluetooth");
+       Plugin *plugin = broker.pMgr.getPlugin("bluetooth");
        ASSERT_TRUE(plugin != NULL);
 
        ret = plugin->set("power", false);
@@ -265,7 +265,7 @@ TEST(PluginManager, getPluginBluetooth)
        ret = plugin->set("abcdefg", true);
        EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
 
-       ret = broker.piMgr.unloadPlugins();
+       ret = broker.pMgr.unloadPlugins();
        EXPECT_EQ(ret, MODES_ERROR_NONE);
        EXPECT_TRUE(broker.emptyPluginMap());
 }