#include <tizen.h>
#define TIZEN_ERROR_MODES -0x03020000
-/**
- * @file modes-errors.h
- */
+ /**
+ * @file modes-errors.h
+ */
-/**
- * @ingroup CAPI_MODE_SUPERVISOR_MODULE
- * @brief Enumeration for Modes error code.
- * @since_tizen 5.5
- * @{
- */
+ /**
+ * @ingroup CAPI_MODE_SUPERVISOR_MODULE
+ * @brief Enumeration for Modes error code.
+ * @since_tizen 5.5
+ * @{
+ */
typedef enum {
MODES_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
MODES_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
* MODES_ERROR_TIMEOUT -1073741823
*/
+typedef enum {
+ MODEPARSER_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ MODEPARSER_ERROR_FILE_NOTEXIST = -1, /**< Filen do not exist */
+ MODEPARSER_ERROR_FORMAT_INVALID = -2 /**< Invalid format */
+} modeparser_error_e;
+
/**
* @}
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(libxml-2.0)
%description
The modes(Mode Supervisor) manages configurations which is described at a mode.
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/mds-dbus.c
PROPERTIES GENERATED TRUE)
-SET(PKG_MODULES gio-2.0 dlog gio-unix-2.0)
+SET(PKG_MODULES gio-2.0 dlog gio-unix-2.0 libxml-2.0)
pkg_check_modules(daemon_pkgs REQUIRED ${PKG_MODULES})
--- /dev/null
+/*
+ * 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 "mdss_Action.h"
+#include "mdss.h"
+
+Action::Action(std::string name)
+ :strName(name)
+{
+}
+
+Action::~Action()
+{
+}
+
+
+
+void Action::setName(std::string name)
+{
+ strName = name;
+}
+
+std::string Action::getName()
+{
+ return strName;
+}
+
+void Action::setAchieve(std::string achieve)
+{
+ strAchieve = achieve;
+}
+
+void Action::setChangeable(std::string changeable)
+{
+ strChangeable = changeable;
+}
+
+void Action::setContent(std::string content)
+{
+ strContent = content;
+}
+
+std::string Action::getAchieve()
+{
+ return strAchieve;
+}
+
+std::string Action::getChangeable()
+{
+ return strChangeable;
+}
+
+std::string Action::getContent()
+{
+ return strContent;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef __MODES_INTERNAL_SUPERVISOR_ACTION_H__
+#define __MODES_INTERNAL_SUPERVISOR_ACTION_H__
+
+#include <string>
+
+class Action
+{
+public:
+ Action(std::string name);
+ ~Action();
+
+public:
+ void setName(std::string name);
+ std::string getName();
+
+ void setAchieve(std::string achieve);
+ void setChangeable(std::string changeable);
+ void setContent(std::string content);
+ std::string getAchieve();
+ std::string getChangeable();
+ std::string getContent();
+
+private:
+ std::string strName;
+ std::string strAchieve;
+ std::string strChangeable;
+ std::string strContent;
+};
+
+#endif /* __MODES_INTERNAL_SUPERVISOR_ACTION_H__ */
--- /dev/null
+/*
+ * 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 "mdss_Mode.h"
+#include "mdss.h"
+
+Mode::Mode()
+{
+}
+Mode::Mode(std::string name)
+ :strName(name)
+{
+}
+
+Mode::~Mode()
+{
+ actionList.clear();
+}
+
+void Mode::addAction(const Action& action)
+{
+ actionList.push_back(action);
+}
+
+unsigned int Mode::getActionCount()
+{
+ return (unsigned int)actionList.size();
+}
+
+bool Mode::getActionbyIndex(int index, Action& action)
+{
+ int count = (int)actionList.size();
+ if (index < 0 || index >= count)
+ return false;
+
+ // delete all items in actionList
+ int i = 0;
+ for (std::list<Action>::iterator it = actionList.begin(); it != actionList.end(); ++it)
+ {
+ if (i == index) {
+ action = *it;
+ return true;
+ }
+ i++;
+ }
+ return false;
+}
+
+void Mode::getActionListIterator(ActionIterator& it_begin, ActionIterator& it_end)
+{
+ it_begin = actionList.begin();
+ it_end = actionList.end();
+}
+
+void Mode::setName(std::string name)
+{
+ strName = name;
+}
+
+std::string Mode::getName()
+{
+ return strName;
+}
+
+void Mode::setTransparent(std::string transparent)
+{
+ strTransparent = transparent;
+}
+
+std::string Mode::getTransparent()
+{
+ return strTransparent;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef __MODES_INTERNAL_SUPERVISOR_MODE_H__
+#define __MODES_INTERNAL_SUPERVISOR_MODE_H__
+
+#include "mdss_Action.h"
+#include <list>
+
+
+typedef std::list<Action>::iterator ActionIterator;
+
+class Mode
+{
+public:
+ Mode();
+ Mode(std::string name);
+ ~Mode();
+
+public:
+ void setName(std::string name);
+ std::string getName();
+
+ void setTransparent(std::string transparent);
+ std::string getTransparent();
+
+ void addAction(const Action& action);
+
+ unsigned int getActionCount();
+ bool getActionbyIndex(int index, Action& action);
+ void getActionListIterator(ActionIterator& it_begin, ActionIterator& it_end);
+
+private:
+ std::string strName;
+ std::string strTransparent;
+
+ std::list<Action> actionList;
+};
+
+#endif /* __MODES_INTERNAL_SUPERVISOR_MODE_H__ */
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef __MODES_INTERNAL_SUPERVISOR_MODEPARSER_H__
+#define __MODES_INTERNAL_SUPERVISOR_MODEPARSER_H__
+
+#include "mdss_Mode.h"
+#include "mdss.h"
+
+class ModeParser
+{
+public:
+ virtual void getMode(const std::string& filepath, Mode& desc) throw(modeparser_error_e) = 0;
+ virtual std::string getModeName(const std::string& filepath) throw(modeparser_error_e) = 0;
+
+protected:
+ ModeParser() {}
+public:
+ virtual ~ModeParser() {}
+public:
+ static ModeParser *Create();
+};
+
+#endif /* __MODES_INTERNAL_SUPERVISOR_MODEPARSER_H__ */
--- /dev/null
+/*
+ * 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.
+ */
+
+#define MODE_TAG_TIZEN "tizen"
+#define MODE_TAG_XMLNS "xmlns"
+#define MODE_TAG_VERSION "version"
+#define MODE_TAG_MODE "mode"
+#define MODE_TAG_ACTION "action"
+#define MODE_TAG_NAME "name"
+#define MODE_TAG_TRANSPARENT "Transparent"
+#define MODE_TAG_ACHIEVE "Achieve"
+#define MODE_TAG_CHANGEABLE "Changeable"
+
+#include "mdss_ModeXmlParser.h"
+
+#include <string>
+#include "mdss.h"
+#include <libxml/tree.h>
+#include <sys/stat.h>
+
+
+ModeXmlParser::ModeXmlParser()
+{
+}
+
+ModeXmlParser ::~ModeXmlParser()
+{
+}
+
+
+
+typedef bool(*callbackFindCondition)(xmlNode *node);
+
+// Find element node that callbackFindCondition retrun true
+static xmlNode *findElement(xmlNode *a_node, callbackFindCondition compare_cb)
+{
+ for (xmlNode *cur_node = a_node; cur_node; cur_node = cur_node->next) {
+ // Check if handle refers for node, not ex. node text
+ if (cur_node->type == XML_ELEMENT_NODE) {
+ if ((*compare_cb)(cur_node)) {
+ return cur_node;
+ }
+ }
+ xmlNode *node = findElement(cur_node->children, compare_cb);
+ if (node)
+ return node;
+ }
+ return nullptr;
+}
+
+// Open XML File with xmlParseDoc()
+static modeparser_error_e OpenXMLFile(const char *filepath, xmlDocPtr& doc)
+{
+ //Check if file exist
+ struct stat data;
+ if (stat(filepath, &data) != 0) {
+ return MODEPARSER_ERROR_FILE_NOTEXIST;
+ }
+
+ // Parse XML
+ doc = xmlParseFile(filepath);
+ if (doc == NULL) {
+ ERR("failed to parse the including file\n");
+ return MODEPARSER_ERROR_FORMAT_INVALID;
+ }
+
+ return MODEPARSER_ERROR_NONE;
+}
+
+// Extract specified data from XML nodes
+static void getDatafromNode(xmlNode *cur_node, Mode& modedesc)
+{
+ xmlChar *tmp1, *tmp2, *tmp3;
+
+ if (!strcmp((char *)cur_node->name, MODE_TAG_MODE)) {
+ std::string name, transparent;
+ tmp1 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_NAME);
+ if (tmp1)
+ name = (char *)tmp1;
+ tmp2 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_TRANSPARENT);
+ if (tmp2)
+ transparent = (char *)tmp2;
+ DBG("%s:\n\tname: %s\n\tTransparent: %s\n", cur_node->name, tmp1, tmp2);
+ xmlFree(tmp1);
+ xmlFree(tmp2);
+
+ modedesc.setName(name);
+ modedesc.setTransparent(transparent);
+ } else if (!strcmp((char *)cur_node->name, MODE_TAG_ACTION)) {
+ std::string name, achieve, changeable, content;
+ tmp1 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_NAME);
+ if (tmp1)
+ name = (char *)tmp1;
+ tmp2 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_ACHIEVE);
+ if (tmp2)
+ achieve = (char *)tmp2;
+ tmp3 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_CHANGEABLE);
+ if (tmp3)
+ changeable = (char *)tmp3;
+ DBG("\t%s:\n\t\tname: %s\n\t\tAchieve: %s\n\t\tChangeable: %s\n", cur_node->name, tmp1, tmp2, tmp3);
+ xmlFree(tmp1);
+ xmlFree(tmp2);
+ xmlFree(tmp3);
+
+ tmp1 = xmlNodeGetContent(cur_node);
+ if (tmp1)
+ content = (char *)tmp1;
+ DBG("\t\tcontent: %s\n", tmp1);
+ xmlFree(tmp1);
+
+ Action modeaction(name);
+ modeaction.setAchieve(achieve);
+ modeaction.setChangeable(changeable);
+ modeaction.setContent(content);
+ modedesc.addAction(modeaction);
+ } else if (!strcmp((char *)cur_node->name, MODE_TAG_TIZEN)) {
+ tmp1 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_XMLNS);
+ tmp2 = xmlGetProp(cur_node, (const xmlChar *)MODE_TAG_VERSION);
+
+ DBG("%s:\n\txmlns: %s\n\tversion: %s\n", cur_node->name, tmp1, tmp2);
+
+ xmlFree(tmp1);
+ xmlFree(tmp2);
+ } else {
+ DBG("%s::\n", cur_node->name);
+ }
+}
+
+
+// Recursively iterate thought XML tree
+static void iterateElement(xmlNode *a_node, Mode& modedesc)
+{
+ xmlNode *cur_node = NULL;
+
+ for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
+ // Check if handle refers for node, not ex. node text
+ if (cur_node->type == XML_ELEMENT_NODE) {
+ // Get feature from node
+ getDatafromNode(cur_node, modedesc);
+ }
+ iterateElement(cur_node->children, modedesc);
+ }
+}
+
+
+void ModeXmlParser::getMode(const std::string& filepath, Mode& modedesc)
+ throw(modeparser_error_e)
+{
+ xmlDocPtr doc;
+ modeparser_error_e err = OpenXMLFile(filepath.c_str(), doc);
+ if (err != MODEPARSER_ERROR_NONE) {
+ throw(err);
+ return;
+ }
+
+ xmlNode *root_element = xmlDocGetRootElement(doc);
+ // Start geting data from nodes
+ iterateElement(root_element, modedesc);
+
+ xmlFreeDoc(doc);
+}
+
+// callback for finding "mode" element
+static bool cbCheckModeElement(xmlNode *node)
+{
+ if (!node)
+ return false;
+ if (strcmp((char *)node->name, MODE_TAG_MODE))
+ return false;
+ return true;
+}
+
+std::string ModeXmlParser::getModeName(const std::string& filepath)
+ throw(modeparser_error_e)
+{
+ std::string name;
+ xmlDocPtr doc;
+ modeparser_error_e err = OpenXMLFile(filepath.c_str(), doc);
+ if (err != MODEPARSER_ERROR_NONE) {
+ throw(err);
+ return name;
+ }
+
+ xmlNode *root_element = xmlDocGetRootElement(doc);
+ // Start geting data from nodes
+ xmlNode *node = findElement(root_element, cbCheckModeElement);
+ if (!node) {
+ xmlFreeDoc(doc);
+ throw(MODEPARSER_ERROR_FORMAT_INVALID);
+ return name;
+ }
+
+ xmlChar *tmp1;
+ if (!strcmp((char *)node->name, MODE_TAG_MODE)) {
+ tmp1 = xmlGetProp(node, (const xmlChar *)MODE_TAG_NAME);
+ if (tmp1) {
+ name = (char *)tmp1;
+ DBG("%s:\n\tname: %s\n", node->name, tmp1);
+ xmlFree(tmp1);
+ return name;
+ }
+ }
+ xmlFreeDoc(doc);
+
+ throw(MODEPARSER_ERROR_FORMAT_INVALID);
+ return name;
+}
+
+//==============================================================//
+// Implementation of ModeParser::Create()
+
+ModeParser *ModeParser::Create()
+{
+ return new ModeXmlParser;
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef __MODES_INTERNAL_SUPERVISOR_MODEXMLPARSER_H__
+#define __MODES_INTERNAL_SUPERVISOR_MODEXMLPARSER_H__
+
+#include "mdss_ModeParser.h"
+
+class ModeXmlParser : public ModeParser
+{
+public:
+ ModeXmlParser();
+ ~ModeXmlParser();
+public:
+ void getMode(const std::string& filepath, Mode& desc) throw(modeparser_error_e);
+ std::string getModeName(const std::string& filepath) throw(modeparser_error_e);
+};
+
+#endif /* __MODES_INTERNAL_SUPERVISOR_MODEXMLPARSER_H__ */
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/supervisor)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0)
+pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0 libxml-2.0)
INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
#==================================================================================================#
TARGET_LINK_LIBRARIES(${MODES_PLUGIN_TEST_NAME} ${test_pkgs_LIBRARIES} )
TARGET_LINK_LIBRARIES(${MODES_PLUGIN_TEST_NAME} -ldl )
#==================================================================================================#
+SET(MODEPARSER_TEST_NAME "modes-test-parser" )
+SET(MODEPARSER_TEST_SRCS "${CMAKE_SOURCE_DIR}/supervisor/mdss_Action.cpp"
+ "${CMAKE_SOURCE_DIR}/supervisor/mdss_Mode.cpp"
+ "${CMAKE_SOURCE_DIR}/supervisor/mdss_ModeXmlParser.cpp"
+ "modes_test_parser.cpp" )
+
+ADD_EXECUTABLE(${MODEPARSER_TEST_NAME} ${MODEPARSER_TEST_SRCS})
+TARGET_LINK_LIBRARIES(${MODEPARSER_TEST_NAME} ${test_pkgs_LIBRARIES})
+INSTALL(TARGETS ${MODEPARSER_TEST_NAME} DESTINATION ${BIN_INSTALL_DIR})
+#==================================================================================================#
SET(MODES_TEST_BASIC "modes-test-basic")
SET(MODES_TEST_BASMDS_SRCS "modes-test-basic.c")
--- /dev/null
+
+/*
+ * 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 <mdss.h>
+#include <mdss_ModeParser.h>
+
+#include <stdio.h>
+
+
+static void PrintModeProperies(Mode& mode)
+{
+ printf("\nMode : %s\n", mode.getName().c_str());
+ printf(" - TranspaMode : %s\n\n", mode.getTransparent().c_str());
+
+ // delete all items in actionList
+ ActionIterator it_begin, it_end;
+ mode.getActionListIterator(it_begin, it_end);
+
+ for (ActionIterator it = it_begin; it != it_end; ++it) {
+ Action& action = *it;
+ printf(" * Action : %s\n", action.getName().c_str());
+ printf(" - Achieve : %s\n", action.getAchieve().c_str());
+ printf(" - Changeable : %s\n", action.getChangeable().c_str());
+ printf(" - Content : %s\n", action.getContent().c_str());
+ }
+}
+
+// ModeParser test code
+static void ModeParserTest(const char *filepath)
+{
+ printf("\n **** ModeParserTest ****\n");
+ printf("Mode File : %s\n\n", filepath);
+
+ ModeParser *modeparser = ModeParser::Create();
+ if (modeparser) {
+ std::string modename;
+ try {
+ modename = modeparser->getModeName(filepath);
+ }
+ catch (modeparser_error_e err) {
+ if (err == MODEPARSER_ERROR_FILE_NOTEXIST)
+ printf("!!!mode file doesn't exist!!!\n");
+ else
+ printf("!!!Please check if mode file is correct!!!\n");
+ }
+ printf("Mode Name : %s\n\n", modename.c_str());
+
+ Mode mode;
+ try {
+ modeparser->getMode(filepath, mode);
+ }
+ catch (modeparser_error_e err) {
+ if (err == MODEPARSER_ERROR_FILE_NOTEXIST)
+ printf("!!!mode file doesn't exist!!!\n");
+ else
+ printf("!!!Please check if mode file is correct!!!\n");
+ }
+ PrintModeProperies(mode);
+
+ delete modeparser;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) return 0;
+
+ ModeParserTest(argv[1]);
+
+ return 0;
+}