Extend get mode list
authorJinWang An <jinwang.an@samsung.com>
Thu, 20 Feb 2020 05:46:08 +0000 (14:46 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
13 files changed:
client/mdsc_get_modes.c
common/dbus.xml
common/dbus_def.h
include/modes.h
include/modes_types.h
supervisor/ModeManager.cpp
supervisor/ModeManager.h
supervisor/ModeParser.h
supervisor/ModeXMLParser.cpp
supervisor/ModeXMLParser.h
supervisor/RequestHandler.cpp
unittest/modes_test_client.cpp
unittest/modes_test_modemgr.cpp

index f3751a3221259d09e3ec465197e8ab5efc2652c2..17e9ec3fc7df32fe963a6100d0b308c5eaa20c45 100644 (file)
 #include "common/dbus.h"
 #include "common/dbus_def.h"
 
+struct mds_list_data_handle {
+       char *name;
+       modes_type_mode_e type;
+       int state;
+};
+
 static GList* _get_mode_list(GVariant *in_data)
 {
        gchar *mode_name;
        gint32 state;
+       gint32 type;
        GVariantIter *iter;
        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, &state)) {
+       while (g_variant_iter_loop(iter, MODES_DBUS_GET_MODES_MODE_SIG, &mode_name, &type, &state)) {
                DBG("mode(%s) : state(%d)", mode_name, state);
-               modes_mode_t *mode = malloc(sizeof(modes_mode_t));
+               mode_list_data_h mode = malloc(sizeof(struct mds_list_data_handle));
                if (NULL == mode) {
                        ERR("malloc() Fail");
                        return NULL;
                }
                mode->name = strdup(mode_name);
                mode->state = state;
+               mode->type = type;
                mode_list = g_list_append(mode_list, mode);
        }
        g_variant_iter_free(iter);
@@ -83,7 +91,7 @@ API int modes_get_modes(modes_h handle, GList **list)
 
 static void _free_mode(gpointer data, gpointer user_data)
 {
-       modes_mode_t *mode = data;
+       mode_list_data_h mode = data;
        free(mode->name);
        free(mode);
 }
@@ -93,3 +101,21 @@ API void modes_free_modes(GList *list)
        g_list_foreach(list, _free_mode, NULL);
        g_list_free(list);
 }
+
+API const char* modes_get_mode_name(mode_list_data_h data)
+{
+       RETV_IF(NULL == data, NULL);
+       return data->name;
+}
+
+API int modes_get_mode_type(mode_list_data_h data)
+{
+       RETV_IF(NULL == data, MODES_ERROR_INVALID_PARAMETER);
+       return data->type;
+}
+
+API int modes_get_mode_state(mode_list_data_h data)
+{
+       RETV_IF(NULL == data, MODES_ERROR_INVALID_PARAMETER);
+       return data->state;
+}
index 714f539feac7b24d2fe934e830f668dca37361b9..683a1ac259c48d8283f1ef357a4fc929d0b36bd1 100644 (file)
@@ -17,7 +17,7 @@
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <method name="getModes">
-                       <arg type="a(si)" name="modeList" direction="out"/>
+                       <arg type="a(sii)" name="modeList" direction="out"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
                <signal name="changedMode">
index a527128f260e2fb4d3875a1e35b50c34ed827a82..ae922bb20c3dfef98857c8193d83f836c641c2d4 100644 (file)
@@ -26,5 +26,5 @@
 #define MODES_DBUS_ACTION_SIG "(sss)"
 #define MODES_DBUS_ACTION_LIST_SIG "a" MODES_DBUS_ACTION_SIG
 
-#define MODES_DBUS_GET_MODES_MODE_SIG "(si)"
+#define MODES_DBUS_GET_MODES_MODE_SIG "(sii)"
 #define MODES_DBUS_GET_MODES_SIG "a" MODES_DBUS_GET_MODES_MODE_SIG
index 592075eca6b5f86c1945e7a45a90733418905a8c..a994552e51d6848d589ff91797b72cafb465154f 100644 (file)
@@ -50,10 +50,11 @@ extern "C" {
 modes_h modes_connect();
 
 /**
- * @brief disconnect mode server.
+ * @brief disconnect modes server.
  * @details Calls this function to disconnect mode server
  * @since_tizen 6.0
  * @privlevel public
+ * @param[in] Handle of modes server to disconnect;
  */
 void modes_disconnect(modes_h handle);
 
@@ -64,6 +65,7 @@ void modes_disconnect(modes_h handle);
  * @privlevel public
  * @privilege %http://tizen.org/privilege/network.get
  * @privilege %http://tizen.org/privilege/internet
+ * @param[in] Handle of modes server
  * @param[in] Mode name to change
  * @return @c 0 on success,
  *         otherwise a negative error value
@@ -80,6 +82,7 @@ int modes_apply_mode(modes_h handle, const char *name);
  * @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
  * @return @c 0 on success,
  *         otherwise a negative error value
@@ -100,6 +103,7 @@ int modes_can_apply(modes_h handle, const char *name);
  * @privlevel public
  * @privilege %http://tizen.org/privilege/network.get
  * @privilege %http://tizen.org/privilege/internet
+ * @param[in] Handle of modes server
  * @param[in] Mode name to undo
  * @return @c 0 on success,
  *         otherwise a negative error value
@@ -117,7 +121,6 @@ int modes_undo_mode(modes_h handle, const char *name);
  * @details Calls this function to create mode.
  * @since_tizen 6.0
  * @privlevel public
- * @param[out]
  * @param[in] Mode name
  * @param[in] Mode type
  * @return @c Mode handle pointer on success,
@@ -131,7 +134,6 @@ modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type);
  * @details Calls this function to hide mode list.
  * @since_tizen 6.0
  * @privlevel public
- * @param[out]
  * @param[in] Mode handle
  * @param[in] Mode hidden
  * @return @c 0 on success,
@@ -190,6 +192,7 @@ int modes_mode_add_action(modes_mode_h mode, modes_action_h action);
  * @details Calls this function to register mode.
  * @since_tizen 6.0
  * @privlevel public
+ * @param[in] Handle of modes server
  * @param[in] Mode handle to register
  * @return @c 0 on success,
  *         otherwise a negative error value
@@ -228,6 +231,7 @@ typedef int (*modes_noti_fn) (const char *mode_name, int state, void *user_data)
  * @details Sets a function to be called when the mode is changed.
  * @since_tizen 6.0
  *
+ * @param[in] Handle of modes server
  * @param[in] cb The callback function to invoke
  * @param[in] user_data The user data to pass to the function
  *
@@ -244,7 +248,8 @@ int modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_da
  * @brief stop recognizing the changed of mode.
  * @details Removes a function to be called when the mode is changed.
  * @since_tizen 6.0
-
+ *
+ * @param[in] Handle of modes server
  * @param[in] cb The callback function to stop invoking
  * @param[in] user_data The user data to pass to the function
  *
@@ -252,16 +257,66 @@ int modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_da
  */
 void modes_unsubscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_data);
 
-//TODO:it must be opaque type
-typedef struct {
-       char *name;
-       //int type;
-       int state;
-} modes_mode_t;
-
+/**
+ * @brief Get mode list
+ * @details Calls this function to get mode list
+ * @since_tizen 6.0
+ * @privlevel public
+ * @param[in] Handle of modes server
+ * @param[in] GList for mode list
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #MODES_ERROR_NONE Successful
+ * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MODES_ERROR_SYSTEM System errors
+ */
 int modes_get_modes(modes_h handle, GList **list);
+
+/**
+ * @brief Free mode list
+ * @details Calls this function to get mode list
+ * @since_tizen 6.0
+ * @privlevel public
+ * @param[in] GList for mode list to free
+ * @return void
+ */
 void modes_free_modes(GList *list);
 
+/**
+ * @brief Get name 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 to free
+ * @return mode name
+ */
+const char* modes_get_mode_name(mode_list_data_h data);
+
+/**
+ * @brief Get type 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 to free
+ * @return mode type
+ * @retval MODES_TYPE_MODE_NORMAL It's allowed to undo and apply other mode
+ * @retval MODES_TYPE_MODE_ONESHOT It doesn't support to be managed.
+ */
+int modes_get_mode_type(mode_list_data_h data);
+
+/**
+ * @brief Get state 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 to free
+ * @return 1 or 0, success otherwise a negative error value.
+ * @retval 1 mode ON
+ * @retval 0 mode OFF
+ * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int modes_get_mode_state(mode_list_data_h data);
+
 /**
  * @}
  */
index dc4e1a396f7b65473decf3f31203f50ab812ea9c..48ef08416bd684760b702811e7b97772312625d8 100644 (file)
@@ -57,7 +57,12 @@ typedef struct mds_mode_handle* modes_mode_h;
  */
 typedef struct mds_action_handle* modes_action_h;
 
-
+/**
+ * @brief The Modes mode data
+ * @details @a mode_list_data_h is an opaque data structure to represent mode data.
+ * @since_tizen 6.0
+ */
+typedef struct mds_list_data_handle* mode_list_data_h;
 /**
  * @}
  */
index 359fb7432e39fdb2b52207794f9b118226ace909..03693732bc58bbe9056b6fcd2d4bdc59647491c9 100644 (file)
@@ -74,9 +74,10 @@ void ModeManager::addModeAttributes(ModeParser *parser, const string &path)
 {
        string modeName = parser->getModeName();
        bool hidden = parser->isHidden();
-       modeMap.insert(std::make_pair(modeName, std::make_pair(path, hidden)));
+       Mode::ModeType type = parser->getModeType();
+       modeMap.insert(std::make_pair(modeName, std::make_tuple(path, type, hidden)));
 
-       DBG("[%d] modeName : %s, modePath : %s, hidden : %s", modeMap.size(), modeName.c_str(), path.c_str(), hidden? "true": "false");
+       DBG("[%d] modeName : %s, modePath : %s, type : %d, hidden : %s", modeMap.size(), modeName.c_str(), path.c_str(), type, hidden? "true": "false");
 }
 
 int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool isTest)
@@ -87,7 +88,7 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i
                return MODES_ERROR_NO_DATA;
        }
 
-       string path = found->second.first;
+       string path = std::get<0>(found->second);
        DBG("applyMode(%s)", path.c_str());
 
        try {
@@ -149,8 +150,8 @@ int ModeManager::registerMode(const Mode &mode)
                return MODES_ERROR_INVALID_PARAMETER;
        }
 
-       modeMap.insert(std::make_pair(mode.getName(), std::make_pair(filename, false)));
-       DBG("[%d] Register modeName : %s, modePath : %s, hidden : false", modeMap.size(), mode.getName().c_str(), filename.c_str());
+       modeMap.insert(std::make_pair(mode.getName(), std::make_tuple(filename, mode.getModeType(), false)));
+       DBG("[%d] Register modeName : %s, modePath : %s, type : %d, hidden : false", modeMap.size(), mode.getName().c_str(), filename.c_str(), mode.getModeType());
 
        return MODES_ERROR_NONE;
 }
@@ -169,16 +170,17 @@ int ModeManager::undoMode(const string &modeName)
        return MODES_ERROR_NONE;
 }
 
-std::list<std::tuple<string, int>> ModeManager::getModes()
+std::list<std::tuple<string, int, int>> ModeManager::getModes()
 {
-       std::list<std::tuple<string, int>> modeList;
+       std::list<std::tuple<string, int, int>> modeList;
 
        for (auto it = modeMap.begin(); it != modeMap.end(); ++it) {
-                       bool hidden = it->second.second;
-                       if (true == hidden)
-                               continue;
+               bool hidden = std::get<2>(it->second);
+               if (true == hidden)
+                       continue;
+               int type = std::get<1>(it->second);
                int state = careTaker.isSavedMode(it->first);
-               modeList.push_back(std::tuple<string, int>(it->first, state));
+               modeList.push_back(std::tuple<string, int, int>(it->first, type, state));
        }
 
        return modeList;
@@ -265,7 +267,7 @@ bool ModeManager::restoreUndoInfo(const string &dirPath)
                                throw ModesEx(ModesEx::NO_DATA);
                        }
 
-                       string path = found->second.first;
+                       string path = std::get<0>(found->second);
                        std::unique_ptr<ModeParser> parser(getModeParser(path));
                        Mode mode = parser->getMode();
                        undoInfoParser.putUndoInfo(mode);
index 82f4adb38b6ef234c1f5f545280ff6f09c3c9493..50b5d9f445ed2cbcd23e69de675b167c3c94bc46 100644 (file)
@@ -43,7 +43,7 @@ public:
        int applyMode(const std::string &modeName, ClientPrivilege &priv, bool isTest);
        int registerMode(const Mode &mode);
        int undoMode(const std::string &modeName);
-       std::list<std::tuple<std::string, int>> getModes();
+       std::list<std::tuple<std::string, int, int>> getModes();
        void attachObserver(ModeObserver *obs);
        void detachObserver(ModeObserver *obs);
 private:
@@ -54,7 +54,7 @@ private:
        void addModeAttributes(ModeParser *parser, const std::string &path);
        ModeParser* getModeParser(const std::string &path);
 
-       std::map<std::string, std::pair<std::string, bool>> modeMap;
+       std::map<std::string, std::tuple<std::string, int, bool>> modeMap;
        std::set<std::string> modeDirList;
        std::string undoDir;
        std::string modeSyntaxFile;
index d28e553ab34fc16daf7d9c0eeaf96238b0ef5844..e18eb011c485325b5d92ba7db8a984b22fa8ec18 100644 (file)
@@ -29,6 +29,7 @@ public:
        virtual Mode getMode() = 0;
        virtual std::string getModeName() = 0;
        virtual bool isHidden() = 0;
+       virtual Mode::ModeType getModeType() = 0;
        virtual void validateMode(const std::string &syntaxFile) = 0;
 protected:
        ModeParser(RuleManager &rMgr) :ruleMgr(rMgr)
index 1fb105b8ea7791fd171531abc6ab69afd3e9a1cc..f20aecdd68ddfe06c502a63220d4e26df4f01a84 100644 (file)
@@ -43,32 +43,35 @@ Mode ModeXMLParser::getMode()
 
 std::string ModeXMLParser::getModeName()
 {
-       if (false == isParsedModeAttr) {
-               parseModeAttr();
-               isParsedModeAttr = true;
-       }
+       parseModeAttrOnly();
        return mode.getName();
 }
 
 bool ModeXMLParser::isHidden()
 {
-       if (false == isParsedModeAttr) {
-               parseModeAttr();
-               isParsedModeAttr = true;
-       }
+       parseModeAttrOnly();
        return mode.isHidden();
 }
 
-void ModeXMLParser::parseModeAttr()
+Mode::ModeType ModeXMLParser::getModeType()
+{
+       parseModeAttrOnly();
+       return mode.getModeType();
+}
+
+void ModeXMLParser::parseModeAttrOnly()
 {
+       if (true == isParsedModeAttr)
+               return;
+
+       isParsedModeAttr = true;
        xmlNodePtr root = getRoot();
        for (xmlNodePtr cur = root->children; cur; cur = cur->next) {
                if (xmlIsBlankNode(cur))
                        continue;
 
                if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::MODE)) {
-                       mode.setName(extractModeName(cur));
-                       mode.setHidden(extractHidden(cur));
+                       parseModeAttr(cur);
                        break;
                }
        }
@@ -122,7 +125,7 @@ void ModeXMLParser::validateElement(xmlNodePtr node)
 void ModeXMLParser::parseElement(xmlNodePtr node)
 {
        if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::MODE)) {
-               parseMode(node);
+               parseModeAttr(node);
        } else if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::ACTION)) {
                parseAction(node);
        } else if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::UNDO)) {
@@ -132,7 +135,7 @@ void ModeXMLParser::parseElement(xmlNodePtr node)
        }
 }
 
-void ModeXMLParser::parseMode(xmlNodePtr node)
+void ModeXMLParser::parseModeAttr(xmlNodePtr node)
 {
        mode.setName(extractModeName(node));
        mode.setModeType(extractModeType(node));
index 2cd72a49ea29ecf94e2ed2c962ed21b4f7245277..d04c45cc51a320954ecd292857757f4758f33d7e 100644 (file)
@@ -32,10 +32,11 @@ public:
        Mode getMode() override;
        std::string getModeName() override;
        bool isHidden() override;
+       Mode::ModeType getModeType() override;
        void validateMode(const std::string &xsd) override;
 
 private:
-       void parseMode(xmlNodePtr node);
+       void parseModeAttr(xmlNodePtr node);
        std::string extractModeName(xmlNodePtr node);
        Mode::ModeType extractModeType(xmlNodePtr node);
        bool extractHidden(xmlNodePtr node);
@@ -43,7 +44,7 @@ private:
        void parseAction(xmlNodePtr node);
        void parseUndo(xmlNodePtr node);
        Action *parseActionInfo(xmlNodePtr node);
-       void parseModeAttr();
+       void parseModeAttrOnly();
        void validateAction(xmlNodePtr node);
        void validateElement(xmlNodePtr node);
        void parseElement(xmlNodePtr node);
index 23b0efeeaf42a85fce98b1ea167488410f2c15bc..aff5b784416e848ee5ce3081c3cc0d95b51249bd 100644 (file)
@@ -104,7 +104,7 @@ gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation
 
        RETV_IF(NULL == modeMgr, FALSE);
 
-       std::list<std::tuple<std::string, int>> modeList = modeMgr->getModes();
+       std::list<std::tuple<std::string, int, int>> modeList = modeMgr->getModes();
        if (modeList.empty()) {
                ERR("getModes() : No Data");
                ret = MODES_ERROR_NO_DATA;
@@ -113,9 +113,10 @@ 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, state) = *it;
-               g_variant_builder_add(modeListBuilder, MODES_DBUS_GET_MODES_MODE_SIG, name.c_str(), state);
+               std::tie(name, type, state) = *it;
+               g_variant_builder_add(modeListBuilder, MODES_DBUS_GET_MODES_MODE_SIG, name.c_str(), type, state);
        }
 
        GVariant *outList = g_variant_new(MODES_DBUS_GET_MODES_SIG, modeListBuilder);
index 3018a84c172ab9a8fab199f262a0a3923ef8fbdd..4b9a61f6e4bd93c35334bf0d772980f642756c89 100644 (file)
@@ -149,15 +149,29 @@ TEST_F(ClientTest, undoModeEx2)
 
 TEST_F(ClientTest, getModes)
 {
+const char* const typeList[3] = {
+               "MODES_TYPE_MODE_NORMAL",
+               "MODES_TYPE_MODE_ONESHOT",
+               "MODES_TYPE_MODE_EXCLUSIVE"
+       };
+
        GList *list, *cur;
        int ret = modes_get_modes(handle, &list);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 
        for (cur = g_list_first(list); cur; cur = g_list_next(cur)) {
-               modes_mode_t *mode = (modes_mode_t*)cur->data;
-               EXPECT_NE(nullptr, mode);
-               EXPECT_NE(nullptr, mode->name);
-               std::cout << mode->name << ":state(" << mode->state << ")" << std::endl;
+               EXPECT_NE(nullptr, cur->data);
+
+               const char *name = modes_get_mode_name((mode_list_data_h)cur->data);
+               EXPECT_NE(nullptr, name);
+
+               int type = modes_get_mode_type((mode_list_data_h)cur->data);
+               EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, type);
+
+               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;
        }
        modes_free_modes(list);
 }
index 785a49dad792962f66fc6e1445d455207a5dcabe..b5dbd336a8689f09daff896844f70c3b736a7f88 100644 (file)
@@ -60,12 +60,18 @@ bool ModeManagerTest::emptyModeMap()
 
 void ModeManagerTest::printModeMap()
 {
+       static const char* const mode_type[3] = {
+               "MODE_NORMAL",
+               "MODE_ONESHOT",
+               "MODE_EXCLUSIVE" };
+
        if (!mdMgr.modeMap.empty()) {
-               cout << "| "; cout.width(15); cout << "Mode Name" << " | " << "ModeXML file Path" << endl;
+               cout << "| "; 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() << " | " << it->second.first.c_str() << " | ";
-                       if (it->second.second)
+                       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 << "hidden";
                        else
                                cout << "Not hidden";