Add mode ID
authorJinWang An <jinwang.an@samsung.com>
Fri, 12 Jun 2020 07:29:24 +0000 (16:29 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 15 Jun 2020 07:22:42 +0000 (16:22 +0900)
Change-Id: Iecf198e21ce8b17bb8c2d4958e58aa0cf629f6cd

42 files changed:
client/mdsc_add_remove.c
client/mdsc_apply.c
client/mdsc_can_apply.c
client/mdsc_get_modes.c
common/dbus.xml
common/dbus_def.h
common/definitions.h
common/gen.sh [changed mode: 0755->0644]
example/mode/tizen_asyncEx1_mode.xml
example/mode/tizen_asyncEx2_mode.xml
example/mode/tizen_asyncFailEx1_mode.xml
example/mode/tizen_asyncFailEx2_mode.xml
example/mode/tizen_asyncValidErr_mode.xml
example/mode/tizen_conflictErrBase_mode.xml
example/mode/tizen_conflictErrExclusive_mode.xml
example/mode/tizen_conflictErr_mode.xml
example/mode/tizen_essentialEx_mode.xml
example/mode/tizen_invalidValErr1_mode.xml
example/mode/tizen_invalidValErr2_mode.xml
example/mode/tizen_normalEx1_mode.xml
example/mode/tizen_normalEx2_mode.xml
include/modes.h
schema/tizen_mode.xsd
supervisor/ClientConnection.cpp
supervisor/EssentialHandler.cpp
supervisor/Mode.cpp
supervisor/Mode.h
supervisor/ModeCareTaker.cpp
supervisor/ModeInfo.h [new file with mode: 0644]
supervisor/ModeManager.cpp
supervisor/ModeManager.h
supervisor/ModeXMLParser.cpp
supervisor/ModeXMLParser.h
supervisor/ModesXMLTag.cpp
supervisor/ModesXMLTag.h
supervisor/RequestHandler.cpp
supervisor/XMLGenerator.cpp
tests/modes_test_async.cpp
tests/modes_test_client.cpp
tests/modes_test_conflict.cpp
tests/modes_test_modemgr.cpp
tests/modes_test_noti.cpp

index b2cdfb186483996ac7085dc5db77d8a01b573e14..3e927861ae8977c303046e733800c785d458419d 100644 (file)
@@ -28,6 +28,7 @@ struct mds_action_handle {
 };
 
 struct mds_mode_handle {
+       char *id;
        char *name;
        modes_type_mode_e type;
        bool hidden;
@@ -97,21 +98,22 @@ static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
        }
 
        GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
-       GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->name, mode->type, mode->hidden, action);
+       GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->id, mode->name, mode->type, mode->hidden, action);
        g_variant_builder_unref(action_builder);
 
        return mode_data;
 }
 
-API modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type)
+API modes_mode_h modes_create_mode(const char *id, const char *name, modes_type_mode_e type)
 {
        struct mds_mode_handle *mode;
 
-       RETV_IF(NULL == name, NULL);
+       RETV_IF(NULL == id, NULL);
 
        mode = malloc(sizeof(struct mds_mode_handle));
        RETV_IF(NULL == mode, NULL);
 
+       mode->id = strdup(id);
        mode->name = strdup(name);
        mode->type = type;
        mode->hidden = false;
@@ -175,13 +177,13 @@ API int modes_add_mode(modes_h handle, modes_mode_h mode)
        return MODES_ERROR_NONE;
 }
 
-API int modes_remove_mode(modes_h handle, const char *name)
+API int modes_remove_mode(modes_h handle, const char *id)
 {
        int ret;
        RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
 
-       ret = _mdsc_dbus_remove_mode_sync(handle->conn, name);
+       ret = _mdsc_dbus_remove_mode_sync(handle->conn, id);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_dbus_remove_mode_sync() Fail(%d)", ret);
                return ret;
@@ -194,6 +196,7 @@ API void modes_destroy_mode(modes_mode_h mode)
 {
        RET_IF(NULL == mode);
 
+       free(mode->id);
        free(mode->name);
 
        g_list_free_full(mode->action_list, _mdsc_free_action);
index 2dda68290b3ea5fefb2ea77037a82ba812164512..737843e3e096d97a9fae4c4992177d8802f5c3e4 100644 (file)
@@ -37,13 +37,13 @@ static int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
        return result;
 }
 
-API int modes_apply_mode(modes_h handle, const char *name)
+API int modes_apply_mode(modes_h handle, const char *id)
 {
        int ret;
        RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
 
-       ret = _mdsc_dbus_apply_mode_sync(handle->conn, name);
+       ret = _mdsc_dbus_apply_mode_sync(handle->conn, id);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
                return ret;
index 64525495d86f92eb4e25d02977b985192cc9407a..19bad9f081299501dc8889df2b8b5cb46fd42a99 100644 (file)
@@ -37,13 +37,13 @@ static int _mdsc_dbus_can_apply_sync(mdsDbus *mdsc_dbus, const char *mode)
        return result;
 }
 
-API int modes_can_apply(modes_h handle, const char *name)
+API int modes_can_apply(modes_h handle, const char *id)
 {
        int ret;
        RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
 
-       ret = _mdsc_dbus_can_apply_sync(handle->conn, name);
+       ret = _mdsc_dbus_can_apply_sync(handle->conn, id);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_dbus_precheck_mode_sync() Fail(%d)", ret);
                return ret;
index 17e9ec3fc7df32fe963a6100d0b308c5eaa20c45..bf1fd158af758ffde8b4feeeb5d9e7251ebde4f7 100644 (file)
@@ -21,6 +21,7 @@
 #include "common/dbus_def.h"
 
 struct mds_list_data_handle {
+       char *id;
        char *name;
        modes_type_mode_e type;
        int state;
@@ -28,6 +29,7 @@ struct mds_list_data_handle {
 
 static GList* _get_mode_list(GVariant *in_data)
 {
+       gchar *mode_id;
        gchar *mode_name;
        gint32 state;
        gint32 type;
@@ -35,13 +37,14 @@ static GList* _get_mode_list(GVariant *in_data)
        GList *mode_list = NULL;;
 
        g_variant_get(in_data, MODES_DBUS_GET_MODES_SIG, &iter);
-       while (g_variant_iter_loop(iter, MODES_DBUS_GET_MODES_MODE_SIG, &mode_name, &type, &state)) {
-               DBG("mode(%s) : state(%d)", mode_name, state);
+       while (g_variant_iter_loop(iter, MODES_DBUS_GET_MODES_MODE_SIG, &mode_id, &mode_name, &type, &state)) {
+               DBG("mode(%s) : state(%d)", mode_id, state);
                mode_list_data_h mode = malloc(sizeof(struct mds_list_data_handle));
                if (NULL == mode) {
                        ERR("malloc() Fail");
                        return NULL;
                }
+               mode->id = strdup(mode_id);
                mode->name = strdup(mode_name);
                mode->state = state;
                mode->type = type;
@@ -92,6 +95,7 @@ API int modes_get_modes(modes_h handle, GList **list)
 static void _free_mode(gpointer data, gpointer user_data)
 {
        mode_list_data_h mode = data;
+       free(mode->id);
        free(mode->name);
        free(mode);
 }
@@ -102,6 +106,12 @@ API void modes_free_modes(GList *list)
        g_list_free(list);
 }
 
+API const char* modes_get_mode_id(mode_list_data_h data)
+{
+       RETV_IF(NULL == data, NULL);
+       return data->id;
+}
+
 API const char* modes_get_mode_name(mode_list_data_h data)
 {
        RETV_IF(NULL == data, NULL);
index 15e8abff99e2e65987ccb86170d8c670e4f9116d..69e16927ed7b98789d2332554aeb9286bf42d2e7 100644 (file)
@@ -13,7 +13,7 @@
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="addMode">
-                       <arg type="(sibv)" name="modeData" direction="in"/>
+                       <arg type="(ssibv)" name="modeData" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="removeMode">
@@ -21,7 +21,7 @@
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="getModes">
-                       <arg type="a(sii)" name="modeList" direction="out"/>
+                       <arg type="a(ssii)" name="modeList" direction="out"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <signal name="changedMode">
index 21486efecb72b623a8bb1d41af74662691d1f578..78486ccea72f18d95dd8d03e5f245051f4f7b00b 100644 (file)
 
 #define MODES_DBUS_OBJPATH "/org/tizen/modes/dbus"
 
-#define MODES_DBUS_MODE_SIG "(sibv)"
+#define MODES_DBUS_MODE_SIG "(ssibv)"
 #define MODES_DBUS_ACTION_SIG "(sss)"
 #define MODES_DBUS_ACTION_LIST_SIG "a" MODES_DBUS_ACTION_SIG
 
-#define MODES_DBUS_GET_MODES_MODE_SIG "(sii)"
+#define MODES_DBUS_GET_MODES_MODE_SIG "(ssii)"
 #define MODES_DBUS_GET_MODES_SIG "a" MODES_DBUS_GET_MODES_MODE_SIG
 
 #define MODES_DBUS_SAFE_STR(x) x ? x : ""
index 994b4c5193aaf80ea9e13e605c459038f79e3401..38840f65d2f059dcfe89a3b948fbf9dac3335ff8 100644 (file)
@@ -62,3 +62,4 @@
 #warning "MODES_UNDO_INFO_DEFAULT_DIR is redefined"
 #endif
 #define MODES_UNDO_FILE_SUFFIX "_undo.xml"
+#define MODES_ID_PREFIX "http://tizen.org/mode/"
old mode 100755 (executable)
new mode 100644 (file)
index 06dac5a1c01ae6dc876b4239278183057ceec555..6a97f2efe846af9c001d21d0e05886c524319f54 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="asyncEx1" type="normal">
+  <mode ID="http://tizen.org/mode/example.asyncEx1" name="asyncEx1" type="normal">
     <action ID="test_001" rule="test.sleep" type="async">5</action>
     <action ID="test_002" rule="test.sleep" type="async">5</action>
     <action ID="test_003" rule="test.sleepErrorReturn" type="async">5</action>
index 8310a2a2301a324b17b5161bb9cf755ceb9d1d7a..1429fc080b7cc096973a9c7a15cfc71dce3e1f6a 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="asyncEx2" type="oneshot">
+  <mode ID="http://tizen.org/mode/example.asyncEx2" name="asyncEx2" type="oneshot">
     <action ID="test_001" rule="test.sleep" type="async">5</action>
     <action ID="test_002" rule="test.sleep" type="async">5</action>
     <action ID="test_003" rule="test.sleepErrorReturn" type="async">5</action>
index b764ffa51a46b5c4df24f0bd7241c6f7a05c3224..6b6207a029a290e61cb917e7eb9a5b2c31b3be1d 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="asyncFail1" type="normal">
+  <mode ID="http://tizen.org/mode/example.asyncFail1" name="asyncFail1" type="normal">
     <action rule="test.sleep" type="async">5</action>
     <action rule="test.sleep" type="async">5</action>
     <action rule="test.sleep" type="async">5</action>
index 74c42637e8832ab8d45502b0378ca6d77148f7f9..340b1a67b7c816aedd9665d3a2234da1d3341c9b 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="asyncFail2" type="oneshot">
+  <mode ID="http://tizen.org/mode/example.asyncFail2" name="asyncFail2" type="oneshot">
     <action rule="test.sleep" type="async">5</action>
     <action rule="test.sleep" type="async">5</action>
     <action rule="test.sleep" type="async">5</action>
index 9ef4ab31374f544e0a29bc4650a255186071bb6d..71347fd304e73cee4a5c792ef229fba3b9e7a8be 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="async_valied" type="normal" hidden="true">
+  <mode ID="http://tizen.org/mode/example.async_valied" name="async_valied" type="normal" hidden="true">
     <action rule="test.sleepErrorReturn" restrict="lock" stopOnErr="true" type="async">5</action>
   </mode>
 </tizenModes>
index 5da442950b639f045c6268d87d8698c57f8d74c3..31893bf310a8442dbeeac928d7592176b9af64e7 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="conflict1" type="normal">
+  <mode ID="http://tizen.org/mode/example.conflict1" name="conflict1" type="normal">
     <action ID="test" rule="test.printInt" restrict="lock">1</action>
   </mode>
 </tizenModes>
index b4d7858d55c47f10a2b393d085134515209049ae..47d6f9f74be0b117ba976ade529200decbb32a19 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="conflict3" type="normal">
+  <mode ID="http://tizen.org/mode/example.conflict3" name="conflict3" type="normal">
     <action ID="test" rule="test.printBool" restrict="lock">true</action>
   </mode>
 </tizenModes>
index 0c21e0a941317af7734b24364d8af4bcb5f4998a..16fb2834a8a462e22618ea828ba77ff538171a37 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="conflict1" type="normal">
+  <mode ID="http://tizen.org/mode/example.conflict1" name="conflict1" type="normal">
     <action ID="test" rule="test.printInt" restrict="lock" stopOnErr="true">2</action>
   </mode>
 </tizenModes>
index 1a6c3afef5e5fef82519c51ce57793396f321d1c..f2e460972525f4296b08d6386090d76faf321599 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="essential_ex" type="normal">
+  <mode ID="http://tizen.org/mode/example.essential_ex" name="essential_ex" type="normal">
     <action rule="test.printBool">on</action>
     <action rule="test.connect">Modes-JBL</action>
     <action rule="test.changeTime" restrict="essential">3</action>
index 134df11aff00ea49e01601d83ceba698e274d7e9..bd656057785ab752a46c30fdc4f2d8362f72cf8d 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="invalid1" type="normal">
+  <mode ID="http://tizen.org/mode/example.invalid1" name="invalid1" type="normal">
     <action rule="test.printBool" restrict="lock">123</action>
   </mode>
 </tizenModes>
index 0078fffe83fa00d14dea682e9b553624518eb01f..c0d46c1d74cfb563a70876c72393d70f6fe13351 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="invalid2" type="normal">
+  <mode ID="http://tizen.org/mode/example.invalid2" name="invalid2" type="normal">
     <action rule="test.printInt" restrict="lock">PRINT_TREE</action>
   </mode>
 </tizenModes>
index fb1f7b1c06d21715b8a32bebf5c8f9dac13d740a..e1227385260d338f166c03b479384c7ca389d77a 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="ex1" type="normal">
+  <mode ID="http://tizen.org/mode/example.ex1" name="ex1" type="normal">
     <action ID="wifiOn" rule="test.printBool" priority="-100">on</action>
     <action rule="test.launch" before="GoPbsKids">com.vpn.usa123</action>
     <action ID="GoPbsKids" rule="web.url" after="wifiOn">https://pbskids.org/</action>
index 227ec5a8bd7c6e4225e631d60bc69239a275806c..6d30f7147d252f460351fa4f8b11ee9bb377b01a 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <tizenModes xmlns="http://www.tizen.org" version="6.0">
-  <mode name="ex2" type="normal" hidden="true">
+  <mode ID="http://tizen.org/mode/example.ex2" name="ex2" type="normal" hidden="true">
     <action ID="1" rule="test.printInt" stopOnErr="true" restrict="lock">PRINT_FOUR</action>
     <action ID="wifiOff" rule="test.printBool" restrict="lock">off</action>
     <action rule="test.alwaySameValue">test</action>
index e2675ef3e5c26f63370b6dcf46fb1d5eb4364376..41d763167b5871730d76b5577cffde984a416a02 100644 (file)
@@ -57,13 +57,13 @@ modes_h modes_connect();
 void modes_disconnect(modes_h handle);
 
 /**
- * @brief Apply mode with the given name.
+ * @brief Apply mode with the given mode id.
  * @details Calls this function to change Modes.
  * @since_tizen 6.0
  * @privlevel public
- * @privilege according to privileges of the \p name Mode
+ * @privilege according to privileges of the mode id
  * @param[in] Handle of modes server
- * @param[in] Mode name to change
+ * @param[in] Mode ID to change
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #MODES_ERROR_NONE Successful
@@ -72,15 +72,15 @@ void modes_disconnect(modes_h handle);
  * @retval #MODES_ERROR_PERMISSION_DENIED Permission denied
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_apply_mode(modes_h handle, const char *name);
+int modes_apply_mode(modes_h handle, const char *id);
 
 /**
- * @brief Precheck to apply mode with the given name.
+ * @brief Precheck to apply mode with the given mode id.
  * @details Calls this function to change Modes.
  * @since_tizen 6.0
  * @privlevel public
  * @param[in] Handle of modes server
- * @param[in] Mode name to change
+ * @param[in] Mode ID to change
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #MODES_ERROR_NONE Successful
@@ -91,16 +91,16 @@ int modes_apply_mode(modes_h handle, const char *name);
  * @retval #MODES_ERROR_CONFLICT Conflict
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_can_apply(modes_h handle, const char *name);
+int modes_can_apply(modes_h handle, const char *id);
 
 /**
- * @brief undo mode with the given name.
+ * @brief undo mode with the given mode id.
  * @details If the mode is not applied bebore, it will be ingnored.
  * @since_tizen 6.0
  * @privlevel public
- * @privilege according to privileges of the \p name Mode
+ * @privilege according to privileges of the mode id
  * @param[in] Handle of modes server
- * @param[in] Mode name to undo
+ * @param[in] Mode ID to undo
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #MODES_ERROR_NONE Successful
@@ -109,7 +109,7 @@ int modes_can_apply(modes_h handle, const char *name);
  * @retval #MODES_ERROR_PERMISSION_DENIED Permission denied
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_undo_mode(modes_h handle, const char *name);
+int modes_undo_mode(modes_h handle, const char *id);
 
 
 /**
@@ -118,12 +118,13 @@ int modes_undo_mode(modes_h handle, const char *name);
  * @since_tizen 6.0
  * @privlevel public
  * @param[in] Mode name
+ * @param[in] Mode ID
  * @param[in] Mode type
  * @return @c Mode handle pointer on success,
  *         otherwise NULL value
  * @retval NULL Failed to create the mode handler
  */
-modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type);
+modes_mode_h modes_create_mode(const char *id, const char *name, modes_type_mode_e type);
 
 /**
  * @brief Set Mode hidden.
@@ -209,7 +210,7 @@ void modes_destroy_mode(modes_mode_h mode);
  * @retval #MODES_ERROR_CONFLICT Try to remove applied mode.
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_remove_mode(modes_h handle, const char *name);
+int modes_remove_mode(modes_h handle, const char *id);
 
 /**
  * @brief Adds callback for recognizing the changed of mode.
@@ -263,6 +264,16 @@ int modes_get_modes(modes_h handle, GList **list);
  */
 void modes_free_modes(GList *list);
 
+/**
+ * @brief Get ID of mode from GList data
+ * @details Calls this function to get mode list
+ * @since_tizen 6.0
+ * @privlevel public
+ * @param[in] GList for mode list
+ * @return mode ID
+ */
+const char* modes_get_mode_id(mode_list_data_h data);
+
 /**
  * @brief Get name of mode from GList data
  * @details Calls this function to get mode list
index 3692d821479188162c4a6544ad482caca0acee7f..4ffb4297baf1cd0a1393f639cd3791ba077eadbd 100644 (file)
@@ -10,6 +10,7 @@
               <xs:element maxOccurs="unbounded" name="action" type="o:actionT" />
               <xs:element minOccurs="0" maxOccurs="unbounded" name="undo" type="o:actionT" />
             </xs:sequence>
+            <xs:attribute name="ID" type="xs:string" use="required" />
             <xs:attribute name="name" type="xs:string" use="required" />
             <xs:attribute name="type" type="o:modeTypeT" use="required" />
             <xs:attribute name="hidden" type="xs:boolean" use="optional" />
index f253553d244195f0940794b46cb6d9b65f5043d3..9f5d5b5b85f6bc63e4fa4743fb4b26743a6dcd9e 100644 (file)
@@ -57,9 +57,9 @@ void ClientConnection::addRequestHandler(const std::string &method, GCallback cb
        g_signal_connect(dbusHandle, method.c_str(), cb, NULL);
 }
 
-void ClientConnection::update(const std::string &name, ModeState state)
+void ClientConnection::update(const std::string &id, ModeState state)
 {
-       mds_dbus_emit_changed_mode(dbusHandle, name.c_str(), state);
+       mds_dbus_emit_changed_mode(dbusHandle, id.c_str(), state);
 }
 
 void ClientConnection::onBusAcquired(GDBusConnection *conn, const gchar *name, gpointer userData)
index 5170df59388d3479c6e53353efb89eda6e83d568..ab06d402d6b4ed55823b25d8d0f99e8cf598e635 100644 (file)
@@ -28,11 +28,11 @@ void EssentialHandler::setModeManager(ModeManager *mgr)
        modeMgr = mgr;
 }
 
-void EssentialHandler::undoHandler(const std::string &modeName)
+void EssentialHandler::undoHandler(const std::string &modeID)
 {
-       DBG("undo idler(%s) is added", modeName.c_str());
+       DBG("undo idler(%s) is added", modeID.c_str());
 
-       g_idle_add(undoIdler, new std::string(modeName));
+       g_idle_add(undoIdler, new std::string(modeID));
 }
 
 gboolean EssentialHandler::undoIdler(gpointer data)
@@ -40,12 +40,12 @@ gboolean EssentialHandler::undoIdler(gpointer data)
        RETV_IF(NULL == data, G_SOURCE_REMOVE);
        RETV_IF(nullptr == modeMgr, G_SOURCE_REMOVE);
 
-       std::string &modeName = *(std::string*)data;
+       std::string &modeID = *(std::string*)data;
 
-       int ret = modeMgr->undoMode(modeName);
+       int ret = modeMgr->undoMode(modeID);
        if (MODES_ERROR_NONE != ret)
-               ERR("undoMode(%s) Fail(%d)", modeName.c_str(), ret);
+               ERR("undoMode(%s) Fail(%d)", modeID.c_str(), ret);
 
-       delete &modeName;
+       delete &modeID;
        return G_SOURCE_REMOVE;
 }
index 039788a0d107448d225ddba49c1df39a19ccd245..47228a94ccf16af986340510f0070c472736a40f 100644 (file)
@@ -16,6 +16,7 @@
 #include "Mode.h"
 
 #include <thread>
+#include <algorithm>
 #include "modes_constants.h"
 #include "ModesEx.h"
 
@@ -50,6 +51,16 @@ const std::string Mode::getName() const
        return name;
 }
 
+void Mode::setID(const std::string &data)
+{
+       id = data;
+}
+
+const std::string Mode::getID() const
+{
+       return id;
+}
+
 void Mode::setModeType(Mode::ModeType val)
 {
        type = val;
@@ -139,3 +150,10 @@ std::list<std::shared_ptr<Action>> Mode::getUndoList() const
 {
        return undoList;
 }
+
+std::string Mode::getFileNameID() const
+{
+       std::string fileID = id.substr(sizeof(MODES_ID_PREFIX)-1);
+       std::replace(fileID.begin(), fileID.end(), '/', '_');
+       return fileID;
+}
index c22a838f031620edae1a1e9dfceca67965f51c04..7249159e8f5ac685c256d84fa9be8b3146a5406b 100644 (file)
@@ -35,6 +35,10 @@ public:
        void setName(const std::string &data);
        const std::string getName() const;
 
+       void setID(const std::string &data);
+       const std::string getID() const;
+       std::string getFileNameID() const;
+
        void setModeType(Mode::ModeType val);
        ModeType getModeType() const;
 
@@ -55,6 +59,7 @@ public:
        void undo();
 private:
        std::string name;
+       std::string id;
        ModeType type;
        bool hidden;
        bool essential;
index 382d660e69111ef88364d43d216360e47edd21d5..3bce37a49fe7b3abcd1bf7b2705b4dc0aee9e1ff 100644 (file)
@@ -32,15 +32,15 @@ std::string ModeCareTaker::getUndoInfoDir()
        return undoDir;
 }
 
-bool ModeCareTaker::hasUndoInfo(const std::string &modeName)
+bool ModeCareTaker::hasUndoInfo(const std::string &filenameID)
 {
-       std::string file = undoDir + "/tizen_" + modeName + MODES_UNDO_FILE_SUFFIX;
+       std::string file = undoDir + "/tizen_" + filenameID + MODES_UNDO_FILE_SUFFIX;
        return (access(file.c_str(), F_OK) == 0);
 }
 
 void ModeCareTaker::restoreMode(Mode &mode)
 {
-       std::string file = undoDir + "/tizen_" + mode.getName() + MODES_UNDO_FILE_SUFFIX;
+       std::string file = undoDir + "/tizen_" + mode.getFileNameID() + MODES_UNDO_FILE_SUFFIX;
        try {
                UndoInfoParser undoInfoParser(file);
                undoInfoParser.putUndoInfo(mode);
@@ -58,37 +58,36 @@ void ModeCareTaker::pushMode(const Mode &mode)
        realPushMode(mode);
 
        XMLGenerator gen;
-       gen.makeUndoInfoXML(undoDir + "/tizen_" + mode.getName() + MODES_UNDO_FILE_SUFFIX, mode);
+       gen.makeUndoInfoXML(undoDir + "/tizen_" + mode.getFileNameID() + MODES_UNDO_FILE_SUFFIX, mode);
 }
 
-int ModeCareTaker::popMode(const std::string &name, Mode &mode)
+int ModeCareTaker::popMode(const std::string &id, Mode &mode)
 {
-       auto found = savedModes.find(name);
+       auto found = savedModes.find(id);
        if (savedModes.end() == found) {
-               ERR("No Mode(%s)", name.c_str());
+               ERR("No Mode(%s)", id.c_str());
                return MODES_ERROR_NO_DATA;
        }
 
-       std::string filePath = undoDir + "/tizen_" + name + MODES_UNDO_FILE_SUFFIX;
+       mode = found->second;
+       std::string filePath = undoDir + "/tizen_" + mode.getFileNameID() + MODES_UNDO_FILE_SUFFIX;
        if (0 != remove(filePath.c_str()))
                ERR("remove(%s) Fail(%d)", filePath.c_str(), errno);
 
        for (auto it = essentialMap.begin(); it != essentialMap.end();) {
-               if (it->second == name)
+               if (it->second == id)
                        it = essentialMap.erase(it);
                else
                        ++it;
        }
 
-       mode = found->second;
        savedModes.erase(found);
-
        return MODES_ERROR_NONE;
 }
 
 bool ModeCareTaker::isConflict(const Mode &mode)
 {
-       if (isSavedMode(mode.getName()))
+       if (isSavedMode(mode.getID()))
                return true;
 
        if (checkConflictAction(mode))
@@ -97,11 +96,11 @@ bool ModeCareTaker::isConflict(const Mode &mode)
        return false;
 }
 
-bool ModeCareTaker::isSavedMode(const std::string &name)
+bool ModeCareTaker::isSavedMode(const std::string &id)
 {
-       auto found = savedModes.find(name);
+       auto found = savedModes.find(id);
        if (savedModes.end() != found) {
-               INFO("Mode(%s) is Saved Mode", name.c_str());
+               INFO("Mode(%s) is Saved Mode", id.c_str());
                return true;
        }
 
@@ -138,7 +137,7 @@ void ModeCareTaker::update(int *key)
 
 void ModeCareTaker::realPushMode(const Mode &mode)
 {
-       savedModes.insert(std::pair<std::string, Mode>(mode.getName(), mode));
+       savedModes.insert(std::pair<std::string, Mode>(mode.getID(), mode));
 
        if (mode.hasEssential())
                handleEssentialAction(mode);
@@ -160,13 +159,13 @@ bool ModeCareTaker::checkConflictAction(const Mode &mode)
 
 void ModeCareTaker::handleEssentialAction(const Mode &mode)
 {
-       DBG("Mode has Essential Action(%s)", mode.getName().c_str());
+       DBG("Mode has Essential Action(%s)", mode.getID().c_str());
 
        std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
        for (auto it = actionList.begin(); it != actionList.end(); it++) {
                if ((*it)->getRestrict() == Action::ESSENTIAL) {
                        DBG("Essential Action(%s)", (*it)->getRuleName().c_str());
-                       essentialMap.insert(std::make_pair((*it).get(), mode.getName()));
+                       essentialMap.insert(std::make_pair((*it).get(), mode.getID()));
                        if (true == (*it)->checkChanged()) {
                                EssentialHandler::undoHandler(mode.getName());
                                return;
diff --git a/supervisor/ModeInfo.h b/supervisor/ModeInfo.h
new file mode 100644 (file)
index 0000000..3303faf
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019-2020 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.
+ */
+#pragma once
+
+#include <string>
+#include "mdss.h"
+
+MODES_NAMESPACE_BEGIN
+struct ModeInfo {
+       std::string id;
+       std::string name;
+       std::string path;
+       bool hidden;
+       int type;
+       int state;
+};
+MODES_NAMESPACE_END
index 0ad3cc612b18fa9bef5f382fab0e20660dae9de0..c56d19dffec695ac6eb9931ffee8a9d5de6e116e 100644 (file)
@@ -22,6 +22,7 @@
 #include <exception>
 #include "mdss.h"
 #include "ModesEx.h"
+#include "ModeInfo.h"
 #include "ModeObserver.h"
 #include "XMLGenerator.h"
 #include "ModeXMLParser.h"
@@ -49,32 +50,32 @@ void ModeManager::init()
 void ModeManager::addModeAttributes(ModeXMLParser &parser, const string &path)
 {
        Mode mode = parser.getMode();
-       auto infos = std::make_tuple(path, mode.getModeType(), mode.isHidden());
-       modeMap.insert(std::make_pair(mode.getName(), infos));
+       ModeInfo info = { mode.getID(), mode.getName(), path, mode.isHidden(), mode.getModeType(), 0 };
+       modeMap.insert(std::make_pair(mode.getID(), info));
 
-       if (careTaker.hasUndoInfo(mode.getName()))
+       if (careTaker.hasUndoInfo(mode.getFileNameID()))
                careTaker.restoreMode(mode);
 
-       DBG("[%zu]Name(%s), Path(%s), Type(%d), hidden(%s)", modeMap.size(), mode.getName().c_str(),
-               path.c_str(), mode.getModeType(), mode.isHidden() ? "true": "false");
+       DBG("[%zu]ID(%s), Name(%s), Path(%s), Type(%d), hidden(%s)", modeMap.size(), mode.getID().c_str(),
+               mode.getName().c_str(), path.c_str(), mode.getModeType(), mode.isHidden() ? "true": "false");
 }
 
-int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool isTest)
+int ModeManager::applyMode(const string &modeID, ClientPrivilege &priv, bool isTest)
 {
-       auto found = modeMap.find(modeName);
+       auto found = modeMap.find(modeID);
        if (modeMap.end() == found) {
-               ERR("No Mode(%s)", modeName.c_str());
+               ERR("No Mode(%s)", modeID.c_str());
                return MODES_ERROR_NO_DATA;
        }
 
-       string path = std::get<0>(found->second);
+       string path = found->second.path;
        DBG("applyMode(%s)", path.c_str());
 
        try {
                ModeXMLParser parser(path, ruleMgr);
                Mode mode = parser.getMode();
 
-               DBG("applyMode(%s) Run", mode.getName().c_str());
+               DBG("applyMode(%s) Run", mode.getID().c_str());
 
                int ret = priv.check(mode);
                if (MODES_ERROR_NONE != ret) {
@@ -83,7 +84,7 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i
                }
 
                if (careTaker.isConflict(mode)) {
-                       ERR("mode(%s) is conflict", mode.getName().c_str());
+                       ERR("mode(%s) is conflict", mode.getID().c_str());
                        return MODES_ERROR_CONFLICT;
                }
 
@@ -93,14 +94,14 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i
                if (Mode::MODE_ONESHOT == mode.getModeType()) {
                        ret = mode.applyOneShot();
                        if (MODES_ERROR_NONE != ret) {
-                               ERR("mode(%s) apply() Fail", mode.getName().c_str());
+                               ERR("mode(%s) apply() Fail", mode.getID().c_str());
                                mode.undo();
                                return ret;
                        }
                } else {
                        ret = mode.apply();
                        if (MODES_ERROR_NONE != ret) {
-                               ERR("mode(%s) apply() Fail", mode.getName().c_str());
+                               ERR("mode(%s) apply() Fail", mode.getID().c_str());
                                mode.undo();
                                return ret;
                        }
@@ -118,19 +119,19 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i
                        return MODES_ERROR_SYSTEM;
                }
        }
-       notifyObservers(modeName, ModeObserver::ON);
+       notifyObservers(modeID, ModeObserver::ON);
        return MODES_ERROR_NONE;
 }
 
 int ModeManager::addMode(const Mode &mode)
 {
-       string path = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getName() + "_mode.xml";
+       string path = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getFileNameID() + "_mode.xml";
        XMLGenerator xmlWriter;
 
-       auto element = std::make_pair(mode.getName(), std::make_tuple(path, mode.getModeType(), false));
-       auto result = modeMap.insert(element);
+       ModeInfo info = { mode.getID(), mode.getName(), path, false, mode.getModeType(), 0};
+       auto result = modeMap.insert(std::make_pair(mode.getID(), info));
        if (false == result.second) {
-               ERR("Invalid mode(%s), already exists", mode.getName().c_str());
+               ERR("Invalid mode(%s), already exists", mode.getID().c_str());
                return MODES_ERROR_INVALID_PARAMETER;
        }
 
@@ -149,28 +150,28 @@ int ModeManager::addMode(const Mode &mode)
                }
        }
 
-       DBG("[%zu]addMode : Name(%s), Path(%s), Type(%d)", modeMap.size(), mode.getName().c_str(),
-               path.c_str(), mode.getModeType());
+       DBG("[%zu]addMode : ID(%s), Name(%s), Path(%s), Type(%d)", modeMap.size(), mode.getID().c_str(),
+               mode.getName().c_str(), path.c_str(), mode.getModeType());
 
        return MODES_ERROR_NONE;
 }
 
-int ModeManager::removeMode(const string &modeName)
+int ModeManager::removeMode(const string &modeID)
 {
-       if (true == careTaker.isSavedMode(modeName)) {
-               ERR("Mode(%s) is applied.", modeName.c_str());
+       if (true == careTaker.isSavedMode(modeID)) {
+               ERR("Mode(%s) is applied.", modeID.c_str());
                return MODES_ERROR_CONFLICT;
        }
 
-       auto result = modeMap.find(modeName);
+       auto result = modeMap.find(modeID);
        if (result == modeMap.end()) {
-               ERR("Invalid mode(%s), not found", modeName.c_str());
+               ERR("Invalid mode(%s), not found", modeID.c_str());
                return MODES_ERROR_INVALID_PARAMETER;
        }
 
-       string path = std::get<0>(result->second);
+       string path = result->second.path;
        if (string::npos == path.find(MODES_CUSTOM_MODE_DEFAULT_DIR)) {
-               ERR("Invalid mode(%s), custom mode only can be removed.", modeName.c_str());
+               ERR("Invalid mode(%s), custom mode only can be removed.", modeID.c_str());
                return MODES_ERROR_INVALID_PARAMETER;
        }
 
@@ -179,15 +180,15 @@ int ModeManager::removeMode(const string &modeName)
        if (0 != remove(path.c_str()))
                ERR("remove(%s) Fail(%d)", path.c_str(), errno);
 
-       DBG("[%zu]removeMode : Name(%s), Path(%s)", modeMap.size(), modeName.c_str(), path.c_str());
+       DBG("[%zu]removeMode : ID(%s), Path(%s)", modeMap.size(), modeID.c_str(), path.c_str());
 
        return MODES_ERROR_NONE;
 }
 
-int ModeManager::undoMode(const string &modeName, ClientPrivilege &priv)
+int ModeManager::undoMode(const string &modeID, ClientPrivilege &priv)
 {
        Mode mode;
-       int ret = careTaker.popMode(modeName, mode);
+       int ret = careTaker.popMode(modeID, mode);
        if (MODES_ERROR_NONE != ret) {
                ERR("popMode() Fail(%d)", ret);
                return ret;
@@ -200,37 +201,35 @@ int ModeManager::undoMode(const string &modeName, ClientPrivilege &priv)
        }
 
        mode.undo();
-       notifyObservers(modeName, ModeObserver::OFF);
+       notifyObservers(modeID, ModeObserver::OFF);
 
        return MODES_ERROR_NONE;
 }
 
-int ModeManager::undoMode(const string &modeName)
+int ModeManager::undoMode(const string &modeID)
 {
        Mode mode;
-       int ret = careTaker.popMode(modeName, mode);
+       int ret = careTaker.popMode(modeID, mode);
        if (MODES_ERROR_NONE != ret) {
                ERR("popMode() Fail(%d)", ret);
                return ret;
        }
 
        mode.undo();
-       notifyObservers(modeName, ModeObserver::OFF);
+       notifyObservers(modeID, ModeObserver::OFF);
 
        return MODES_ERROR_NONE;
 }
 
-std::list<std::tuple<string, int, int>> ModeManager::getModes()
+std::list<ModeInfo> ModeManager::getModes()
 {
-       std::list<std::tuple<string, int, int>> modeList;
+       std::list<ModeInfo> modeList;
 
        for (auto it = modeMap.begin(); it != modeMap.end(); ++it) {
-               bool hidden = std::get<2>(it->second);
-               if (true == hidden)
+               if (true == it->second.hidden)
                        continue;
-               int type = std::get<1>(it->second);
-               int state = careTaker.isSavedMode(it->first);
-               modeList.push_back(std::tuple<string, int, int>(it->first, type, state));
+               it->second.state = careTaker.isSavedMode(it->first);
+               modeList.push_back(it->second);
        }
 
        return modeList;
@@ -246,10 +245,10 @@ void ModeManager::detachObserver(ModeObserver *obs)
        observers.remove(obs);
 }
 
-void ModeManager::notifyObservers(const string &modeName, ModeObserver::ModeState state)
+void ModeManager::notifyObservers(const string &modeID, ModeObserver::ModeState state)
 {
        for (auto it = observers.begin(); it != observers.end(); ++it)
-               (*it)->update(modeName, state);
+               (*it)->update(modeID, state);
 }
 
 bool ModeManager::makeModeMap(const string &dirPath)
@@ -298,4 +297,3 @@ void ModeManager::addModeDirectory(const string &dirPath)
 
        modeDirList.insert(dirPath);
 }
-
index 36f7a8f9b209711c742142586f62043284c8c564..e883b72475ebcad584abd72befb9e0f1126d64e7 100644 (file)
@@ -19,6 +19,7 @@
 #include <utility>
 #include <set>
 #include "mdss.h"
+#include "ModeInfo.h"
 #include "RuleManager.h"
 #include "ModeObserver.h"
 #include "ModeCareTaker.h"
@@ -38,7 +39,7 @@ public:
        int removeMode(const std::string &modeName);
        int undoMode(const std::string &modeName);
        int undoMode(const std::string &modeName, ClientPrivilege &priv);
-       std::list<std::tuple<std::string, int, int>> getModes();
+       std::list<ModeInfo> getModes();
        void attachObserver(ModeObserver *obs);
        void detachObserver(ModeObserver *obs);
 private:
@@ -46,7 +47,7 @@ private:
        bool makeModeMap(const std::string &dirPath);
        void addModeAttributes(ModeXMLParser &parser, const std::string &path);
 
-       std::map<std::string, std::tuple<std::string, int, bool>> modeMap;
+       std::map<std::string, ModeInfo> modeMap;
        std::set<std::string> modeDirList;
        std::string modeSyntaxFile;
        RuleManager &ruleMgr;
index ebe8a38f5b9bbe5fbe0c9d75f44a2bfd5d4632dd..08e45ddf64bc1c1cd6601b8f76259a8b6caca226 100644 (file)
@@ -72,11 +72,17 @@ void ModeXMLParser::iterateElement(xmlNodePtr node)
 
 void ModeXMLParser::parseModeAttr(xmlNodePtr node)
 {
+       mode.setID(extractModeID(node));
        mode.setName(extractModeName(node));
        mode.setModeType(extractModeType(node));
        mode.setHidden(extractHidden(node));
 }
 
+std::string ModeXMLParser::extractModeID(xmlNodePtr node)
+{
+       return extractValueOfTag(node, ModesXMLTag::ID);
+}
+
 std::string ModeXMLParser::extractModeName(xmlNodePtr node)
 {
        return extractValueOfTag(node, ModesXMLTag::NAME);
index f7bbd5fbc607b580cdf00b3bceb40416530f38ea..3e4591f680a911b9ee7ee8e995d779745976b553 100644 (file)
@@ -34,6 +34,7 @@ public:
 private:
        void parseModeAttr(xmlNodePtr node);
        std::string extractModeName(xmlNodePtr node);
+       std::string extractModeID(xmlNodePtr node);
        Mode::ModeType extractModeType(xmlNodePtr node);
        bool extractHidden(xmlNodePtr node);
        void parseActionAttr(xmlNodePtr node, Action *action);
index c535007c97499e3ff470a0d778cbb05e886e2094..bf998c54789ee5f64912e73d3b1f679d88d7a814 100644 (file)
@@ -29,6 +29,7 @@ const xmlChar* const ModesXMLTag::CUR_VERSION = (xmlChar*)"6.0";
 const xmlChar* const ModesXMLTag::TYPE = (xmlChar*)"type";
 const xmlChar* const ModesXMLTag::TRUE = (xmlChar*)"true";
 const xmlChar* const ModesXMLTag::FALSE = (xmlChar*)"false";
+const xmlChar* const ModesXMLTag::ID = (xmlChar*)"ID";
 //Mode
 const xmlChar* const ModesXMLTag::MODE = (xmlChar*)"mode";
 const xmlChar* const ModesXMLTag::NAME = (xmlChar*)"name";
@@ -41,7 +42,6 @@ const xmlChar* const ModesXMLTag::STOP_ON_ERR = (xmlChar*)"stopOnErr";
 const xmlChar* const ModesXMLTag::RESTRICT = (xmlChar*)"restrict";
 const char* const ModesXMLTag::RESTRICT_LOCK = "lock";
 const char* const ModesXMLTag::RESTRICT_ESSENTIAL = "essential";
-const xmlChar* const ModesXMLTag::ID = (xmlChar*)"ID";
 //UndoInfo
 const xmlChar* const ModesXMLTag::UNDO_INFO = (xmlChar*)"UndoInfo";
 const xmlChar* const ModesXMLTag::INFO = (xmlChar*)"info";
index 25e8d2e39046f580982df35c693dd2f63aef7d3b..3f937c87b49b1fc5d176c21468276a553220c811 100644 (file)
@@ -32,6 +32,7 @@ struct ModesXMLTag {
        static const xmlChar* const TYPE;
        static const xmlChar* const TRUE;
        static const xmlChar* const FALSE;
+       static const xmlChar* const ID;
 
        //Mode
        static const xmlChar* const MODE;
@@ -45,7 +46,6 @@ struct ModesXMLTag {
        static const xmlChar* const RESTRICT;
        static const char* const RESTRICT_LOCK;
        static const char* const RESTRICT_ESSENTIAL;
-       static const xmlChar* const ID;
        //UndoInfo
        static const xmlChar* const UNDO_INFO;
        static const xmlChar* const INFO;
index f58e8f6c0b846fe3668288e342ade4228b5a47d7..77ed2232d93a83ffed4af06120cb4ffea4291e4c 100644 (file)
@@ -38,14 +38,14 @@ void RequestHandler::setRuleManager(RuleManager *mgr)
 }
 
 gboolean RequestHandler::canApplyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
-       const gchar *modeName, gpointer userData)
+       const gchar *modeID, gpointer userData)
 {
        RETV_IF(NULL == modeMgr, FALSE);
 
-       DBG("mode name = %s", modeName);
+       DBG("mode ID = %s", modeID);
 
        ClientPrivilege privInfo(invocation);
-       int ret = modeMgr->applyMode(modeName, privInfo, true);
+       int ret = modeMgr->applyMode(modeID, privInfo, true);
 
        mds_dbus_complete_can_apply(object, invocation, ret);
 
@@ -56,15 +56,15 @@ gboolean RequestHandler::canApplyModeHandler(mdsDbus *object, GDBusMethodInvocat
 }
 
 gboolean RequestHandler::applyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
-       const gchar *modeName, gpointer userData)
+       const gchar *modeID, gpointer userData)
 {
        RETV_IF(NULL == modeMgr, FALSE);
-       RETV_IF(NULL == modeName, FALSE);
+       RETV_IF(NULL == modeID, FALSE);
 
-       DBG("mode name = %s", modeName);
+       DBG("mode name = %s", modeID);
 
        ClientPrivilege privInfo(invocation);
-       int ret = modeMgr->applyMode(modeName, privInfo, false);
+       int ret = modeMgr->applyMode(modeID, privInfo, false);
 
        mds_dbus_complete_apply_mode(object, invocation, ret);
 
@@ -75,15 +75,15 @@ gboolean RequestHandler::applyModeHandler(mdsDbus *object, GDBusMethodInvocation
 }
 
 gboolean RequestHandler::undoModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
-       const gchar *modeName, gpointer userData)
+       const gchar *modeID, gpointer userData)
 {
        RETV_IF(NULL == modeMgr, FALSE);
-       RETV_IF(NULL == modeName, FALSE);
+       RETV_IF(NULL == modeID, FALSE);
 
-       DBG("mode name = %s", modeName);
+       DBG("mode ID = %s", modeID);
 
        ClientPrivilege privInfo(invocation);
-       int ret = modeMgr->undoMode(modeName, privInfo);
+       int ret = modeMgr->undoMode(modeID, privInfo);
 
        mds_dbus_complete_undo_mode(object, invocation, ret);
 
@@ -115,12 +115,12 @@ gboolean RequestHandler::addModeHandler(mdsDbus *object, GDBusMethodInvocation *
 }
 
 gboolean RequestHandler::removeModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
-               const gchar *modeName, gpointer userData)
+               const gchar *modeID, gpointer userData)
 {
        RETV_IF(NULL == modeMgr, FALSE);
-       RETV_IF(NULL == modeName, FALSE);
+       RETV_IF(NULL == modeID, FALSE);
 
-       int ret = modeMgr->removeMode(modeName);
+       int ret = modeMgr->removeMode(modeID);
        mds_dbus_complete_remove_mode(object, invocation, ret);
 
        return TRUE;
@@ -132,7 +132,7 @@ gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation
 
        RETV_IF(NULL == modeMgr, FALSE);
 
-       std::list<std::tuple<std::string, int, int>> modeList = modeMgr->getModes();
+       std::list<ModeInfo> modeList = modeMgr->getModes();
        if (modeList.empty()) {
                ERR("getModes() : No Data");
                ret = MODES_ERROR_NO_DATA;
@@ -140,11 +140,8 @@ gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation
 
        GVariantBuilder *modeListBuilder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_GET_MODES_SIG));
        for (auto it = modeList.begin(); it != modeList.end(); ++it) {
-               int state;
-               int type;
-               std::string name;
-               std::tie(name, type, state) = *it;
-               g_variant_builder_add(modeListBuilder, MODES_DBUS_GET_MODES_MODE_SIG, name.c_str(), type, state);
+               g_variant_builder_add(modeListBuilder, MODES_DBUS_GET_MODES_MODE_SIG, it->id.c_str(),
+                               it->name.c_str(), it->type, it->state);
        }
 
        GVariant *outList = g_variant_new(MODES_DBUS_GET_MODES_SIG, modeListBuilder);
@@ -161,7 +158,7 @@ gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation
 Mode RequestHandler::getModefromData(GVariant *inData)
 {
        GVariant *actionList;
-       gchar *modeName;
+       gchar *modeID, *modeName;
        gchar *id, *actName, *value;
        gint32 type;
        GVariantIter *iter;
@@ -169,8 +166,8 @@ Mode RequestHandler::getModefromData(GVariant *inData)
        Mode::ModeType modeType;
        gboolean modeHidden;
 
-       g_variant_get(inData, MODES_DBUS_MODE_SIG, &modeName, &type, &modeHidden, &actionList);
-       DBG("mode_name : %s // type : %d // hidden : %s", modeName, type, modeHidden? "true" : "false");
+       g_variant_get(inData, MODES_DBUS_MODE_SIG, &modeID, &modeName, &type, &modeHidden, &actionList);
+       DBG("id : %s // mode_name : %s // type : %d // hidden : %s", modeID, modeName, type, modeHidden? "true" : "false");
 
        switch (type) {
        case MODES_TYPE_MODE_NORMAL:
@@ -185,9 +182,11 @@ Mode RequestHandler::getModefromData(GVariant *inData)
                modeType = Mode::MODE_ONESHOT;
        }
 
+       mode.setID(modeID);
        mode.setName(modeName);
        mode.setModeType(modeType);
        mode.setHidden(modeHidden);
+       g_free(modeID);
        g_free(modeName);
 
        g_variant_get(actionList, MODES_DBUS_ACTION_LIST_SIG, &iter);
index 814190daa1893ebb3d3e555888285447914dd35d..45619d9d921974a500b97dcb0e2004ad919c5ba0 100644 (file)
@@ -84,9 +84,11 @@ void XMLGenerator::makeModeXML(const std::string &path, const Mode &mode)
 
        const std::string modeType = getModeTypeStr(mode.getModeType());
        std::string modeName = mode.getName();
+       std::string modeID = mode.getID();
 
        xmlNodePtr modeNode = xmlNewNode(NULL, ModesXMLTag::MODE);
 
+       xmlSetProp(modeNode, ModesXMLTag::ID, (xmlChar*)modeID.c_str());
        xmlSetProp(modeNode, ModesXMLTag::NAME, (xmlChar*)modeName.c_str());
        xmlSetProp(modeNode, ModesXMLTag::TYPE, (xmlChar*)modeType.c_str());
        if (true == mode.isHidden())
index 7a591b5d79e92b779ffe8655bb4a42ece16eeaff..78de0585743e7b037e37167c89e6027a8728ec66 100644 (file)
@@ -67,30 +67,30 @@ GMainLoop *AsyncTest::loop = NULL;
 
 TEST_F(AsyncTest, normalAsync)
 {
-       const char *modeName = "asyncEx1";
-       modes_undo_mode(handle, modeName);
-       g_idle_add(ModeIdler, (gpointer)modeName);
+       const char *modeID = "http://tizen.org/mode/example.asyncEx1";
+       modes_undo_mode(handle, modeID);
+       g_idle_add(ModeIdler, (gpointer)modeID);
        g_main_loop_run(loop);
 }
 
 TEST_F(AsyncTest, oneshotAsync)
 {
-       const char *modeName = "asyncEx2";
-       int ret = modes_apply_mode(handle, modeName);
+       const char *modeID = "http://tizen.org/mode/example.asyncEx2";
+       int ret = modes_apply_mode(handle, modeID);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 }
 
 TEST_F(AsyncTest, normalAsyncFail)
 {
-       const char *modeName = "asyncFail1";
-       modes_undo_mode(handle, modeName);
-       g_idle_add(failIdler, (gpointer)modeName);
+       const char *modeID = "http://tizen.org/mode/example.asyncFail1";
+       modes_undo_mode(handle, modeID);
+       g_idle_add(failIdler, (gpointer)modeID);
        g_main_loop_run(loop);
 }
 
 TEST_F(AsyncTest, oneshotAsyncFail)
 {
-       const char *modeName = "asyncFail2";
-       g_idle_add(failIdler, (gpointer)modeName);
+       const char *modeID = "http://tizen.org/mode/example.asyncFail2";
+       g_idle_add(failIdler, (gpointer)modeID);
        g_main_loop_run(loop);
 }
index 23acfa42facf7ee1b92befc26bc869cfad41a4ea..f28cce79315202bdfef72d6b9b410c3fb7e22e75 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 #include <iostream>
+#include <string>
 #include <glib.h>
 #include <gtest/gtest.h>
 #include <modes.h>
@@ -54,9 +55,10 @@ protected:
                return G_SOURCE_REMOVE;
        }
 
-       static void addModeTest(gpointer data)
+       static void addModeTest(std::string name)
        {
-               modes_mode_h created_mode = modes_create_mode((char*)data, MODES_TYPE_MODE_NORMAL);
+               std::string id = MODES_ID_PREFIX"example." + name;
+               modes_mode_h created_mode = modes_create_mode(id.c_str(), name.c_str(), MODES_TYPE_MODE_NORMAL);
                modes_action_h action_handle[2];
                action_handle[0] = modes_create_action("test.printBool", "on");
                action_handle[1] = modes_create_action("test.printBool", "off");
@@ -73,15 +75,17 @@ protected:
                modes_destroy_mode(created_mode);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               result = modes_apply_mode(handle, (char*)data);
+               result = modes_apply_mode(handle, id.c_str());
                EXPECT_EQ(MODES_ERROR_NONE, result);
        }
 
        static gboolean addModeIdler(gpointer data)
        {
-               addModeTest(data);
-               modes_undo_mode(handle, (char*)data);
-               modes_remove_mode(handle, (char*)data);
+               addModeTest((char*)data);
+
+               std::string id = MODES_ID_PREFIX"example." + std::string((char*)data);
+               modes_undo_mode(handle, id.c_str());
+               modes_remove_mode(handle, id.c_str());
                g_main_loop_quit(loop);
 
                return G_SOURCE_REMOVE;
@@ -89,13 +93,14 @@ protected:
 
        static gboolean removeModeIdler(gpointer data)
        {
-               addModeTest(data);
+               addModeTest((char*)data);
 
-               result = modes_remove_mode(handle, (char*)data);
+               std::string id = MODES_ID_PREFIX"example." + std::string((char*)data);
+               result = modes_remove_mode(handle, id.c_str());
                EXPECT_EQ(MODES_ERROR_CONFLICT, result);
 
-               modes_undo_mode(handle, (char*)data);
-               result = modes_remove_mode(handle, (char*)data);
+               modes_undo_mode(handle, id.c_str());
+               result = modes_remove_mode(handle, id.c_str());
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
                g_main_loop_quit(loop);
@@ -113,29 +118,29 @@ GMainLoop *ClientTest::loop = NULL;
 
 TEST_F(ClientTest, applyModeP)
 {
-       modes_undo_mode(handle, "ex1");
-       g_idle_add(applyModeIdler, (gpointer)"ex1");
+       modes_undo_mode(handle, "http://tizen.org/mode/example.ex1");
+       g_idle_add(applyModeIdler, (gpointer)"http://tizen.org/mode/example.ex1");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
 }
 
 TEST_F(ClientTest, applyModeN)
 {
-       g_idle_add(applyModeIdler, (gpointer)"non_ex2");
+       g_idle_add(applyModeIdler, (gpointer)"http://tizen.org/mode/example.non_ex2");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NO_DATA, result);
 }
 
 TEST_F(ClientTest, canApplyModeP)
 {
-       modes_undo_mode(handle, "ex1");
-       int ret = modes_can_apply(handle, "ex1");
+       modes_undo_mode(handle, "http://tizen.org/mode/example.ex1");
+       int ret = modes_can_apply(handle, "http://tizen.org/mode/example.ex1");
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 }
 
 TEST_F(ClientTest, canApplyModeN)
 {
-       int ret = modes_can_apply(handle, "ex4");
+       int ret = modes_can_apply(handle, "http://tizen.org/mode/example.ex4");
        EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
 }
 
@@ -158,16 +163,16 @@ TEST_F(ClientTest, removeMode)
 
 TEST_F(ClientTest, undoModeEx1)
 {
-       modes_undo_mode(handle, "ex1");
-       g_idle_add(undoModeIdler, (gpointer)"ex1");
+       modes_undo_mode(handle, "http://tizen.org/mode/example.ex1");
+       g_idle_add(undoModeIdler, (gpointer)"http://tizen.org/mode/example.ex1");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
 }
 
 TEST_F(ClientTest, undoModeEx2)
 {
-       modes_undo_mode(handle, "ex2");
-       g_idle_add(undoModeIdler, (gpointer)"ex2");
+       modes_undo_mode(handle, "http://tizen.org/mode/example.ex2");
+       g_idle_add(undoModeIdler, (gpointer)"http://tizen.org/mode/example.ex2");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
 }
@@ -186,6 +191,8 @@ TEST_F(ClientTest, getModes)
        for (cur = g_list_first(list); cur; cur = g_list_next(cur)) {
                EXPECT_NE(nullptr, cur->data);
 
+               const char *id = modes_get_mode_id((mode_list_data_h)cur->data);
+
                const char *name = modes_get_mode_name((mode_list_data_h)cur->data);
                EXPECT_NE(nullptr, name);
 
@@ -195,7 +202,7 @@ TEST_F(ClientTest, getModes)
                int state = modes_get_mode_state((mode_list_data_h)cur->data);
                EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, state);
 
-               std::cout << name << " " << typeList[type] << "(" << type << ") :state(" << state << ")" << std::endl;
+               std::cout << id << " "<< name << " " << typeList[type] << "(" << type << ") :state(" << state << ")" << std::endl;
        }
        modes_free_modes(list);
 }
index 29cb270e1ca21b001613eff53e161c081f84c250..c9b0df8a0a343bbfba1e45880edb429d2a984106 100644 (file)
@@ -59,7 +59,7 @@ TEST_F(ConflictTest, isSavedMode)
 {
        ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
        Mode mode = modeparser.getMode();
-       EXPECT_TRUE(careTaker.isSavedMode(mode.getName()));
+       EXPECT_TRUE(careTaker.isSavedMode(mode.getID()));
 }
 
 TEST_F(ConflictTest, checkConflictAction)
index f7aaa2e6779cb751bdac7bc4e894d69e4dbc507a..3e81b56506280bec4050e5b8e6d713279ac16b76 100644 (file)
@@ -61,12 +61,13 @@ void ModeManagerTest::printModeMap()
                "MODE_EXCLUSIVE" };
 
        if (!mdMgr.modeMap.empty()) {
-               cout << "| "; cout.width(15); cout << "Mode Name" << " | " << "ModeXML file Path" << "| type      | hidden" << endl;
+               cout << "| "; cout.width(30); cout << "Mode ID" << " | "; cout.width(15); cout << "Mode Name" << " | " << "ModeXML file Path" << "| type | hidden" << endl;
 
                for (auto it = mdMgr.modeMap.begin(); it != mdMgr.modeMap.end(); it++) {
-                       cout << "| ";  cout.width(15); cout << it->first.c_str() << " | " << std::get<0>(it->second).c_str() << " | ";
-                       cout << mode_type[std::get<1>(it->second)];
-                       if (std::get<2>(it->second))
+                       cout << "| ";  cout.width(30); cout << it->first.c_str() << " | " << it->second.name.c_str() << " | ";
+                       cout << it->second.path.c_str() << " | ";
+                       cout << mode_type[it->second.type] << " | ";
+                       if (it->second.hidden)
                                cout << "hidden";
                        else
                                cout << "Not hidden";
index 9145c84f6fd83b9db509ce2f9c6f0788a479c6ac..f170e66cf390fe3a36126bbc77ed532855ff6204 100644 (file)
@@ -42,12 +42,12 @@ protected:
                return G_SOURCE_REMOVE;
        }
 
-       static int notiFunc(const char *modeName, int state, void *user_data)
+       static int notiFunc(const char *modeID, int state, void *user_data)
        {
                char *requestMode = (char*)user_data;
 
-               std::cout << "notiFunc Changed Mode : " << modeName << std::endl;
-               EXPECT_EQ(requestMode, std::string(modeName));
+               std::cout << "notiFunc Changed Mode : " << modeID << std::endl;
+               EXPECT_EQ(requestMode, std::string(modeID));
                std::cout << "state : " << state << std::endl;
                EXPECT_EQ(expectedState, state);
 
@@ -56,12 +56,12 @@ protected:
                return MODES_ERROR_NONE;
        }
 
-       static int changeFn(const char *modeName, int state, void *user_data)
+       static int changeFn(const char *modeID, int state, void *user_data)
        {
                char *requestMode = (char*)user_data;
 
-               std::cout << "changeFn Changed Mode : " << modeName << std::endl;
-               EXPECT_EQ(requestMode, std::string(modeName));
+               std::cout << "changeFn Changed Mode : " << modeID << std::endl;
+               EXPECT_EQ(requestMode, std::string(modeID));
                std::cout << "state : " << state << std::endl;
 
                if (0 == state)
@@ -70,9 +70,9 @@ protected:
                return MODES_ERROR_NONE;
        }
 
-       static int notiMultiFunc1(const char *modeName, int state, void *user_data)
+       static int notiMultiFunc1(const char *modeID, int state, void *user_data)
        {
-               std::cout << "notiMultiFunc1 Changed Mode : " << modeName << std::endl;
+               std::cout << "notiMultiFunc1 Changed Mode : " << modeID << std::endl;
                std::cout << "state : " << state << std::endl;
 
                calledbit1 |= 0x1 << state;
@@ -80,9 +80,9 @@ protected:
                return MODES_ERROR_NONE;
        }
 
-       static int notiMultiFunc2(const char *modeName, int state, void *user_data)
+       static int notiMultiFunc2(const char *modeID, int state, void *user_data)
        {
-               std::cout << "notiMultiFunc2 Changed Mode : " << modeName << std::endl;
+               std::cout << "notiMultiFunc2 Changed Mode : " << modeID << std::endl;
                std::cout << "state : " << state << std::endl;
 
                calledbit2 |= 0x1 << state;
@@ -90,9 +90,9 @@ protected:
                return MODES_ERROR_NONE;
        }
 
-       static int notiMultiFunc3(const char *modeName, int state, void *user_data)
+       static int notiMultiFunc3(const char *modeID, int state, void *user_data)
        {
-               std::cout << "notiMultiFunc3 Changed Mode : " << modeName << std::endl;
+               std::cout << "notiMultiFunc3 Changed Mode : " << modeID << std::endl;
                std::cout << "state : " << state << std::endl;
 
                EXPECT_TRUE(NULL == user_data || notiTestMode == user_data);
@@ -126,11 +126,11 @@ unsigned char ClientNotiTest::calledbit2 = 0;
 unsigned char ClientNotiTest::calledbit3 = 0;
 unsigned char ClientNotiTest::calledbit4 = 0;
 GMainLoop *ClientNotiTest::loop = NULL;
-const char *ClientNotiTest::notiTestMode = "ex2";
+const char *ClientNotiTest::notiTestMode = "http://tizen.org/mode/example.ex2";
 
 TEST_F(ClientNotiTest, subscribeCB)
 {
-       const char *testMode = "ex2";
+       const char *testMode = "http://tizen.org/mode/example.ex2";
        modes_noti_ID id = modes_subscribe_mode_changes(handle, notiFunc, (void*)testMode);
        EXPECT_NE(nullptr , id);
 
@@ -181,7 +181,7 @@ TEST_F(ClientNotiTest, subscribeMultiCb)
 
 TEST_F(ClientNotiTest, essentialAction)
 {
-       const char *testMode = "essential_ex";
+       const char *testMode = "http://tizen.org/mode/example.essential_ex";
        modes_noti_ID id = modes_subscribe_mode_changes(handle, changeFn, (void*)testMode);
        EXPECT_NE(nullptr, id);