--- /dev/null
+---
+Language: Cpp
+# BasedOnStyle: Google
+AccessModifierOffset: -2
+AlignAfterOpenBracket: DontAlign
+AlignConsecutiveMacros: false
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: false
+AllowAllConstructorInitializersOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: InlineOnly
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: Yes
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: false
+ AfterControlStatement: false
+ AfterEnum: false
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: false
+ AfterStruct: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: NonAssignment
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeColon
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeColon
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 100
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 6
+ContinuationIndentWidth: 6
+Cpp11BracedListStyle: true
+DeriveLineEnding: true
+DerivePointerAlignment: true
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^"modes\.h'
+ Priority: -1
+ SortPriority: 0
+ - Regex: '^<ext/.*\.h>'
+ Priority: 2
+ SortPriority: 0
+ - Regex: '^<.*\.h>'
+ Priority: 1
+ SortPriority: 0
+ - Regex: '^<.*'
+ Priority: 2
+ SortPriority: 0
+ - Regex: '.*'
+ Priority: 3
+ SortPriority: 0
+IncludeIsMainRegex: '([-_](test|unittest))?$'
+IncludeIsMainSourceRegex: ''
+IndentCaseLabels: false
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Never
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Right
+RawStringFormats:
+ - Language: Cpp
+ Delimiters:
+ - cc
+ - CC
+ - cpp
+ - Cpp
+ - CPP
+ - 'c++'
+ - 'C++'
+ CanonicalDelimiter: ''
+ BasedOnStyle: google
+ - Language: TextProto
+ Delimiters:
+ - pb
+ - PB
+ - proto
+ - PROTO
+ EnclosingFunctions:
+ - EqualsProto
+ - EquivToProto
+ - PARSE_PARTIAL_TEXT_PROTO
+ - PARSE_TEST_PROTO
+ - PARSE_TEXT_PROTO
+ - ParseTextOrDie
+ - ParseTextProtoOrDie
+ CanonicalDelimiter: ''
+ BasedOnStyle: google
+ReflowComments: true
+SortIncludes: true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles: false
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+Standard: Auto
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 4
+UseCRLF: false
+UseTab: Never
+...
+++ /dev/null
-/*
- * 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.
- */
-#include "modes.h"
-
-#include <stdlib.h>
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-#include "common/dbus_def.h"
-#include "mdsc_subscribe.h"
-
-API modes_h modes_connect()
-{
- mdsDbus *proxy;
- GError *gdbusErr = NULL;
-
- modes_h handle = calloc(1, sizeof(struct mds_handle));
- if (NULL == handle) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- if (pthread_mutex_init(&handle->noti_mutex, NULL)) {
- ERR("pthread_mutex_init() Fail(%d)", errno);
- free(handle);
- return NULL;
- }
-
- proxy = mds_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE, MODES_DBUS_INTERFACE, MODES_DBUS_OBJPATH, NULL, &gdbusErr);
- if (NULL == proxy) {
- ERR("mds_dbus_proxy_new_for_bus_sync() Fail(%s)", gdbusErr ? gdbusErr->message : "unknown");
- g_error_free(gdbusErr);
- free(handle);
- return NULL;
- }
- handle->conn = proxy;
-
- return handle;
-}
-
-API void modes_disconnect(modes_h handle)
-{
- RET_IF(NULL == handle);
-
- mdsc_subscription_disconnect(handle);
- pthread_mutex_destroy(&handle->noti_mutex);
- g_object_unref(handle->conn);
- handle->conn = NULL;
-
- free(handle);
-}
#pragma once
#include <pthread.h>
-#include "common/log.h"
+
#include "common/dbus.h"
#include "common/definitions.h"
+#include "common/log.h"
struct mds_handle {
- mdsDbus *conn;
- gulong noti_dbus_ID;
- GList *noti_cb_list;
- pthread_mutex_t noti_mutex;
+ mdsDbus *conn;
+ gulong noti_dbus_ID;
+ GList *noti_cb_list;
+ pthread_mutex_t noti_mutex;
};
*/
#include "modes.h"
-#include <stdlib.h>
#include <glib.h>
-#include "mdsc.h"
+#include <stdlib.h>
+
#include "common/dbus.h"
#include "common/dbus_def.h"
+#include "mdsc.h"
struct mds_action_handle {
- char *id;
- char *rule;
- char *value;
- bool added;
+ char *id;
+ char *rule;
+ char *value;
+ bool added;
};
struct mds_mode_handle {
- char *id;
- char *name;
- modes_type_mode_e type;
- bool hidden;
- GList *action_list;
+ char *id;
+ char *name;
+ modes_type_mode_e type;
+ bool hidden;
+ GList *action_list;
};
static int _mdsc_dbus_add_mode_sync(mdsDbus *mdsc_dbus, GVariant *mode_data)
{
- int result = MODES_ERROR_NONE;
- gboolean ret;
- GError *error = NULL;
+ int result = MODES_ERROR_NONE;
+ gboolean ret;
+ GError *error = NULL;
- RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
- ret = mds_dbus_call_add_mode_sync(mdsc_dbus, mode_data, &result, NULL, &error);
- if (FALSE == ret) {
- ERR("mds_dbus_call_add_mode_sync() Fail(%s)", error ? error->message : "unknown");
- g_error_free(error);
- return MODES_ERROR_SYSTEM;
- }
+ ret = mds_dbus_call_add_mode_sync(mdsc_dbus, mode_data, &result, NULL, &error);
+ if (FALSE == ret) {
+ ERR("mds_dbus_call_add_mode_sync() Fail(%s)", error ? error->message : "unknown");
+ g_error_free(error);
+ return MODES_ERROR_SYSTEM;
+ }
- return result;
+ return result;
}
static int _mdsc_dbus_remove_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
{
- int result = MODES_ERROR_NONE;
- gboolean ret;
- GError *error = NULL;
+ int result = MODES_ERROR_NONE;
+ gboolean ret;
+ GError *error = NULL;
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- ret = mds_dbus_call_remove_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
- if (FALSE == ret) {
- ERR("mds_dbus_call_remove_mode_sync() Fail(%s)", error ? error->message : "unknown");
- g_error_free(error);
- return MODES_ERROR_SYSTEM;
- }
+ ret = mds_dbus_call_remove_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+ if (FALSE == ret) {
+ ERR("mds_dbus_call_remove_mode_sync() Fail(%s)", error ? error->message : "unknown");
+ g_error_free(error);
+ return MODES_ERROR_SYSTEM;
+ }
- return result;
+ return result;
}
static void _mdsc_free_action(gpointer data)
{
- RET_IF(NULL == data);
+ RET_IF(NULL == data);
- struct mds_action_handle *action_data = data;
+ struct mds_action_handle *action_data = data;
- free(action_data->id);
- free(action_data->rule);
- free(action_data->value);
- free(action_data);
+ free(action_data->id);
+ free(action_data->rule);
+ free(action_data->value);
+ free(action_data);
}
-static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
+static GVariant *_mdsc_create_mode_data(modes_mode_h mode)
{
- RETV_IF(NULL == mode, NULL);
-
- GVariantBuilder *action_builder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_ACTION_LIST_SIG));
- GList *it = g_list_first(mode->action_list);
-
- while (NULL != it) {
- struct mds_action_handle *action_data = (struct mds_action_handle *)it->data;
- g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG, MODES_DBUS_SAFE_STR(action_data->id),
- MODES_DBUS_SAFE_STR(action_data->rule), MODES_DBUS_SAFE_STR(action_data->value));
- it = g_list_next(it);
- }
-
- GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
- 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;
+ RETV_IF(NULL == mode, NULL);
+
+ GVariantBuilder *action_builder =
+ g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_ACTION_LIST_SIG));
+ GList *it = g_list_first(mode->action_list);
+
+ while (NULL != it) {
+ struct mds_action_handle *action_data = (struct mds_action_handle *)it->data;
+ g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG,
+ MODES_DBUS_SAFE_STR(action_data->id), MODES_DBUS_SAFE_STR(action_data->rule),
+ MODES_DBUS_SAFE_STR(action_data->value));
+ it = g_list_next(it);
+ }
+
+ GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
+ 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 *id, const char *name, modes_type_mode_e type)
{
- struct mds_mode_handle *mode;
+ struct mds_mode_handle *mode;
- RETV_IF(NULL == id, NULL);
+ RETV_IF(NULL == id, NULL);
- mode = malloc(sizeof(struct mds_mode_handle));
- RETV_IF(NULL == mode, 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;
- mode->action_list = NULL;
+ mode->id = strdup(id);
+ mode->name = strdup(name);
+ mode->type = type;
+ mode->hidden = false;
+ mode->action_list = NULL;
- return mode;
+ return mode;
}
API int modes_set_hidden(modes_mode_h mode, bool hidden)
{
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- mode->hidden = hidden;
+ mode->hidden = hidden;
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
API modes_action_h modes_create_action(const char *name, const char *value)
{
- struct mds_action_handle *action;
+ struct mds_action_handle *action;
- RETV_IF(NULL == name, NULL);
- RETV_IF(NULL == value, NULL);
+ RETV_IF(NULL == name, NULL);
+ RETV_IF(NULL == value, NULL);
- action = malloc(sizeof(struct mds_action_handle));
- RETV_IF(NULL == action, NULL);
+ action = malloc(sizeof(struct mds_action_handle));
+ RETV_IF(NULL == action, NULL);
- action->rule = strdup(name);
- action->value = strdup(value);
- action->id = NULL;
- action->added = false;
+ action->rule = strdup(name);
+ action->value = strdup(value);
+ action->id = NULL;
+ action->added = false;
- return action;
+ return action;
}
API void modes_free_action(modes_action_h action)
{
- RET_IF(NULL == action);
+ RET_IF(NULL == action);
- if (action->added)
- return;
+ if (action->added)
+ return;
- _mdsc_free_action(action);
+ _mdsc_free_action(action);
}
API int modes_mode_insert_action(modes_mode_h mode, modes_action_h action)
{
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
- mode->action_list = g_list_append(mode->action_list, action);
- action->added = true;
+ mode->action_list = g_list_append(mode->action_list, action);
+ action->added = true;
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
API int modes_add_mode(modes_h handle, modes_mode_h mode)
{
- int ret;
+ int ret;
- RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- GVariant *mode_data = _mdsc_create_mode_data(mode);
- RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
+ GVariant *mode_data = _mdsc_create_mode_data(mode);
+ RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
- ret = _mdsc_dbus_add_mode_sync(handle->conn, mode_data);
- if (MODES_ERROR_NONE != ret) {
- ERR("_mdsc_dbus_add_mode_sync() Fail(%d)", ret);
- return ret;
- }
+ ret = _mdsc_dbus_add_mode_sync(handle->conn, mode_data);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("_mdsc_dbus_add_mode_sync() Fail(%d)", ret);
+ return ret;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
API int modes_remove_mode(modes_h handle, const char *id)
{
- int ret;
- RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
+ int ret;
+ RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
- 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;
- }
+ 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;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
API void modes_free_mode(modes_mode_h mode)
{
- RET_IF(NULL == mode);
+ RET_IF(NULL == mode);
- free(mode->id);
- free(mode->name);
+ free(mode->id);
+ free(mode->name);
- g_list_free_full(mode->action_list, _mdsc_free_action);
+ g_list_free_full(mode->action_list, _mdsc_free_action);
- free(mode);
+ free(mode);
}
-
#include "modes.h"
#include <glib.h>
-#include "mdsc.h"
+
#include "common/dbus.h"
+#include "mdsc.h"
static int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
{
- int result = MODES_ERROR_NONE;
- gboolean ret;
- GError *error = NULL;
+ int result = MODES_ERROR_NONE;
+ gboolean ret;
+ GError *error = NULL;
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- ret = mds_dbus_call_apply_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
- if (FALSE == ret) {
- ERR("mds_dbus_call_apply_mode_sync() Fail(%s)", error ? error->message : "unknown");
- g_error_free(error);
- return MODES_ERROR_SYSTEM;
- }
+ ret = mds_dbus_call_apply_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+ if (FALSE == ret) {
+ ERR("mds_dbus_call_apply_mode_sync() Fail(%s)", error ? error->message : "unknown");
+ g_error_free(error);
+ return MODES_ERROR_SYSTEM;
+ }
- return result;
+ return result;
}
API int modes_apply_mode(modes_h handle, const char *id)
{
- int ret;
- RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
+ int ret;
+ RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
- 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;
- }
+ 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;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
--- /dev/null
+/*
+ * 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.
+ */
+#include "modes.h"
+
+#include <glib.h>
+#include <stdlib.h>
+
+#include "common/dbus.h"
+#include "common/dbus_def.h"
+#include "mdsc.h"
+#include "mdsc_subscribe.h"
+
+API modes_h modes_connect()
+{
+ mdsDbus *proxy;
+ GError *gdbusErr = NULL;
+
+ modes_h handle = calloc(1, sizeof(struct mds_handle));
+ if (NULL == handle) {
+ ERR("calloc() Fail(%d)", errno);
+ return NULL;
+ }
+
+ if (pthread_mutex_init(&handle->noti_mutex, NULL)) {
+ ERR("pthread_mutex_init() Fail(%d)", errno);
+ free(handle);
+ return NULL;
+ }
+
+ proxy = mds_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
+ MODES_DBUS_INTERFACE, MODES_DBUS_OBJPATH, NULL, &gdbusErr);
+ if (NULL == proxy) {
+ ERR("mds_dbus_proxy_new_for_bus_sync() Fail(%s)", gdbusErr ? gdbusErr->message : "unknown");
+ g_error_free(gdbusErr);
+ free(handle);
+ return NULL;
+ }
+ handle->conn = proxy;
+
+ return handle;
+}
+
+API void modes_disconnect(modes_h handle)
+{
+ RET_IF(NULL == handle);
+
+ mdsc_subscription_disconnect(handle);
+ pthread_mutex_destroy(&handle->noti_mutex);
+ g_object_unref(handle->conn);
+ handle->conn = NULL;
+
+ free(handle);
+}
#include "modes.h"
#include <glib.h>
-#include "mdsc.h"
+
#include "common/dbus.h"
+#include "mdsc.h"
static int _mdsc_dbus_can_apply_sync(mdsDbus *mdsc_dbus, const char *mode)
{
- int result = MODES_ERROR_NONE;
- gboolean ret;
- GError *error = NULL;
+ int result = MODES_ERROR_NONE;
+ gboolean ret;
+ GError *error = NULL;
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- ret = mds_dbus_call_can_apply_sync(mdsc_dbus, mode, &result, NULL, &error);
- if (FALSE == ret) {
- ERR("mds_dbus_call_can_apply_sync() Fail(%s)", error ? error->message : "unknown");
- g_error_free(error);
- return MODES_ERROR_SYSTEM;
- }
+ ret = mds_dbus_call_can_apply_sync(mdsc_dbus, mode, &result, NULL, &error);
+ if (FALSE == ret) {
+ ERR("mds_dbus_call_can_apply_sync() Fail(%s)", error ? error->message : "unknown");
+ g_error_free(error);
+ return MODES_ERROR_SYSTEM;
+ }
- return result;
+ return result;
}
API int modes_can_apply(modes_h handle, const char *id)
{
- int ret;
- RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
+ int ret;
+ RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
- 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;
- }
+ 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;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
* limitations under the License.
*/
#include "modes.h"
-#include <stdlib.h>
+
#include <glib.h>
-#include "mdsc.h"
+#include <stdlib.h>
+
#include "common/dbus.h"
#include "common/dbus_def.h"
+#include "mdsc.h"
struct mds_list_data_handle {
- char *id;
- char *name;
- modes_type_mode_e type;
- int state;
+ char *id;
+ char *name;
+ modes_type_mode_e type;
+ int state;
};
static void _free_mode(gpointer data)
{
- mode_list_data_h mode = data;
- free(mode->id);
- free(mode->name);
- free(mode);
+ mode_list_data_h mode = data;
+ free(mode->id);
+ free(mode->name);
+ free(mode);
}
-static GList* _get_mode_list(GVariant *in_data, int *result)
+static GList *_get_mode_list(GVariant *in_data, int *result)
{
- gchar *mode_id;
- 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_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(%d)", errno);
- free(mode_id);
- free(mode_name);
- g_list_free_full(mode_list, _free_mode);
- mode_list = NULL;
- *result = MODES_ERROR_OUT_OF_MEMORY;
- break;
- }
- mode->id = strdup(mode_id);
- mode->name = strdup(mode_name);
- mode->state = state;
- mode->type = type;
- mode_list = g_list_append(mode_list, mode);
- }
- g_variant_iter_free(iter);
- g_variant_unref(in_data);
-
- return mode_list;
+ gchar *mode_id;
+ 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_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(%d)", errno);
+ free(mode_id);
+ free(mode_name);
+ g_list_free_full(mode_list, _free_mode);
+ mode_list = NULL;
+ *result = MODES_ERROR_OUT_OF_MEMORY;
+ break;
+ }
+ mode->id = strdup(mode_id);
+ mode->name = strdup(mode_name);
+ mode->state = state;
+ mode->type = type;
+ mode_list = g_list_append(mode_list, mode);
+ }
+ g_variant_iter_free(iter);
+ g_variant_unref(in_data);
+
+ return mode_list;
}
static int _mdsc_dbus_get_modes_sync(mdsDbus *mdsc_dbus, GList **list)
{
- gboolean ret;
- GError *error = NULL;
- int result = MODES_ERROR_NONE;
- GVariant *mode_list = NULL;
+ gboolean ret;
+ GError *error = NULL;
+ int result = MODES_ERROR_NONE;
+ GVariant *mode_list = NULL;
- RETV_IF(NULL == list, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list, MODES_ERROR_INVALID_PARAMETER);
- ret = mds_dbus_call_get_modes_sync(mdsc_dbus, &mode_list, &result, NULL, &error);
- if (FALSE == ret) {
- ERR("mds_dbus_call_get_modes_sync() Fail(%s)", error ? error->message : "unknown");
- g_error_free(error);
- return MODES_ERROR_SYSTEM;
- }
+ ret = mds_dbus_call_get_modes_sync(mdsc_dbus, &mode_list, &result, NULL, &error);
+ if (FALSE == ret) {
+ ERR("mds_dbus_call_get_modes_sync() Fail(%s)", error ? error->message : "unknown");
+ g_error_free(error);
+ return MODES_ERROR_SYSTEM;
+ }
- *list = _get_mode_list(mode_list, &result);
+ *list = _get_mode_list(mode_list, &result);
- return result;
+ return result;
}
API int modes_get_modes(modes_h handle, GList **list)
{
- int ret;
+ int ret;
- RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == list, MODES_ERROR_INVALID_PARAMETER);
- ret = _mdsc_dbus_get_modes_sync(handle->conn, list);
- if (MODES_ERROR_NONE != ret) {
- ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
- return ret;
- }
+ ret = _mdsc_dbus_get_modes_sync(handle->conn, list);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
+ return ret;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
API void modes_free_modes(GList *list)
{
- g_list_free_full(list, _free_mode);
+ g_list_free_full(list, _free_mode);
}
-API const char* modes_get_mode_id(mode_list_data_h data)
+API const char *modes_get_mode_id(mode_list_data_h data)
{
- RETV_IF(NULL == data, NULL);
- return data->id;
+ RETV_IF(NULL == data, NULL);
+ return data->id;
}
-API const char* modes_get_mode_name(mode_list_data_h data)
+API const char *modes_get_mode_name(mode_list_data_h data)
{
- RETV_IF(NULL == data, NULL);
- return data->name;
+ 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;
+ 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;
+ RETV_IF(NULL == data, MODES_ERROR_INVALID_PARAMETER);
+ return data->state;
}
* limitations under the License.
*/
#include "modes.h"
+
#include "mdsc_subscribe.h"
-#include <stdlib.h>
#include <glib.h>
-#include "mdsc.h"
+#include <stdlib.h>
+
#include "common/dbus.h"
+#include "mdsc.h"
struct mds_noti_data {
- modes_noti_fn cb;
- void *user_data;
+ modes_noti_fn cb;
+ void *user_data;
};
static void _mutex_lock(pthread_mutex_t *mutex)
{
- int ret = pthread_mutex_lock(mutex);
- if (0 != ret)
- ERR("pthread_mutex_lock() Fail(%d)", errno);
+ int ret = pthread_mutex_lock(mutex);
+ if (0 != ret)
+ ERR("pthread_mutex_lock() Fail(%d)", errno);
}
static void _mutex_unlock(pthread_mutex_t *mutex)
{
- int ret = pthread_mutex_unlock(mutex);
- if (0 != ret)
- ERR("pthread_mutex_unlock() Fail(%d)", errno);
+ int ret = pthread_mutex_unlock(mutex);
+ if (0 != ret)
+ ERR("pthread_mutex_unlock() Fail(%d)", errno);
}
static void _on_changed_mode(mdsDbus *mdsc_dbus, const char *mode, int state, gpointer user_data)
{
- int i;
- GList *it;
- modes_h handle = user_data;
-
- RET_IF(NULL == handle);
-
- _mutex_lock(&handle->noti_mutex);
- int length = g_list_length(handle->noti_cb_list);
- struct mds_noti_data cb_list[length];
-
- for (i = 0, it = handle->noti_cb_list; it != NULL; it = g_list_next(it), i++) {
- modes_noti_ID data = it->data;
- if (data) {
- cb_list[i].cb = data->cb;
- cb_list[i].user_data = data->user_data;
- }
- }
- _mutex_unlock(&handle->noti_mutex);
-
- length = i;
- for (i = 0; i < length; i++) {
- if (cb_list[i].cb)
- cb_list[i].cb(mode, state, cb_list[i].user_data);
- }
+ int i;
+ GList *it;
+ modes_h handle = user_data;
+
+ RET_IF(NULL == handle);
+
+ _mutex_lock(&handle->noti_mutex);
+ int length = g_list_length(handle->noti_cb_list);
+ struct mds_noti_data cb_list[length];
+
+ for (i = 0, it = handle->noti_cb_list; it != NULL; it = g_list_next(it), i++) {
+ modes_noti_ID data = it->data;
+ if (data) {
+ cb_list[i].cb = data->cb;
+ cb_list[i].user_data = data->user_data;
+ }
+ }
+ _mutex_unlock(&handle->noti_mutex);
+
+ length = i;
+ for (i = 0; i < length; i++) {
+ if (cb_list[i].cb)
+ cb_list[i].cb(mode, state, cb_list[i].user_data);
+ }
}
API modes_noti_ID modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_data)
{
- RETV_IF(NULL == handle, NULL);
- RETV_IF(NULL == handle->conn, NULL);
+ RETV_IF(NULL == handle, NULL);
+ RETV_IF(NULL == handle->conn, NULL);
- modes_noti_ID data = malloc(sizeof(struct mds_noti_data));
- if (NULL == data) {
- ERR("malloc() Fail(%d)", errno);
- return NULL;
- }
+ modes_noti_ID data = malloc(sizeof(struct mds_noti_data));
+ if (NULL == data) {
+ ERR("malloc() Fail(%d)", errno);
+ return NULL;
+ }
- data->cb = cb;
- data->user_data = user_data;
+ data->cb = cb;
+ data->user_data = user_data;
- if (NULL == handle->noti_cb_list)
- handle->noti_dbus_ID = g_signal_connect(handle->conn,
- "changed-mode",
- G_CALLBACK(_on_changed_mode),
- handle);
+ if (NULL == handle->noti_cb_list)
+ handle->noti_dbus_ID =
+ g_signal_connect(handle->conn, "changed-mode", G_CALLBACK(_on_changed_mode), handle);
- _mutex_lock(&handle->noti_mutex);
- handle->noti_cb_list = g_list_append(handle->noti_cb_list, data);
- _mutex_unlock(&handle->noti_mutex);
+ _mutex_lock(&handle->noti_mutex);
+ handle->noti_cb_list = g_list_append(handle->noti_cb_list, data);
+ _mutex_unlock(&handle->noti_mutex);
- return data;
+ return data;
}
API void modes_unsubscribe_mode_changes(modes_h handle, modes_noti_ID id)
{
- RET_IF(NULL == handle);
- RET_IF(NULL == handle->conn);
-
- _mutex_lock(&handle->noti_mutex);
- handle->noti_cb_list = g_list_remove(handle->noti_cb_list, id);
- free(id);
- if (NULL == handle->noti_cb_list) {
- g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
- handle->noti_dbus_ID = 0;
- }
- _mutex_unlock(&handle->noti_mutex);
+ RET_IF(NULL == handle);
+ RET_IF(NULL == handle->conn);
+
+ _mutex_lock(&handle->noti_mutex);
+ handle->noti_cb_list = g_list_remove(handle->noti_cb_list, id);
+ free(id);
+ if (NULL == handle->noti_cb_list) {
+ g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
+ handle->noti_dbus_ID = 0;
+ }
+ _mutex_unlock(&handle->noti_mutex);
}
void mdsc_subscription_disconnect(modes_h handle)
{
- RET_IF(NULL == handle);
-
- _mutex_lock(&handle->noti_mutex);
- if (handle->noti_cb_list) {
- g_list_free_full(handle->noti_cb_list, free);
- handle->noti_cb_list = NULL;
- g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
- handle->noti_dbus_ID = 0;
- }
- _mutex_unlock(&handle->noti_mutex);
+ RET_IF(NULL == handle);
+
+ _mutex_lock(&handle->noti_mutex);
+ if (handle->noti_cb_list) {
+ g_list_free_full(handle->noti_cb_list, free);
+ handle->noti_cb_list = NULL;
+ g_signal_handler_disconnect(handle->conn, handle->noti_dbus_ID);
+ handle->noti_dbus_ID = 0;
+ }
+ _mutex_unlock(&handle->noti_mutex);
}
#include "modes.h"
#include <glib.h>
-#include "mdsc.h"
+
#include "common/dbus.h"
+#include "mdsc.h"
static int _mdsc_dbus_undo_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
{
- gboolean ret;
- GError *error = NULL;
- int result = MODES_ERROR_NONE;
+ gboolean ret;
+ GError *error = NULL;
+ int result = MODES_ERROR_NONE;
- RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
- ret = mds_dbus_call_undo_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
- if (FALSE == ret) {
- ERR("mds_dbus_call_undo_mode_sync() Fail(%s)", error ? error->message : "unknown");
- g_error_free(error);
- return MODES_ERROR_SYSTEM;
- }
+ ret = mds_dbus_call_undo_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+ if (FALSE == ret) {
+ ERR("mds_dbus_call_undo_mode_sync() Fail(%s)", error ? error->message : "unknown");
+ g_error_free(error);
+ return MODES_ERROR_SYSTEM;
+ }
- return result;
+ return result;
}
API int modes_undo_mode(modes_h handle, const char *name)
{
- int ret;
+ int ret;
- RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+ RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
- ret = _mdsc_dbus_undo_mode_sync(handle->conn, name);
- if (MODES_ERROR_NONE != ret) {
- ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
- return ret;
- }
+ ret = _mdsc_dbus_undo_mode_sync(handle->conn, name);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
+ return ret;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
#define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
#endif /* MDS_STDOUT */
-
#ifdef MDS_SUPERVISOR
#define DBG(fmt, arg...) _DBG(MDS_LOG_BROWN "<Daemon>" MDS_LOG_END fmt, ##arg)
#define INFO(fmt, arg...) _INFO(MDS_LOG_BLUE "<Daemon>" MDS_LOG_END fmt, ##arg)
#define ERR(fmt, arg...) _ERR(fmt, ##arg)
#endif /* MDS_SUPERVISOR */
-#define RET_IF(expr) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- return; \
- } \
- } while (0)
+#define RET_IF(expr) \
+ do { \
+ if (expr) { \
+ ERR("(%s)", #expr); \
+ return; \
+ } \
+ } while (0)
-#define RETV_IF(expr, val) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- return (val); \
- } \
- } while (0)
+#define RETV_IF(expr, val) \
+ do { \
+ if (expr) { \
+ ERR("(%s)", #expr); \
+ return (val); \
+ } \
+ } while (0)
#define RETM_IF(expr, fmt, arg...) \
- do { \
- if (expr) { \
- ERR(fmt, ##arg); \
- return; \
- } \
- } while (0)
+ do { \
+ if (expr) { \
+ ERR(fmt, ##arg); \
+ return; \
+ } \
+ } while (0)
#define RETVM_IF(expr, val, fmt, arg...) \
- do { \
- if (expr) { \
- ERR(fmt, ##arg); \
- return (val); \
- } \
- } while (0)
+ do { \
+ if (expr) { \
+ ERR(fmt, ##arg); \
+ return (val); \
+ } \
+ } while (0)
-#define ERR_IF(expr) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- } \
- } while (0)
+#define ERR_IF(expr) \
+ do { \
+ if (expr) { \
+ ERR("(%s)", #expr); \
+ } \
+ } while (0)
#define WARN_IF(expr, fmt, arg...) \
- do { \
- if (expr) { \
- WARN(fmt, ##arg); \
- } \
- } while (0)
+ do { \
+ if (expr) { \
+ WARN(fmt, ##arg); \
+ } \
+ } while (0)
*/
#pragma once
-#include "modes_errors.h"
#include "definitions.h"
#include "log.h"
+#include "modes_errors.h"
*/
#pragma once
-#include <string>
#include <modes_errors.h>
-namespace ModeSupervisorNamespace {
-
- typedef void (*valueChangedCB)(void *userData);
-
- class PluginAction {
- public:
- PluginAction(const std::string &actionKey)
- : key(actionKey)
- {
- }
- virtual ~PluginAction() = default;
-
- std::string getKey()
- {
- return key;
- }
-
- //If it is true, the Action is ignored.
- //It is possible to get the old value in this procedure
- //because the set() is immediately called after this function
- virtual bool IsCurrentValue(int val)
- {
- return false;
- }
- virtual bool IsCurrentValue(double val)
- {
- return false;
- }
- virtual bool IsCurrentValue(bool val)
- {
- return false;
- }
- virtual bool IsCurrentValue(const std::string &val)
- {
- return false;
- }
+#include <string>
- virtual int set(int val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual int set(double val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual int set(bool val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual int set(const std::string &val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
+namespace ModeSupervisorNamespace {
- virtual void undo()
- {
- }
- virtual std::string getUndoInfo()
- {
- return std::string();
- }
- virtual int setUndoInfo(const std::string &info)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual int setChangedCallback(valueChangedCB callback, void *userData)
- {
- // The callback should be called when the value is changed(Not Same).
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual void unSetChangedCallback(valueChangedCB callback)
- {
- }
- protected:
- const std::string key;
- };
-}
+typedef void (*valueChangedCB)(void *userData);
+
+class PluginAction {
+ public:
+ PluginAction(const std::string &actionKey) : key(actionKey) {}
+ virtual ~PluginAction() = default;
+
+ std::string getKey() { return key; }
+
+ // If it is true, the Action is ignored.
+ // It is possible to get the old value in this procedure
+ // because the set() is immediately called after this function
+ virtual bool IsCurrentValue(int val) { return false; }
+ virtual bool IsCurrentValue(double val) { return false; }
+ virtual bool IsCurrentValue(bool val) { return false; }
+ virtual bool IsCurrentValue(const std::string &val) { return false; }
+
+ virtual int set(int val) { return MODES_ERROR_NOT_SUPPORTED; }
+ virtual int set(double val) { return MODES_ERROR_NOT_SUPPORTED; }
+ virtual int set(bool val) { return MODES_ERROR_NOT_SUPPORTED; }
+ virtual int set(const std::string &val) { return MODES_ERROR_NOT_SUPPORTED; }
+
+ virtual void undo() {}
+ virtual std::string getUndoInfo() { return std::string(); }
+ virtual int setUndoInfo(const std::string &info) { return MODES_ERROR_NOT_SUPPORTED; }
+ virtual int setChangedCallback(valueChangedCB callback, void *userData)
+ {
+ // The callback should be called when the value is changed(Not Same).
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual void unSetChangedCallback(valueChangedCB callback) {}
+
+ protected:
+ const std::string key;
+};
+} // namespace ModeSupervisorNamespace
*/
#pragma once
-#include <string>
-#include <modes_errors.h>
#include <ModesPIAction.h>
+#include <modes_errors.h>
+
+#include <string>
namespace ModeSupervisorNamespace {
- class Plugin {
- public:
- Plugin() = default;
- virtual ~Plugin() = default;
-
- void setName(const std::string &pluginName)
- {
- name = pluginName;
- }
-
- std::string getName()
- {
- return name;
- }
-
- //It should returns dynamic allocated instance of PluginAction
- virtual PluginAction* newAction(const std::string &key) = 0;
-
- //Using destructor of PluginAction without overriding is recommended
- virtual void deleteAction(PluginAction *piAction)
- {
- //release resources of piAction
- delete piAction;
- }
- private:
- std::string name;
- };
-
- typedef Plugin* (*createFunc)(void);
- typedef void (*destroyFunc)(Plugin*);
-}
+class Plugin {
+ public:
+ Plugin() = default;
+ virtual ~Plugin() = default;
+
+ void setName(const std::string &pluginName) { name = pluginName; }
+
+ std::string getName() { return name; }
+
+ // It should returns dynamic allocated instance of PluginAction
+ virtual PluginAction *newAction(const std::string &key) = 0;
+
+ // Using destructor of PluginAction without overriding is recommended
+ virtual void deleteAction(PluginAction *piAction)
+ {
+ // release resources of piAction
+ delete piAction;
+ }
+
+ private:
+ std::string name;
+};
+
+typedef Plugin *(*createFunc)(void);
+typedef void (*destroyFunc)(Plugin *);
+} // namespace ModeSupervisorNamespace
#endif
#include <glib.h>
-#include <modes_types.h>
#include <modes_errors.h>
+#include <modes_types.h>
/**
* @file modes.h
*/
int modes_undo_mode(modes_h handle, const char *id);
-
/**
* @brief Create Mode.
* @details Calls this function to create mode.
* @param[in] GList for mode list
* @return mode ID
*/
-const char* modes_get_mode_id(mode_list_data_h data);
+const char *modes_get_mode_id(mode_list_data_h data);
/**
* @brief Get name of mode from GList data
* @param[in] GList for mode list to free
* @return mode name
*/
-const char* modes_get_mode_name(mode_list_data_h data);
+const char *modes_get_mode_name(mode_list_data_h data);
/**
* @brief Get type of mode from GList data
}
#endif
-#endif //__MODE_SUPERVISOR_H__
+#endif //__MODE_SUPERVISOR_H__
#ifndef __MODE_SUPERVISOR_CONSTANTS_H__
#define __MODE_SUPERVISOR_CONSTANTS_H__
-
/**
* @file modes_constants.h
*/
-
/**
* @addtogroup CAPI_MODE_SUPERVISOR_COMMON_MODULE
* @{
*/
-
/**
* @brief Definition for temporary.
* @since_tizen 3.0
*/
#define MODES_DEFINITION NULL
-
-
/**
* @brief Enumeration for mode type.
* @since_tizen 6.0
*/
typedef enum {
- MODES_TYPE_MODE_NORMAL = 0, /**< Indicates normal mode that is allowed to undo and apply other mode */
- MODES_TYPE_MODE_ONESHOT = (1 << 0), /**< Indicates one-shot mode that has no management(undo) */
+ MODES_TYPE_MODE_NORMAL =
+ 0, /**< Indicates normal mode that is allowed to undo and apply other mode */
+ MODES_TYPE_MODE_ONESHOT = (1 << 0), /**< Indicates one-shot mode that has no management(undo) */
} modes_type_mode_e;
-
/**
* @brief Enumeration for restriction.
* @since_tizen 6.0
*/
-typedef enum {
- MODES_RESTRICTION_NONE,
- MODES_RESTRICTION_LOCK
-} modes_restriction_e;
+typedef enum { MODES_RESTRICTION_NONE, MODES_RESTRICTION_LOCK } modes_restriction_e;
/**
* @}
*/
-
-#endif //__MODE_SUPERVISOR_CONSTANTS_H__
+#endif //__MODE_SUPERVISOR_CONSTANTS_H__
#define __MODE_SUPERVISOR_ERRORS_H__
#include <tizen.h>
-#define TIZEN_ERROR_MODES -0x03020000
+#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 6.0
- * @{
- */
+/**
+ * @ingroup CAPI_MODE_SUPERVISOR_MODULE
+ * @brief Enumeration for Modes error code.
+ * @since_tizen 6.0
+ * @{
+ */
typedef enum {
- MODES_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- MODES_ERROR_ALREADY = TIZEN_ERROR_ALREADY_IN_PROGRESS, /** Operation already in progress */
- MODES_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */
- MODES_ERROR_TIMEOUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */
- MODES_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
- MODES_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
- MODES_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- MODES_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
- MODES_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- MODES_ERROR_SYSTEM = TIZEN_ERROR_MODES | 0x03, /**< System errors */
- MODES_ERROR_CONFLICT = TIZEN_ERROR_MODES | 0x04, /**< Conflict */
+ MODES_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
+ MODES_ERROR_ALREADY = TIZEN_ERROR_ALREADY_IN_PROGRESS, /** Operation already in progress */
+ MODES_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */
+ MODES_ERROR_TIMEOUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */
+ MODES_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+ MODES_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
+ MODES_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ MODES_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ MODES_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ MODES_ERROR_SYSTEM = TIZEN_ERROR_MODES | 0x03, /**< System errors */
+ MODES_ERROR_CONFLICT = TIZEN_ERROR_MODES | 0x04, /**< Conflict */
} modes_error_e;
/*
* MODES_ERROR_CONFLICT - 50462716
*/
-
/**
* @}
*/
-#endif //__MODE_SUPERVISOR_ERRORS_H__
+#endif //__MODE_SUPERVISOR_ERRORS_H__
#ifndef __MODE_SUPERVISOR_TYPES_H__
#define __MODE_SUPERVISOR_TYPES_H__
-
-#include <tizen_type.h> //tizen_type.h includes stdbool.h
#include <modes_constants.h>
-
+#include <tizen_type.h> //tizen_type.h includes stdbool.h
/**
* @file modes_types.h
*/
-
/**
* @ingroup CAPI_MODE_SUPERVISOR_MODULE
* @defgroup CAPI_MODE_SUPERVISOR_COMMON_MODULE Common
*/
typedef struct mds_mode_handle* modes_mode_h;
-
/**
* @brief The mds_action_handle type values action handle.
* @details @a modes_action_h is an opaque data structure.
* @see modes_subscribe_mode_changes()
* @see modes_unsubscribe_mode_changes()
*/
-typedef int (*modes_noti_fn) (const char *mode_name, int state, void *user_data);
+typedef int (*modes_noti_fn)(const char* mode_name, int state, void* user_data);
/**
* @}
*/
-
-#endif //__MODE_SUPERVISOR_TYPES_H__
+#endif //__MODE_SUPERVISOR_TYPES_H__
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "modes_errors.h"
-#include "ModesPlugin.h"
#include "ModesPIAction.h"
-#include "common/log.h"
-#include "common/definitions.h"
+#include "ModesPlugin.h"
#include "TestPluginAction.h"
+#include "common/definitions.h"
+#include "common/log.h"
+#include "modes_errors.h"
MODES_NAMESPACE_USE;
class TestPlugin : public Plugin {
-private:
-
-public:
- TestPlugin();
- ~TestPlugin() override = default;
+ public:
+ TestPlugin();
+ ~TestPlugin() override = default;
- PluginAction* newAction(const std::string &key) override;
- void deleteAction(PluginAction *piAction) override;
+ PluginAction *newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
};
-extern "C" API Plugin* objectCreate(void)
+extern "C" API Plugin *objectCreate(void)
{
- return new TestPlugin();
+ return new TestPlugin();
}
extern "C" API void objectDelete(Plugin *plugin)
{
- delete plugin;
+ delete plugin;
}
TestPlugin::TestPlugin()
{
- setName("test");
+ setName("test");
}
-PluginAction* TestPlugin::newAction(const std::string &key)
+PluginAction *TestPlugin::newAction(const std::string &key)
{
- return new TestPluginAction(key);
+ return new TestPluginAction(key);
}
void TestPlugin::deleteAction(PluginAction *piAction)
{
- //release resource of piAction
- //Using destructor of PluginAction without overriding is recommended
- delete piAction;
+ // release resource of piAction
+ // Using destructor of PluginAction without overriding is recommended
+ delete piAction;
}
*/
#include "TestPluginAction.h"
-#include <thread>
#include <chrono>
-#include "modes_errors.h"
-#include "common/log.h"
+#include <thread>
+
#include "common/definitions.h"
+#include "common/log.h"
+#include "modes_errors.h"
MODES_NAMESPACE_USE;
int TestPluginAction::printIntVal = 0;
TestPluginAction::TestPluginAction(const std::string &actionKey)
- : PluginAction(actionKey), changeTimeVal(0), cb(nullptr), cbData(nullptr)
+ : PluginAction(actionKey), changeTimeVal(0), cb(nullptr), cbData(nullptr)
{
}
bool TestPluginAction::IsCurrentValue(int val)
{
- if ("changeTime" == key) {
- if (val == changeTimeVal)
- return true;
- } else {
- if (val == printIntVal)
- return true;
- }
- return false;
+ if ("changeTime" == key) {
+ if (val == changeTimeVal)
+ return true;
+ } else {
+ if (val == printIntVal)
+ return true;
+ }
+ return false;
}
bool TestPluginAction::IsCurrentValue(const std::string &val)
{
- return true;
+ return true;
}
int TestPluginAction::set(int val)
{
- if ("changeAccuracy" == key) {
- DBG("set(%s, %d)", key.c_str(), val);
- } else if ("exactness" == key) {
- DBG("set(%s, %d)", key.c_str(), val);
- } else if ("nightLight" == key) {
- DBG("set(%s, %d)", key.c_str(), val);
- } else if ("printInt" == key) {
- DBG("set(%s, %d)", key.c_str(), val);
- printIntVal = val;
- } else if ("sleep" == key) {
- std::this_thread::sleep_for(std::chrono::seconds(val));
- DBG("set(%s, %d)", key.c_str(), val);
- } else if ("sleepErrorReturn" == key) {
- std::this_thread::sleep_for(std::chrono::seconds(val));
- DBG("set(%s, %d)", key.c_str(), val);
- return MODES_ERROR_SYSTEM;
- } else if ("changeTime" == key) {
- g_timeout_add_seconds(val, changeTimeout, this);
- DBG("set(%s, %d)", key.c_str(), val);
- changeTimeVal = val;
- } else {
- ERR("Unknown key(%s)", key.c_str());
- return MODES_ERROR_NOT_SUPPORTED;
- }
-
- return MODES_ERROR_NONE;
+ if ("changeAccuracy" == key) {
+ DBG("set(%s, %d)", key.c_str(), val);
+ } else if ("exactness" == key) {
+ DBG("set(%s, %d)", key.c_str(), val);
+ } else if ("nightLight" == key) {
+ DBG("set(%s, %d)", key.c_str(), val);
+ } else if ("printInt" == key) {
+ DBG("set(%s, %d)", key.c_str(), val);
+ printIntVal = val;
+ } else if ("sleep" == key) {
+ std::this_thread::sleep_for(std::chrono::seconds(val));
+ DBG("set(%s, %d)", key.c_str(), val);
+ } else if ("sleepErrorReturn" == key) {
+ std::this_thread::sleep_for(std::chrono::seconds(val));
+ DBG("set(%s, %d)", key.c_str(), val);
+ return MODES_ERROR_SYSTEM;
+ } else if ("changeTime" == key) {
+ g_timeout_add_seconds(val, changeTimeout, this);
+ DBG("set(%s, %d)", key.c_str(), val);
+ changeTimeVal = val;
+ } else {
+ ERR("Unknown key(%s)", key.c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+
+ return MODES_ERROR_NONE;
}
int TestPluginAction::set(double val)
{
- DBG("TestPlugin::set double (%s, %lf)", key.c_str(), val);
+ DBG("TestPlugin::set double (%s, %lf)", key.c_str(), val);
- if ("printFloat" != key) {
- ERR("Unknown key(%s)", key.c_str());
- return MODES_ERROR_NOT_SUPPORTED;
- }
- return MODES_ERROR_NONE;
+ if ("printFloat" != key) {
+ ERR("Unknown key(%s)", key.c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ return MODES_ERROR_NONE;
}
int TestPluginAction::set(bool val)
{
- DBG("TestPlugin::set bool (%s, %s)", key.c_str(), val ? "true" : "false");
+ DBG("TestPlugin::set bool (%s, %s)", key.c_str(), val ? "true" : "false");
- if ("printBool" != key) {
- ERR("Unknown key(%s)", key.c_str());
- return MODES_ERROR_NOT_SUPPORTED;
- }
+ if ("printBool" != key) {
+ ERR("Unknown key(%s)", key.c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
int TestPluginAction::set(const std::string &val)
{
- DBG("TestPlugin::set string (%s, %s)", key.c_str(), val.c_str());
+ DBG("TestPlugin::set string (%s, %s)", key.c_str(), val.c_str());
- if ("alwaysSameValue" == key) {
- ERR("key(%s) should not reach here", key.c_str());
- return MODES_ERROR_NOT_SUPPORTED;
- }
+ if ("alwaysSameValue" == key) {
+ ERR("key(%s) should not reach here", key.c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
void TestPluginAction::undo()
{
- INFO("TestPluginAction::undo(%s) is Called", getKey().c_str());
+ INFO("TestPluginAction::undo(%s) is Called", getKey().c_str());
}
std::string TestPluginAction::getUndoInfo()
{
- return getKey();
+ return getKey();
}
int TestPluginAction::setUndoInfo(const std::string &info)
{
- INFO("Undo info(%s)", info.c_str());
- return MODES_ERROR_NONE;
+ INFO("Undo info(%s)", info.c_str());
+ return MODES_ERROR_NONE;
}
int TestPluginAction::setChangedCallback(valueChangedCB callback, void *userData)
{
- cb = callback;
- cbData = userData;
+ cb = callback;
+ cbData = userData;
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
void TestPluginAction::unSetChangedCallback(valueChangedCB callback)
{
- cb = NULL;
- cbData = NULL;
+ cb = NULL;
+ cbData = NULL;
}
void TestPluginAction::callChangedCB()
{
- INFO("%s is changed", getKey().c_str());
+ INFO("%s is changed", getKey().c_str());
- if (cb)
- cb(cbData);
+ if (cb)
+ cb(cbData);
}
gboolean TestPluginAction::changeTimeout(gpointer data)
{
- RETV_IF(nullptr == data, G_SOURCE_REMOVE);
+ RETV_IF(nullptr == data, G_SOURCE_REMOVE);
- TestPluginAction *testAction = (TestPluginAction*)data;
- testAction->callChangedCB();
+ TestPluginAction *testAction = (TestPluginAction *)data;
+ testAction->callChangedCB();
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
}
#pragma once
#include <glib.h>
+
#include <string>
+
#include "ModesPIAction.h"
#include "common/definitions.h"
MODES_NAMESPACE_BEGIN
class TestPluginAction : public PluginAction {
-public:
- TestPluginAction(const std::string &actionKey);
- ~TestPluginAction() override = default;
-
- bool IsCurrentValue(int val) override;
- bool IsCurrentValue(const std::string &val) override;
-
- int set(int val) override;
- int set(double val) override;
- int set(bool val) override;
- int set(const std::string &val) override;
- void undo() override;
- std::string getUndoInfo() override;
- int setUndoInfo(const std::string &data) override;
- int setChangedCallback(valueChangedCB callback, void *userData) override;
- void unSetChangedCallback(valueChangedCB callback) override;
- void callChangedCB();
-private:
- static gboolean changeTimeout(gpointer data);
-
- static int printIntVal;
- int changeTimeVal;
- valueChangedCB cb;
- void *cbData;
+ public:
+ TestPluginAction(const std::string &actionKey);
+ ~TestPluginAction() override = default;
+
+ bool IsCurrentValue(int val) override;
+ bool IsCurrentValue(const std::string &val) override;
+
+ int set(int val) override;
+ int set(double val) override;
+ int set(bool val) override;
+ int set(const std::string &val) override;
+ void undo() override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &data) override;
+ int setChangedCallback(valueChangedCB callback, void *userData) override;
+ void unSetChangedCallback(valueChangedCB callback) override;
+ void callChangedCB();
+
+ private:
+ static gboolean changeTimeout(gpointer data);
+
+ static int printIntVal;
+ int changeTimeVal;
+ valueChangedCB cb;
+ void *cbData;
};
MODES_NAMESPACE_END
-
#include "Action.h"
#include <memory>
-#include "mdss.h"
+
#include "ModesEx.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
-std::map<std::string, Action*> Action::subscribedActions;
+std::map<std::string, Action *> Action::subscribedActions;
Action::Action(const std::string &name, std::shared_ptr<PluginAction> pluginAction)
- : ruleName(name), ignoreUndo(false), type(SYNC), life(PERMANENT), piAction(pluginAction),
- locked(false), stopOnErr(false), restriction(NONE)
+ : ruleName(name),
+ ignoreUndo(false),
+ type(SYNC),
+ life(PERMANENT),
+ piAction(pluginAction),
+ locked(false),
+ stopOnErr(false),
+ restriction(NONE)
{
}
void Action::printInfo()
{
- DBG("Action(%s):ID(%s), Restrict(%d)", getRuleName().c_str(), getID().c_str(), getRestrict());
+ DBG("Action(%s):ID(%s), Restrict(%d)", getRuleName().c_str(), getID().c_str(), getRestrict());
}
void Action::setRuleName(const std::string &data)
{
- ruleName = data;
+ ruleName = data;
}
std::string Action::getRuleName()
{
- return ruleName;
+ return ruleName;
}
void Action::setIgnoreUndo(bool ignore)
{
- ignoreUndo = ignore;
+ ignoreUndo = ignore;
}
bool Action::isIgnored()
{
- return ignoreUndo;
+ return ignoreUndo;
}
void Action::setID(const std::string &actionId)
{
- id = actionId;
+ id = actionId;
}
std::string Action::getID()
{
- return id;
+ return id;
}
void Action::setRestrict(const ActionRestrict &data)
{
- restriction = data;
+ restriction = data;
}
void Action::setStopOnErr(bool val)
{
- stopOnErr = val;
+ stopOnErr = val;
}
bool Action::getStopOnErr()
{
- return stopOnErr;
+ return stopOnErr;
}
void Action::setType(ActionType val)
{
- type = val;
+ type = val;
}
Action::ActionType Action::getType()
{
- return type;
+ return type;
}
void Action::setLife(ActionRuleLife val)
{
- life = val;
+ life = val;
}
Action::ActionRuleLife Action::getLife()
{
- return life;
+ return life;
}
Action::ActionRestrict Action::getRestrict()
{
- return restriction;
+ return restriction;
}
void Action::setLocked(bool lock)
{
- locked = lock;
+ locked = lock;
}
bool Action::isLocked()
{
- return locked;
+ return locked;
}
void Action::setPrivileges(std::list<std::string> privList)
{
- privileges = privList;
+ privileges = privList;
}
-const std::list<std::string>& Action::getPrivileges()
+const std::list<std::string> &Action::getPrivileges()
{
- return privileges;
+ return privileges;
}
void Action::attachObserver(ActionObserver *obs)
{
- observers.push_back(obs);
+ observers.push_back(obs);
}
void Action::detachObserver(ActionObserver *obs)
{
- observers.remove(obs);
+ observers.remove(obs);
}
std::string Action::backupUndoInfo()
{
- return piAction->getUndoInfo();
+ return piAction->getUndoInfo();
}
int Action::restoreUndoInfo(const std::string &info)
{
- RETV_IF(ignoreUndo, MODES_ERROR_NONE);
+ RETV_IF(ignoreUndo, MODES_ERROR_NONE);
- int ret = piAction->setUndoInfo(info);
- if (MODES_ERROR_NONE != ret) {
- ignoreUndo = true;
- ERR("piAction(%s) setUndoInfo(%s) Fail", piAction->getKey().c_str(), info.c_str());
- return ret;
- }
- subscribeChanges();
+ int ret = piAction->setUndoInfo(info);
+ if (MODES_ERROR_NONE != ret) {
+ ignoreUndo = true;
+ ERR("piAction(%s) setUndoInfo(%s) Fail", piAction->getKey().c_str(), info.c_str());
+ return ret;
+ }
+ subscribeChanges();
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
void Action::subscribeChanges()
{
- int ret = piAction->setChangedCallback(valueChangedCallback, this);
- if (MODES_ERROR_NONE != ret) {
- WARN("piAction(%s) setChangedCallback() Fail(%d)", piAction->getKey().c_str(), ret);
- } else {
- auto result = subscribedActions.insert(std::pair<std::string, Action*>(ruleName, this));
- if (false == result.second) {
- WARN("Action(%s), already exists", ruleName.c_str());
- return;
- }
- }
+ int ret = piAction->setChangedCallback(valueChangedCallback, this);
+ if (MODES_ERROR_NONE != ret) {
+ WARN("piAction(%s) setChangedCallback() Fail(%d)", piAction->getKey().c_str(), ret);
+ } else {
+ auto result = subscribedActions.insert(std::pair<std::string, Action *>(ruleName, this));
+ if (false == result.second) {
+ WARN("Action(%s), already exists", ruleName.c_str());
+ return;
+ }
+ }
}
void Action::unsubscribeChanges()
{
- piAction->unSetChangedCallback(valueChangedCallback);
- subscribedActions.erase(ruleName);
+ piAction->unSetChangedCallback(valueChangedCallback);
+ subscribedActions.erase(ruleName);
}
void Action::invokeChangedCB()
{
- auto found = subscribedActions.find(ruleName);
- if (subscribedActions.end() != found)
- valueChangedCallback(found->second);
+ auto found = subscribedActions.find(ruleName);
+ if (subscribedActions.end() != found)
+ valueChangedCallback(found->second);
}
void Action::valueChangedCallback(void *userData)
{
- Action *action = (Action*)userData;
- RET_IF(nullptr == action);
+ Action *action = (Action *)userData;
+ RET_IF(nullptr == action);
- action->notifyObservers();
+ action->notifyObservers();
- DBG("Action(%s) Changed", action->ruleName.c_str());
+ DBG("Action(%s) Changed", action->ruleName.c_str());
}
void Action::notifyObservers()
{
- RET_IF(true == ignoreUndo);
+ RET_IF(true == ignoreUndo);
- unsubscribeChanges();
- ignoreUndo = true;
+ unsubscribeChanges();
+ ignoreUndo = true;
- for (auto it = observers.begin(); it != observers.end(); ++it)
- (*it)->update(reinterpret_cast<int*>(this));
+ for (auto it = observers.begin(); it != observers.end(); ++it)
+ (*it)->update(reinterpret_cast<int *>(this));
}
*/
#pragma once
-#include <map>
#include <list>
-#include <string>
+#include <map>
#include <memory>
-#include "mdss.h"
-#include "ModesPIAction.h"
+#include <string>
+
#include "ActionObserver.h"
+#include "ModesPIAction.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class Action {
-public:
- typedef enum {
- NONE,
- LOCK,
- ESSENTIAL
- } ActionRestrict;
+ public:
+ typedef enum { NONE, LOCK, ESSENTIAL } ActionRestrict;
+
+ typedef enum { SYNC, ASYNC } ActionType;
+
+ typedef enum { PERMANENT, VOLATILE } ActionRuleLife;
- typedef enum {
- SYNC,
- ASYNC
- } ActionType;
+ Action(const std::string &ruleName, std::shared_ptr<PluginAction> pluginAction);
+ virtual ~Action();
- typedef enum {
- PERMANENT,
- VOLATILE
- } ActionRuleLife;
+ void printInfo();
+ void setRuleName(const std::string &data);
+ std::string getRuleName();
+ void setIgnoreUndo(bool ignore);
+ bool isIgnored();
+ void setID(const std::string &actionId);
+ std::string getID();
+ void setRestrict(const ActionRestrict &data);
+ ActionRestrict getRestrict();
+ void setLocked(bool lock);
+ bool isLocked();
+ void setStopOnErr(bool val);
+ bool getStopOnErr();
+ void setType(ActionType val);
+ ActionType getType();
+ void setLife(ActionRuleLife val);
+ ActionRuleLife getLife();
+ void setPrivileges(std::list<std::string> privList);
+ const std::list<std::string> &getPrivileges();
+ void attachObserver(ActionObserver *obs);
+ void detachObserver(ActionObserver *obs);
+ std::string backupUndoInfo();
+ int restoreUndoInfo(const std::string &info);
+ virtual int setValue(const std::string &val) = 0;
+ virtual bool checkChanged() = 0;
+ virtual std::string getStringOfValue() = 0;
+ virtual int apply() = 0;
+ virtual int applyOneShot() = 0;
+ virtual void undo() = 0;
- Action(const std::string &ruleName, std::shared_ptr<PluginAction> pluginAction);
- virtual ~Action();
+ protected:
+ void subscribeChanges();
+ void unsubscribeChanges();
+ void invokeChangedCB();
+ std::string ruleName;
+ bool ignoreUndo;
+ ActionType type;
+ ActionRuleLife life;
+ std::shared_ptr<PluginAction> piAction;
- void printInfo();
- void setRuleName(const std::string &data);
- std::string getRuleName();
- void setIgnoreUndo(bool ignore);
- bool isIgnored();
- void setID(const std::string &actionId);
- std::string getID();
- void setRestrict(const ActionRestrict &data);
- ActionRestrict getRestrict();
- void setLocked(bool lock);
- bool isLocked();
- void setStopOnErr(bool val);
- bool getStopOnErr();
- void setType(ActionType val);
- ActionType getType();
- void setLife(ActionRuleLife val);
- ActionRuleLife getLife();
- void setPrivileges(std::list<std::string> privList);
- const std::list<std::string>& getPrivileges();
- void attachObserver(ActionObserver *obs);
- void detachObserver(ActionObserver *obs);
- std::string backupUndoInfo();
- int restoreUndoInfo(const std::string &info);
- virtual int setValue(const std::string &val) = 0;
- virtual bool checkChanged() = 0;
- virtual std::string getStringOfValue() = 0;
- virtual int apply() = 0;
- virtual int applyOneShot() = 0;
- virtual void undo() = 0;
-protected:
- void subscribeChanges();
- void unsubscribeChanges();
- void invokeChangedCB();
- std::string ruleName;
- bool ignoreUndo;
- ActionType type;
- ActionRuleLife life;
- std::shared_ptr<PluginAction> piAction;
-private:
- static void valueChangedCallback(void *userData);
- void notifyObservers();
- std::string id;
- std::list<std::string> privileges;
- bool locked; //Another action(same rule) is restricted(LOCK), It is assigned by ConflictManager
- bool stopOnErr;
- ActionRestrict restriction;
- std::list<ActionObserver*> observers;
- static std::map<std::string, Action*> subscribedActions;
+ private:
+ static void valueChangedCallback(void *userData);
+ void notifyObservers();
+ std::string id;
+ std::list<std::string> privileges;
+ bool locked; // Another action(same rule) is restricted(LOCK), It is assigned by
+ // ConflictManager
+ bool stopOnErr;
+ ActionRestrict restriction;
+ std::list<ActionObserver *> observers;
+ static std::map<std::string, Action *> subscribedActions;
#ifdef MDS_TEST
- friend class PolicyTest;
+ friend class PolicyTest;
#endif
};
#pragma once
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ActionObserver {
-public:
- virtual void update(int *key) = 0;
+ public:
+ virtual void update(int *key) = 0;
};
MODES_NAMESPACE_END
#include "ActionRule.h"
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_USE;
-ActionRule::ActionRule()
- : plugin(nullptr), life(Action::PERMANENT)
+ActionRule::ActionRule() : plugin(nullptr), life(Action::PERMANENT)
{
}
std::string ActionRule::getName()
{
- return ruleName;
+ return ruleName;
}
void ActionRule::setPlugin(Plugin *pi)
{
- plugin = pi;
+ plugin = pi;
}
-Plugin* ActionRule::getPlugin()
+Plugin *ActionRule::getPlugin()
{
- return plugin;
+ return plugin;
}
void ActionRule::addPrivilege(const std::string &priv)
{
- privileges.push_back(priv);
+ privileges.push_back(priv);
}
void ActionRule::setLife(Action::ActionRuleLife val)
{
- life = val;
+ life = val;
}
#include <list>
#include <string>
-#include "mdss.h"
-#include "ModesPlugin.h"
+
#include "Action.h"
+#include "ModesPlugin.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ActionRule {
-public:
- ActionRule();
- virtual ~ActionRule() = default;
-
- std::string getName();
- Plugin* getPlugin();
- void setPlugin(Plugin *pi);
- void addPrivilege(const std::string &priv);
- void setLife(Action::ActionRuleLife val);
- virtual Action* makeAction() = 0;
- virtual int addAlias(const std::string &alias, const std::string &value) = 0;
-protected:
- std::string ruleName;
- std::list<std::string> privileges;
- Plugin *plugin;
- Action::ActionRuleLife life;
-private:
- // TODO:: handle conflict List, since, description, version
- //std::list<std::string> conflictActionList;
- //std::string description;
- //enum since;
- //std::string domain;
+ public:
+ ActionRule();
+ virtual ~ActionRule() = default;
+
+ std::string getName();
+ Plugin *getPlugin();
+ void setPlugin(Plugin *pi);
+ void addPrivilege(const std::string &priv);
+ void setLife(Action::ActionRuleLife val);
+ virtual Action *makeAction() = 0;
+ virtual int addAlias(const std::string &alias, const std::string &value) = 0;
+
+ protected:
+ std::string ruleName;
+ std::list<std::string> privileges;
+ Plugin *plugin;
+ Action::ActionRuleLife life;
+
+ private:
+ // TODO:: handle conflict List, since, description, version
+ // std::list<std::string> conflictActionList;
+ // std::string description;
+ // enum since;
+ // std::string domain;
};
MODES_NAMESPACE_END
MODES_NAMESPACE_USE;
char ArgumentParser::argp_doc[] =
- "The modes(Mode Supervisor) manages configurations which is described at a mode."
- "The mode includes settings of display, sound, lte / 3g, wifi, sensor, etc."
- "\v"
- "Tizen: <http://www.tizen.org>";
+ "The modes(Mode Supervisor) manages configurations which is described at a mode."
+ "The mode includes settings of display, sound, lte / 3g, wifi, sensor, etc."
+ "\v"
+ "Tizen: <http://www.tizen.org>";
char ArgumentParser::args_doc[] =
- "[extraModeDir1] [extraModeDir...] [--pluginDir=../plugin]"
- " [--ruleDir=../example] [--[--help]";
+ "[extraModeDir1] [extraModeDir...] [--pluginDir=../plugin]"
+ " [--ruleDir=../example] [--[--help]";
struct argp_option ArgumentParser::options[] = {
- {"pluginDir", 'p', "pluginDirPath", OPTION_ARG_OPTIONAL, "Set directory of plugin"},
- {"ruleDir", 'r', "actionRuleDirPath", OPTION_ARG_OPTIONAL, "Set directory of Action Rule file"},
- { 0 }
-};
+ {"pluginDir", 'p', "pluginDirPath", OPTION_ARG_OPTIONAL, "Set directory of plugin"},
+ {"ruleDir", 'r', "actionRuleDirPath", OPTION_ARG_OPTIONAL,
+ "Set directory of Action Rule file"},
+ {0}};
error_t ArgumentParser::parse_opt(int key, char *arg, struct argp_state *state)
{
- ArgumentParser *parser = (ArgumentParser *)state->input;
- char *nextArg;
-
- switch (key) {
- case 'p':
- nextArg = state->argv[state->next];
- if (nextArg && *nextArg != '-') {
- parser->pluginDir = nextArg;
- state->next++;
- }
- break;
- case 'r':
- nextArg = state->argv[state->next];
- if (nextArg && *nextArg != '-') {
- parser->ruleDir = nextArg;
- state->next++;
- }
- break;
- case ARGP_KEY_NO_ARGS:
- break;
- case ARGP_KEY_ARG:
- parser->modeDirCount = (state->argc - state->next) + 1;
- parser->modeXMLDirList = &state->argv[state->next-1];
- state->next = state->argc;
- break;
- default:
- return ARGP_ERR_UNKNOWN;
- }
- return 0;
+ ArgumentParser *parser = (ArgumentParser *)state->input;
+ char *nextArg;
+
+ switch (key) {
+ case 'p':
+ nextArg = state->argv[state->next];
+ if (nextArg && *nextArg != '-') {
+ parser->pluginDir = nextArg;
+ state->next++;
+ }
+ break;
+ case 'r':
+ nextArg = state->argv[state->next];
+ if (nextArg && *nextArg != '-') {
+ parser->ruleDir = nextArg;
+ state->next++;
+ }
+ break;
+ case ARGP_KEY_NO_ARGS:
+ break;
+ case ARGP_KEY_ARG:
+ parser->modeDirCount = (state->argc - state->next) + 1;
+ parser->modeXMLDirList = &state->argv[state->next - 1];
+ state->next = state->argc;
+ break;
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
}
/* Our argp parser. */
struct argp ArgumentParser::argp_input = {options, parse_opt, args_doc, argp_doc};
ArgumentParser::ArgumentParser()
- :modeDirCount(0), modeXMLDirList(NULL), ruleDir(NULL), pluginDir(NULL)
+ : modeDirCount(0), modeXMLDirList(NULL), ruleDir(NULL), pluginDir(NULL)
{
}
ModesConfig ArgumentParser::parse(int argc, char **argv)
{
- argp_program_version = "mode-supervisor " MODES_VERSION;
- argp_parse(&argp_input, argc, argv, 0, 0, this);
-
- ModesConfig config;
-
- if (this->modeDirCount) {
- for (int i = 0; i <= this->modeDirCount; ++i)
- DBG("mode xml dir path list[%d] %s", i, this->modeXMLDirList[i]);
-
- config.modeXMLDirs = std::set<std::string>(modeXMLDirList, modeXMLDirList + modeDirCount);
- }
- auto found = config.modeXMLDirs.find(MODES_MODE_DEFAULT_DIR);
- if (config.modeXMLDirs.end() == found)
- config.modeXMLDirs.insert(MODES_MODE_DEFAULT_DIR);
-
- if (this->ruleDir) {
- DBG("Action Rule dir path: %s", this->ruleDir);
- config.actionRuleDir = this->ruleDir;
- } else {
- config.actionRuleDir = MODES_ACTIONRULE_DEFAULT_DIR;
- }
-
- if (this->pluginDir) {
- DBG("plugin dir path : %s", this->pluginDir);
- config.pluginDir = this->pluginDir;
- } else {
- config.pluginDir = MODES_PLUGIN_DEFAULT_DIR;
- }
-
- return config;
+ argp_program_version = "mode-supervisor " MODES_VERSION;
+ argp_parse(&argp_input, argc, argv, 0, 0, this);
+
+ ModesConfig config;
+
+ if (this->modeDirCount) {
+ for (int i = 0; i <= this->modeDirCount; ++i)
+ DBG("mode xml dir path list[%d] %s", i, this->modeXMLDirList[i]);
+
+ config.modeXMLDirs = std::set<std::string>(modeXMLDirList, modeXMLDirList + modeDirCount);
+ }
+ auto found = config.modeXMLDirs.find(MODES_MODE_DEFAULT_DIR);
+ if (config.modeXMLDirs.end() == found)
+ config.modeXMLDirs.insert(MODES_MODE_DEFAULT_DIR);
+
+ if (this->ruleDir) {
+ DBG("Action Rule dir path: %s", this->ruleDir);
+ config.actionRuleDir = this->ruleDir;
+ } else {
+ config.actionRuleDir = MODES_ACTIONRULE_DEFAULT_DIR;
+ }
+
+ if (this->pluginDir) {
+ DBG("plugin dir path : %s", this->pluginDir);
+ config.pluginDir = this->pluginDir;
+ } else {
+ config.pluginDir = MODES_PLUGIN_DEFAULT_DIR;
+ }
+
+ return config;
}
*/
#pragma once
-#include <string> //for avoiding a bug of argp. it should include before argp.h
+#include <string> //for avoiding a bug of argp. it should include before argp.h
#include <argp.h>
-#include "mdss.h"
+
#include "ModesConfig.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ArgumentParser {
-public:
- ArgumentParser();
- ModesConfig parse(int argc, char **argv);
-private:
- int modeDirCount;
- char **modeXMLDirList;
- char *ruleDir;
- char *pluginDir;
+ public:
+ ArgumentParser();
+ ModesConfig parse(int argc, char **argv);
+
+ private:
+ int modeDirCount;
+ char **modeXMLDirList;
+ char *ruleDir;
+ char *pluginDir;
- static char argp_doc[];
- static char args_doc[];
- static struct argp_option options[];
- static error_t parse_opt(int key, char *arg, struct argp_state *state);
- static struct argp argp_input;
+ static char argp_doc[];
+ static char args_doc[];
+ static struct argp_option options[];
+ static error_t parse_opt(int key, char *arg, struct argp_state *state);
+ static struct argp argp_input;
};
MODES_NAMESPACE_END;
*/
#include "ClientConnection.h"
+#include "ModesEx.h"
#include "common/dbus_def.h"
#include "mdss.h"
-#include "ModesEx.h"
MODES_NAMESPACE_USE;
void ClientConnection::startDbus()
{
- if (ownerId) {
- ERR("Already Connected");
- return;
- }
+ if (ownerId) {
+ ERR("Already Connected");
+ return;
+ }
- ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM, MODES_DBUS_INTERFACE,
- G_BUS_NAME_OWNER_FLAGS_REPLACE, onBusAcquired,
- NULL, NULL, NULL, NULL);
+ ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM, MODES_DBUS_INTERFACE,
+ G_BUS_NAME_OWNER_FLAGS_REPLACE, onBusAcquired, NULL, NULL, NULL, NULL);
- dbusHandle = mds_dbus_skeleton_new();
- if (NULL == dbusHandle) {
- ERR("mds_dbus_skeleton_new() Fail");
- throw ModesEx(ModesEx::DBUS_ERROR);
- }
+ dbusHandle = mds_dbus_skeleton_new();
+ if (NULL == dbusHandle) {
+ ERR("mds_dbus_skeleton_new() Fail");
+ throw ModesEx(ModesEx::DBUS_ERROR);
+ }
}
void ClientConnection::stopDbus()
{
- g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(dbusHandle));
- g_bus_unown_name(ownerId);
- g_object_unref(dbusHandle);
+ g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(dbusHandle));
+ g_bus_unown_name(ownerId);
+ g_object_unref(dbusHandle);
- dbusHandle = NULL;
- ownerId = 0;
+ dbusHandle = NULL;
+ ownerId = 0;
}
void ClientConnection::addRequestHandler(const std::string &method, GCallback cb)
{
- g_signal_connect(dbusHandle, method.c_str(), cb, NULL);
+ g_signal_connect(dbusHandle, method.c_str(), cb, NULL);
}
void ClientConnection::update(const std::string &id, ModeState state)
{
- mds_dbus_emit_changed_mode(dbusHandle, id.c_str(), state);
+ mds_dbus_emit_changed_mode(dbusHandle, id.c_str(), state);
}
void ClientConnection::onBusAcquired(GDBusConnection *conn, const gchar *name, gpointer userData)
{
- int ret;
- GError *error = NULL;
+ int ret;
+ GError *error = NULL;
- ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(dbusHandle),
- conn, MODES_DBUS_OBJPATH, &error);
- if (FALSE == ret) {
- ERR("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
- g_error_free(error);
- }
+ ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(dbusHandle), conn,
+ MODES_DBUS_OBJPATH, &error);
+ if (FALSE == ret) {
+ ERR("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
+ g_error_free(error);
+ }
}
#pragma once
#include <string>
+
+#include "ModeObserver.h"
#include "common/dbus.h"
#include "mdss.h"
-#include "ModeObserver.h"
MODES_NAMESPACE_BEGIN
class ClientConnection : public ModeObserver {
-public:
- void startDbus();
- void stopDbus();
- void addRequestHandler(const std::string &method, GCallback cb);
- void update(const std::string &name, ModeState state);
-private:
- static void onBusAcquired(GDBusConnection *conn,
- const gchar *name, gpointer user_data);
- static mdsDbus *dbusHandle;
- static guint ownerId ;
+ public:
+ void startDbus();
+ void stopDbus();
+ void addRequestHandler(const std::string &method, GCallback cb);
+ void update(const std::string &name, ModeState state);
+
+ private:
+ static void onBusAcquired(GDBusConnection *conn, const gchar *name, gpointer user_data);
+ static mdsDbus *dbusHandle;
+ static guint ownerId;
};
MODES_NAMESPACE_END
-
*/
#include "ClientPrivilege.h"
-#include <string>
#include <cynara-client.h>
-#include <cynara-session.h>
#include <cynara-creds-gdbus.h>
+#include <cynara-session.h>
+
+#include <string>
+
#include "common/dbus.h"
#include "mdss.h"
MODES_NAMESPACE_USE;
ClientPrivilege::ClientPrivilege(GDBusMethodInvocation *invocation)
- : handle(NULL), client(NULL), user(NULL), clientSession(NULL)
+ : handle(NULL), client(NULL), user(NULL), clientSession(NULL)
{
- int pid;
- GDBusConnection *conn = g_dbus_method_invocation_get_connection(invocation);
- // Do not free this string, it is owned by connection
- const char *senderUniqueName = g_dbus_method_invocation_get_sender(invocation);
+ int pid;
+ GDBusConnection *conn = g_dbus_method_invocation_get_connection(invocation);
+ // Do not free this string, it is owned by connection
+ const char *senderUniqueName = g_dbus_method_invocation_get_sender(invocation);
- int ret = cynara_creds_gdbus_get_user(conn, senderUniqueName, USER_METHOD_DEFAULT, &user);
- if (CYNARA_API_SUCCESS != ret)
- ERR("cynara_creds_gdbus_get_user() Fail(%d)", ret);
+ int ret = cynara_creds_gdbus_get_user(conn, senderUniqueName, USER_METHOD_DEFAULT, &user);
+ if (CYNARA_API_SUCCESS != ret)
+ ERR("cynara_creds_gdbus_get_user() Fail(%d)", ret);
- ret = cynara_creds_gdbus_get_client(conn, senderUniqueName, CLIENT_METHOD_DEFAULT, &client);
- if (CYNARA_API_SUCCESS != ret)
- ERR("cynara_creds_gdbus_get_client() Fail(%d)", ret);
+ ret = cynara_creds_gdbus_get_client(conn, senderUniqueName, CLIENT_METHOD_DEFAULT, &client);
+ if (CYNARA_API_SUCCESS != ret)
+ ERR("cynara_creds_gdbus_get_client() Fail(%d)", ret);
- ret = cynara_creds_gdbus_get_pid(conn, senderUniqueName, &pid);
- if (CYNARA_API_SUCCESS != ret)
- ERR("cynara_creds_gdbus_get_pid() Fail(%d)", ret);
+ ret = cynara_creds_gdbus_get_pid(conn, senderUniqueName, &pid);
+ if (CYNARA_API_SUCCESS != ret)
+ ERR("cynara_creds_gdbus_get_pid() Fail(%d)", ret);
- clientSession = cynara_session_from_pid(pid);
- if (NULL == clientSession)
- ERR("cynara_session_from_pid() Fail()");
+ clientSession = cynara_session_from_pid(pid);
+ if (NULL == clientSession)
+ ERR("cynara_session_from_pid() Fail()");
- ret = cynara_initialize(&handle, NULL);
- if (CYNARA_API_SUCCESS != ret)
- ERR("cynara_initialize() Fail(%d)", ret);
+ ret = cynara_initialize(&handle, NULL);
+ if (CYNARA_API_SUCCESS != ret)
+ ERR("cynara_initialize() Fail(%d)", ret);
}
ClientPrivilege::~ClientPrivilege()
{
- cynara_finish(handle);
- free(client);
- free(user);
- free(clientSession);
+ cynara_finish(handle);
+ free(client);
+ free(user);
+ free(clientSession);
}
int ClientPrivilege::check(const Mode &mode)
{
- auto actionList = mode.getActionList();
- for (auto it = actionList.begin(); it != actionList.end(); it++) {
- auto privList = (*it)->getPrivileges();
- for (auto privIt = privList.begin(); privIt != privList.end(); privIt++) {
- //No Privilege = Allow All
- if ((*privIt).empty())
- continue;
- int ret = checkCynara((*it)->getRuleName(), *privIt);
- if (MODES_ERROR_NONE != ret)
- return ret;
- }
- }
- return MODES_ERROR_NONE;
+ auto actionList = mode.getActionList();
+ for (auto it = actionList.begin(); it != actionList.end(); it++) {
+ auto privList = (*it)->getPrivileges();
+ for (auto privIt = privList.begin(); privIt != privList.end(); privIt++) {
+ // No Privilege = Allow All
+ if ((*privIt).empty())
+ continue;
+ int ret = checkCynara((*it)->getRuleName(), *privIt);
+ if (MODES_ERROR_NONE != ret)
+ return ret;
+ }
+ }
+ return MODES_ERROR_NONE;
}
int ClientPrivilege::checkCynara(const std::string &rule, const std::string &priv)
{
- int ret = cynara_check(handle, client, clientSession, user, priv.c_str());
- if (CYNARA_API_ACCESS_ALLOWED != ret) {
- ERR("Action(%s) priv.check(%s) Fail(%d)", rule.c_str(), priv.c_str(), ret);
- if (ret == CYNARA_API_ACCESS_DENIED)
- return MODES_ERROR_PERMISSION_DENIED;
- else
- return MODES_ERROR_SYSTEM;
- }
+ int ret = cynara_check(handle, client, clientSession, user, priv.c_str());
+ if (CYNARA_API_ACCESS_ALLOWED != ret) {
+ ERR("Action(%s) priv.check(%s) Fail(%d)", rule.c_str(), priv.c_str(), ret);
+ if (ret == CYNARA_API_ACCESS_DENIED)
+ return MODES_ERROR_PERMISSION_DENIED;
+ else
+ return MODES_ERROR_SYSTEM;
+ }
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
-
-
*/
#pragma once
-#include <string>
#include <cynara-client.h>
+
+#include <string>
+
#include "Mode.h"
-#include "mdss.h"
#include "common/dbus.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ClientPrivilege {
-public:
- ClientPrivilege(GDBusMethodInvocation *invocation);
- ~ClientPrivilege();
- int check(const Mode &mode);
-private:
- int checkCynara(const std::string &rule, const std::string &priv);
- cynara *handle;
- char *client;
- char *user;
- char *clientSession;
+ public:
+ ClientPrivilege(GDBusMethodInvocation *invocation);
+ ~ClientPrivilege();
+ int check(const Mode &mode);
+
+ private:
+ int checkCynara(const std::string &rule, const std::string &priv);
+ cynara *handle;
+ char *client;
+ char *user;
+ char *clientSession;
};
MODES_NAMESPACE_END
#include "EssentialHandler.h"
#include <glib.h>
-#include "mdss.h"
+
#include "ModesEx.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
void EssentialHandler::setModeManager(ModeManager *mgr)
{
- modeMgr = mgr;
+ modeMgr = mgr;
}
void EssentialHandler::undoHandler(const std::string &modeID)
{
- DBG("undo idler(%s) is added", modeID.c_str());
+ DBG("undo idler(%s) is added", modeID.c_str());
- g_idle_add(undoIdler, new std::string(modeID));
+ g_idle_add(undoIdler, new std::string(modeID));
}
gboolean EssentialHandler::undoIdler(gpointer data)
{
- RETV_IF(NULL == data, G_SOURCE_REMOVE);
- RETV_IF(nullptr == modeMgr, G_SOURCE_REMOVE);
+ RETV_IF(NULL == data, G_SOURCE_REMOVE);
+ RETV_IF(nullptr == modeMgr, G_SOURCE_REMOVE);
- std::string &modeID = *(std::string*)data;
+ std::string &modeID = *(std::string *)data;
- int ret = modeMgr->undoMode(modeID);
- if (MODES_ERROR_NONE != ret)
- ERR("undoMode(%s) Fail(%d)", modeID.c_str(), ret);
+ int ret = modeMgr->undoMode(modeID);
+ if (MODES_ERROR_NONE != ret)
+ ERR("undoMode(%s) Fail(%d)", modeID.c_str(), ret);
- delete &modeID;
- return G_SOURCE_REMOVE;
+ delete &modeID;
+ return G_SOURCE_REMOVE;
}
*/
#pragma once
-#include <string>
#include <glib.h>
-#include "mdss.h"
+
+#include <string>
+
#include "ModeManager.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class EssentialHandler {
-public:
- static void setModeManager(ModeManager *mgr);
- static void undoHandler(const std::string &modeName);
-private:
- static gboolean undoIdler(gpointer data);
- static ModeManager *modeMgr;
+ public:
+ static void setModeManager(ModeManager *mgr);
+ static void undoHandler(const std::string &modeName);
+
+ private:
+ static gboolean undoIdler(gpointer data);
+ static ModeManager *modeMgr;
};
MODES_NAMESPACE_END
*/
#include "Mode.h"
-#include <thread>
#include <algorithm>
-#include "modes_constants.h"
+#include <thread>
+
#include "ModesEx.h"
+#include "modes_constants.h"
MODES_NAMESPACE_USE;
-Mode::Mode()
- : type(MODE_NORMAL), hidden(false), essential(false)
+Mode::Mode() : type(MODE_NORMAL), hidden(false), essential(false)
{
}
void Mode::addAction(Action *action)
{
- actionList.push_back(std::shared_ptr<Action>(action));
+ actionList.push_back(std::shared_ptr<Action>(action));
}
void Mode::addUndo(Action *action)
{
- undoList.push_back(std::shared_ptr<Action>(action));
+ undoList.push_back(std::shared_ptr<Action>(action));
}
void Mode::setName(const std::string &data)
{
- name = data;
+ name = data;
}
const std::string Mode::getName() const
{
- return name;
+ return name;
}
void Mode::setID(const std::string &data)
{
- id = data;
+ id = data;
}
const std::string Mode::getID() const
{
- return id;
+ return id;
}
void Mode::setModeType(Mode::ModeType val)
{
- type = val;
+ type = val;
}
Mode::ModeType Mode::getModeType() const
{
- return type;
+ return type;
}
void Mode::setHidden(bool val)
{
- hidden = val;
+ hidden = val;
}
bool Mode::isHidden() const
{
- return hidden;
+ return hidden;
}
void Mode::setEssential(bool val)
{
- essential = val;
+ essential = val;
}
bool Mode::hasEssential() const
{
- return essential;
+ return essential;
}
int Mode::apply()
{
- std::list<std::shared_ptr<Action>>::iterator it;
- for (it = actionList.begin(); it != actionList.end(); it++) {
- if ((*it)->isLocked()) //It was checked by ConflictManager(isConflict)
- continue;
+ std::list<std::shared_ptr<Action>>::iterator it;
+ for (it = actionList.begin(); it != actionList.end(); it++) {
+ if ((*it)->isLocked()) // It was checked by ConflictManager(isConflict)
+ continue;
- if (Action::ActionType::ASYNC == (*it)->getType()) {
- std::thread(&Action::apply, *it).detach();
- } else {
- int ret = (*it)->apply();
- if (MODES_ERROR_NONE != ret && (*it)->getStopOnErr()) {
- ERR("Action(%s) apply Fail(%d)", (*it)->getRuleName().c_str(), ret);
- return ret;
- }
- }
- }
- return MODES_ERROR_NONE;
+ if (Action::ActionType::ASYNC == (*it)->getType()) {
+ std::thread(&Action::apply, *it).detach();
+ } else {
+ int ret = (*it)->apply();
+ if (MODES_ERROR_NONE != ret && (*it)->getStopOnErr()) {
+ ERR("Action(%s) apply Fail(%d)", (*it)->getRuleName().c_str(), ret);
+ return ret;
+ }
+ }
+ }
+ return MODES_ERROR_NONE;
}
int Mode::applyOneShot()
{
- std::list<std::shared_ptr<Action>>::iterator it;
- for (it = actionList.begin(); it != actionList.end(); it++) {
- if ((*it)->isLocked()) //It was checked by ConflictManager(isConflict)
- continue;
+ std::list<std::shared_ptr<Action>>::iterator it;
+ for (it = actionList.begin(); it != actionList.end(); it++) {
+ if ((*it)->isLocked()) // It was checked by ConflictManager(isConflict)
+ continue;
- if (Action::ActionType::ASYNC == (*it)->getType()) {
- std::thread(&Action::applyOneShot, *it).detach();
- } else {
- int ret = (*it)->applyOneShot();
- if (MODES_ERROR_NONE != ret && (*it)->getStopOnErr()) {
- ERR("Action(%s) applyOneShot Fail(%d)", (*it)->getRuleName().c_str(), ret);
- return ret;
- }
- }
- }
- return MODES_ERROR_NONE;
+ if (Action::ActionType::ASYNC == (*it)->getType()) {
+ std::thread(&Action::applyOneShot, *it).detach();
+ } else {
+ int ret = (*it)->applyOneShot();
+ if (MODES_ERROR_NONE != ret && (*it)->getStopOnErr()) {
+ ERR("Action(%s) applyOneShot Fail(%d)", (*it)->getRuleName().c_str(), ret);
+ return ret;
+ }
+ }
+ }
+ return MODES_ERROR_NONE;
}
void Mode::undo()
{
- std::list<std::shared_ptr<Action>>::iterator it;
- for (it = actionList.begin(); it != actionList.end(); it++)
- (*it)->undo();
+ std::list<std::shared_ptr<Action>>::iterator it;
+ for (it = actionList.begin(); it != actionList.end(); it++)
+ (*it)->undo();
- for (it = undoList.begin(); it != undoList.end(); it++)
- (*it)->applyOneShot();
+ for (it = undoList.begin(); it != undoList.end(); it++)
+ (*it)->applyOneShot();
}
std::list<std::shared_ptr<Action>> Mode::getActionList() const
{
- return actionList;
+ return actionList;
}
std::list<std::shared_ptr<Action>> Mode::getUndoList() const
{
- return undoList;
+ 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;
+ std::string fileID = id.substr(sizeof(MODES_ID_PREFIX) - 1);
+ std::replace(fileID.begin(), fileID.end(), '/', '_');
+ return fileID;
}
#pragma once
#include <list>
-#include <string>
#include <memory>
-#include "mdss.h"
+#include <string>
+
#include "Action.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class Mode {
-public:
- typedef enum {
- MODE_NORMAL,
- MODE_ONESHOT,
- } ModeType;
+ public:
+ typedef enum {
+ MODE_NORMAL,
+ MODE_ONESHOT,
+ } ModeType;
+
+ Mode();
+ ~Mode();
+ void setName(const std::string &data);
+ const std::string getName() const;
- Mode();
- ~Mode();
- 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 setID(const std::string &data);
- const std::string getID() const;
- std::string getFileNameID() const;
+ void setModeType(Mode::ModeType val);
+ ModeType getModeType() const;
- void setModeType(Mode::ModeType val);
- ModeType getModeType() const;
+ void setHidden(bool val);
+ bool isHidden() const;
- void setHidden(bool val);
- bool isHidden() const;
+ void setEssential(bool val);
+ bool hasEssential() const;
- void setEssential(bool val);
- bool hasEssential() const;
+ void addAction(Action *action);
+ std::list<std::shared_ptr<Action>> getActionList() const;
- void addAction(Action *action);
- std::list<std::shared_ptr<Action>> getActionList() const;
+ void addUndo(Action *action);
+ std::list<std::shared_ptr<Action>> getUndoList() const;
- void addUndo(Action *action);
- std::list<std::shared_ptr<Action>> getUndoList() const;
+ int apply();
+ int applyOneShot();
+ void undo();
- int apply();
- int applyOneShot();
- void undo();
-private:
- std::string name;
- std::string id;
- ModeType type;
- bool hidden;
- bool essential;
- std::list<std::shared_ptr<Action>> actionList;
- std::list<std::shared_ptr<Action>> undoList;
+ private:
+ std::string name;
+ std::string id;
+ ModeType type;
+ bool hidden;
+ bool essential;
+ std::list<std::shared_ptr<Action>> actionList;
+ std::list<std::shared_ptr<Action>> undoList;
#ifdef MDS_TEST
- friend class ParserTest;
+ friend class ParserTest;
#endif
};
*/
#include "ModeCareTaker.h"
-#include "mdss.h"
-#include "XMLGenerator.h"
-#include "UndoInfoParser.h"
#include "EssentialHandler.h"
+#include "UndoInfoParser.h"
+#include "XMLGenerator.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
-ModeCareTaker::ModeCareTaker(const std::string &undoInfoDir)
- : undoDir(undoInfoDir)
+ModeCareTaker::ModeCareTaker(const std::string &undoInfoDir) : undoDir(undoInfoDir)
{
}
std::string ModeCareTaker::getUndoInfoDir()
{
- return undoDir;
+ return undoDir;
}
bool ModeCareTaker::hasUndoInfo(const std::string &filenameID)
{
- std::string file = undoDir + "/tizen_" + filenameID + MODES_UNDO_FILE_SUFFIX;
- return (access(file.c_str(), F_OK) == 0);
+ 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.getFileNameID() + MODES_UNDO_FILE_SUFFIX;
- try {
- UndoInfoParser undoInfoParser(file);
- undoInfoParser.putUndoInfo(mode);
-
- realPushMode(mode);
- } catch (std::exception &e) {
- ERR("parser(%s) Fail(%s)", file.c_str(), e.what());
- if (0 != remove(file.c_str()))
- ERR("remove(%s) Fail(%d)", file.c_str(), errno);
- }
+ std::string file = undoDir + "/tizen_" + mode.getFileNameID() + MODES_UNDO_FILE_SUFFIX;
+ try {
+ UndoInfoParser undoInfoParser(file);
+ undoInfoParser.putUndoInfo(mode);
+
+ realPushMode(mode);
+ } catch (std::exception &e) {
+ ERR("parser(%s) Fail(%s)", file.c_str(), e.what());
+ if (0 != remove(file.c_str()))
+ ERR("remove(%s) Fail(%d)", file.c_str(), errno);
+ }
}
void ModeCareTaker::pushMode(const Mode &mode)
{
- realPushMode(mode);
+ realPushMode(mode);
- XMLGenerator gen;
- gen.makeUndoInfoXML(undoDir + "/tizen_" + mode.getFileNameID() + MODES_UNDO_FILE_SUFFIX, mode);
+ XMLGenerator gen;
+ gen.makeUndoInfoXML(undoDir + "/tizen_" + mode.getFileNameID() + MODES_UNDO_FILE_SUFFIX, mode);
}
int ModeCareTaker::popMode(const std::string &id, Mode &mode)
{
- auto found = savedModes.find(id);
- if (savedModes.end() == found) {
- ERR("No Mode(%s)", id.c_str());
- return MODES_ERROR_NO_DATA;
- }
-
- 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 == id)
- it = essentialMap.erase(it);
- else
- ++it;
- }
-
- savedModes.erase(found);
- return MODES_ERROR_NONE;
+ auto found = savedModes.find(id);
+ if (savedModes.end() == found) {
+ ERR("No Mode(%s)", id.c_str());
+ return MODES_ERROR_NO_DATA;
+ }
+
+ 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 == id)
+ it = essentialMap.erase(it);
+ else
+ ++it;
+ }
+
+ savedModes.erase(found);
+ return MODES_ERROR_NONE;
}
bool ModeCareTaker::isConflict(const Mode &mode)
{
- if (isSavedMode(mode.getID()))
- return true;
+ if (isSavedMode(mode.getID()))
+ return true;
- if (checkConflictAction(mode))
- return true;
+ if (checkConflictAction(mode))
+ return true;
- return false;
+ return false;
}
bool ModeCareTaker::isSavedMode(const std::string &id)
{
- auto found = savedModes.find(id);
- if (savedModes.end() != found) {
- INFO("Mode(%s) is Saved Mode", id.c_str());
- return true;
- }
+ auto found = savedModes.find(id);
+ if (savedModes.end() != found) {
+ INFO("Mode(%s) is Saved Mode", id.c_str());
+ return true;
+ }
- return false;
+ return false;
}
bool ModeCareTaker::findLockedAction(const std::string &ruleName)
{
- for (auto modeIt = savedModes.begin(); modeIt != savedModes.end(); modeIt++) {
- std::list<std::shared_ptr<Action>> actionList = (modeIt->second).getActionList();
-
- for (auto actionIt = actionList.begin(); actionIt != actionList.end(); actionIt++)
- if ((*actionIt)->getRuleName() == ruleName
- && (*actionIt)->getRestrict() == Action::LOCK) {
- ERR("%s is Locked", ruleName.c_str());
- return true;
- }
- }
-
- return false;
+ for (auto modeIt = savedModes.begin(); modeIt != savedModes.end(); modeIt++) {
+ std::list<std::shared_ptr<Action>> actionList = (modeIt->second).getActionList();
+
+ for (auto actionIt = actionList.begin(); actionIt != actionList.end(); actionIt++)
+ if ((*actionIt)->getRuleName() == ruleName
+ && (*actionIt)->getRestrict() == Action::LOCK) {
+ ERR("%s is Locked", ruleName.c_str());
+ return true;
+ }
+ }
+
+ return false;
}
void ModeCareTaker::update(int *key)
{
- Action *action = reinterpret_cast<Action*>(key);
- auto found = essentialMap.find(action);
- if (essentialMap.end() == found) {
- ERR("No Mode related with essential rule(%s)", action->getRuleName().c_str());
- return;
- }
-
- EssentialHandler::undoHandler(found->second);
+ Action *action = reinterpret_cast<Action *>(key);
+ auto found = essentialMap.find(action);
+ if (essentialMap.end() == found) {
+ ERR("No Mode related with essential rule(%s)", action->getRuleName().c_str());
+ return;
+ }
+
+ EssentialHandler::undoHandler(found->second);
}
void ModeCareTaker::realPushMode(const Mode &mode)
{
- savedModes.insert(std::pair<std::string, Mode>(mode.getID(), mode));
+ savedModes.insert(std::pair<std::string, Mode>(mode.getID(), mode));
- if (mode.hasEssential())
- handleEssentialAction(mode);
+ if (mode.hasEssential())
+ handleEssentialAction(mode);
}
bool ModeCareTaker::checkConflictAction(const Mode &mode)
{
- bool stopOnErr = false;
- std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
- for (auto it = actionList.begin(); it != actionList.end(); it++) {
- if (findLockedAction((*it)->getRuleName())) {
- (*it)->setLocked(true);
- if ((*it)->getStopOnErr())
- stopOnErr = true;
- }
- }
- return stopOnErr;
+ bool stopOnErr = false;
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+ for (auto it = actionList.begin(); it != actionList.end(); it++) {
+ if (findLockedAction((*it)->getRuleName())) {
+ (*it)->setLocked(true);
+ if ((*it)->getStopOnErr())
+ stopOnErr = true;
+ }
+ }
+ return stopOnErr;
}
void ModeCareTaker::handleEssentialAction(const Mode &mode)
{
- 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.getID()));
- if (true == (*it)->checkChanged()) {
- EssentialHandler::undoHandler(mode.getName());
- return;
- }
- (*it)->attachObserver(this);
- }
- }
+ 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.getID()));
+ if (true == (*it)->checkChanged()) {
+ EssentialHandler::undoHandler(mode.getName());
+ return;
+ }
+ (*it)->attachObserver(this);
+ }
+ }
}
#include <map>
#include <string>
-#include "mdss.h"
-#include "Mode.h"
+
#include "ActionObserver.h"
+#include "Mode.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ModeCareTaker : public ActionObserver {
-public:
- ModeCareTaker(const std::string &undoInfoDir);
- ~ModeCareTaker() = default;
+ public:
+ ModeCareTaker(const std::string &undoInfoDir);
+ ~ModeCareTaker() = default;
+
+ std::string getUndoInfoDir();
+ bool hasUndoInfo(const std::string &modeName);
+ void restoreMode(Mode &mode);
+ void pushMode(const Mode &mode);
+ int popMode(const std::string &name, Mode &mode);
+ bool isConflict(const Mode &mode);
+ bool isSavedMode(const std::string &name);
+ void update(int *key);
- std::string getUndoInfoDir();
- bool hasUndoInfo(const std::string &modeName);
- void restoreMode(Mode &mode);
- void pushMode(const Mode &mode);
- int popMode(const std::string &name, Mode &mode);
- bool isConflict(const Mode &mode);
- bool isSavedMode(const std::string &name);
- void update(int *key);
-private:
- void realPushMode(const Mode &mode);
- bool checkConflictAction(const Mode &mode);
- void handleEssentialAction(const Mode &mode);
- bool findLockedAction(const std::string &ruleName);
- std::map<std::string, Mode> savedModes;
- std::multimap<Action*, std::string> essentialMap;
- std::string undoDir;
+ private:
+ void realPushMode(const Mode &mode);
+ bool checkConflictAction(const Mode &mode);
+ void handleEssentialAction(const Mode &mode);
+ bool findLockedAction(const std::string &ruleName);
+ std::map<std::string, Mode> savedModes;
+ std::multimap<Action *, std::string> essentialMap;
+ std::string undoDir;
#ifdef MDS_TEST
- friend class ConflictTest;
+ friend class ConflictTest;
#endif
};
#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;
+ std::string id;
+ std::string name;
+ std::string path;
+ bool hidden;
+ int type;
+ int state;
};
MODES_NAMESPACE_END
#include "ModeManager.h"
#include <dirent.h>
+
#include <cstring>
-#include <utility>
-#include <string>
#include <exception>
-#include "mdss.h"
-#include "ModesEx.h"
+#include <string>
+#include <utility>
+
#include "ModeInfo.h"
#include "ModeObserver.h"
-#include "XMLGenerator.h"
#include "ModeXMLParser.h"
+#include "ModesEx.h"
+#include "XMLGenerator.h"
+#include "mdss.h"
using std::string;
MODES_NAMESPACE_USE;
ModeManager::ModeManager(const std::set<string> &modeDirs, const string &xsdFile, RuleManager &rMgr)
- : modeDirList(modeDirs), modeSyntaxFile(xsdFile),
- ruleMgr(rMgr), careTaker(MODES_UNDO_INFO_DEFAULT_DIR)
+ : modeDirList(modeDirs),
+ modeSyntaxFile(xsdFile),
+ ruleMgr(rMgr),
+ careTaker(MODES_UNDO_INFO_DEFAULT_DIR)
{
- modeDirList.insert(MODES_CUSTOM_MODE_DEFAULT_DIR);
+ modeDirList.insert(MODES_CUSTOM_MODE_DEFAULT_DIR);
}
void ModeManager::init()
{
- modeMap.clear();
+ modeMap.clear();
- for (auto it = modeDirList.begin(); it != modeDirList.end(); ++it) {
- makeModeMap(*it);
- DBG("Mode Directory(%s) added", it->c_str());
- }
+ for (auto it = modeDirList.begin(); it != modeDirList.end(); ++it) {
+ makeModeMap(*it);
+ DBG("Mode Directory(%s) added", it->c_str());
+ }
}
void ModeManager::addModeAttributes(ModeXMLParser &parser, const string &path)
{
- Mode mode = parser.getMode();
- ModeInfo info = { mode.getID(), mode.getName(), path, mode.isHidden(), mode.getModeType(), 0 };
- modeMap.insert(std::make_pair(mode.getID(), info));
+ Mode mode = parser.getMode();
+ ModeInfo info = {mode.getID(), mode.getName(), path, mode.isHidden(), mode.getModeType(), 0};
+ modeMap.insert(std::make_pair(mode.getID(), info));
- if (careTaker.hasUndoInfo(mode.getFileNameID()))
- careTaker.restoreMode(mode);
+ if (careTaker.hasUndoInfo(mode.getFileNameID()))
+ careTaker.restoreMode(mode);
- 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");
+ 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 &modeID, ClientPrivilege &priv, bool isTest)
{
- auto found = modeMap.find(modeID);
- if (modeMap.end() == found) {
- ERR("No Mode(%s)", modeID.c_str());
- return MODES_ERROR_NO_DATA;
- }
-
- 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.getID().c_str());
-
- int ret = priv.check(mode);
- if (MODES_ERROR_NONE != ret) {
- ERR("priv.check() Fail(%d)", ret);
- return ret;
- }
-
- if (careTaker.isConflict(mode)) {
- ERR("mode(%s) is conflict", mode.getID().c_str());
- return MODES_ERROR_CONFLICT;
- }
-
- if (isTest)
- return MODES_ERROR_NONE;
-
- if (Mode::MODE_ONESHOT == mode.getModeType()) {
- ret = mode.applyOneShot();
- if (MODES_ERROR_NONE != ret) {
- 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.getID().c_str());
- mode.undo();
- return ret;
- }
- careTaker.pushMode(mode);
- }
- } catch (ModesEx &e) {
- ERR("apply Fail(%s)", e.what());
-
- switch (e.getErrCode()) {
- case ModesEx::INVALID_ARG:
- //Ususally, it is reached by Invalid Mode File
- return MODES_ERROR_NO_DATA;
- case ModesEx::SYSTEM_ERROR:
- default:
- return MODES_ERROR_SYSTEM;
- }
- }
- notifyObservers(modeID, ModeObserver::ON);
- return MODES_ERROR_NONE;
+ auto found = modeMap.find(modeID);
+ if (modeMap.end() == found) {
+ ERR("No Mode(%s)", modeID.c_str());
+ return MODES_ERROR_NO_DATA;
+ }
+
+ 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.getID().c_str());
+
+ int ret = priv.check(mode);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("priv.check() Fail(%d)", ret);
+ return ret;
+ }
+
+ if (careTaker.isConflict(mode)) {
+ ERR("mode(%s) is conflict", mode.getID().c_str());
+ return MODES_ERROR_CONFLICT;
+ }
+
+ if (isTest)
+ return MODES_ERROR_NONE;
+
+ if (Mode::MODE_ONESHOT == mode.getModeType()) {
+ ret = mode.applyOneShot();
+ if (MODES_ERROR_NONE != ret) {
+ 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.getID().c_str());
+ mode.undo();
+ return ret;
+ }
+ careTaker.pushMode(mode);
+ }
+ } catch (ModesEx &e) {
+ ERR("apply Fail(%s)", e.what());
+
+ switch (e.getErrCode()) {
+ case ModesEx::INVALID_ARG:
+ // Ususally, it is reached by Invalid Mode File
+ return MODES_ERROR_NO_DATA;
+ case ModesEx::SYSTEM_ERROR:
+ default:
+ return MODES_ERROR_SYSTEM;
+ }
+ }
+ notifyObservers(modeID, ModeObserver::ON);
+ return MODES_ERROR_NONE;
}
int ModeManager::addMode(const Mode &mode)
{
- string path = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getFileNameID() + "_mode.xml";
- XMLGenerator xmlWriter;
-
- 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.getID().c_str());
- return MODES_ERROR_INVALID_PARAMETER;
- }
-
- try {
- xmlWriter.makeModeXML(path, mode);
- } catch (ModesEx &e) {
- ERR("XML generator Fail(%s)", e.what());
- modeMap.erase(result.first);
-
- switch (e.getErrCode()) {
- case ModesEx::INVALID_ARG:
- return MODES_ERROR_INVALID_PARAMETER;
- case ModesEx::SYSTEM_ERROR:
- default:
- return MODES_ERROR_SYSTEM;
- }
- }
-
- 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;
+ string path = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getFileNameID() + "_mode.xml";
+ XMLGenerator xmlWriter;
+
+ 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.getID().c_str());
+ return MODES_ERROR_INVALID_PARAMETER;
+ }
+
+ try {
+ xmlWriter.makeModeXML(path, mode);
+ } catch (ModesEx &e) {
+ ERR("XML generator Fail(%s)", e.what());
+ modeMap.erase(result.first);
+
+ switch (e.getErrCode()) {
+ case ModesEx::INVALID_ARG:
+ return MODES_ERROR_INVALID_PARAMETER;
+ case ModesEx::SYSTEM_ERROR:
+ default:
+ return MODES_ERROR_SYSTEM;
+ }
+ }
+
+ 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 &modeID)
{
- if (true == careTaker.isSavedMode(modeID)) {
- ERR("Mode(%s) is applied.", modeID.c_str());
- return MODES_ERROR_CONFLICT;
- }
+ if (true == careTaker.isSavedMode(modeID)) {
+ ERR("Mode(%s) is applied.", modeID.c_str());
+ return MODES_ERROR_CONFLICT;
+ }
- auto result = modeMap.find(modeID);
- if (result == modeMap.end()) {
- ERR("Invalid mode(%s), not found", modeID.c_str());
- return MODES_ERROR_INVALID_PARAMETER;
- }
+ auto result = modeMap.find(modeID);
+ if (result == modeMap.end()) {
+ ERR("Invalid mode(%s), not found", modeID.c_str());
+ return MODES_ERROR_INVALID_PARAMETER;
+ }
- 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.", modeID.c_str());
- return MODES_ERROR_INVALID_PARAMETER;
- }
+ 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.", modeID.c_str());
+ return MODES_ERROR_INVALID_PARAMETER;
+ }
- modeMap.erase(result);
+ modeMap.erase(result);
- if (0 != remove(path.c_str()))
- ERR("remove(%s) Fail(%d)", path.c_str(), errno);
+ if (0 != remove(path.c_str()))
+ ERR("remove(%s) Fail(%d)", path.c_str(), errno);
- DBG("[%zu]removeMode : ID(%s), Path(%s)", modeMap.size(), modeID.c_str(), path.c_str());
+ DBG("[%zu]removeMode : ID(%s), Path(%s)", modeMap.size(), modeID.c_str(), path.c_str());
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
int ModeManager::undoMode(const string &modeID, ClientPrivilege &priv)
{
- Mode mode;
- int ret = careTaker.popMode(modeID, mode);
- if (MODES_ERROR_NONE != ret) {
- ERR("popMode() Fail(%d)", ret);
- return ret;
- }
-
- ret = priv.check(mode);
- if (MODES_ERROR_NONE != ret) {
- ERR("priv.check() Fail(%d)", ret);
- return ret;
- }
-
- mode.undo();
- notifyObservers(modeID, ModeObserver::OFF);
-
- return MODES_ERROR_NONE;
+ Mode mode;
+ int ret = careTaker.popMode(modeID, mode);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("popMode() Fail(%d)", ret);
+ return ret;
+ }
+
+ ret = priv.check(mode);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("priv.check() Fail(%d)", ret);
+ return ret;
+ }
+
+ mode.undo();
+ notifyObservers(modeID, ModeObserver::OFF);
+
+ return MODES_ERROR_NONE;
}
int ModeManager::undoMode(const string &modeID)
{
- Mode mode;
- int ret = careTaker.popMode(modeID, mode);
- if (MODES_ERROR_NONE != ret) {
- ERR("popMode() Fail(%d)", ret);
- return ret;
- }
+ Mode mode;
+ int ret = careTaker.popMode(modeID, mode);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("popMode() Fail(%d)", ret);
+ return ret;
+ }
- mode.undo();
- notifyObservers(modeID, ModeObserver::OFF);
+ mode.undo();
+ notifyObservers(modeID, ModeObserver::OFF);
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
std::list<ModeInfo> ModeManager::getModes()
{
- std::list<ModeInfo> modeList;
+ std::list<ModeInfo> modeList;
- for (auto it = modeMap.begin(); it != modeMap.end(); ++it) {
- if (true == it->second.hidden)
- continue;
- it->second.state = careTaker.isSavedMode(it->first);
- modeList.push_back(it->second);
- }
+ for (auto it = modeMap.begin(); it != modeMap.end(); ++it) {
+ if (true == it->second.hidden)
+ continue;
+ it->second.state = careTaker.isSavedMode(it->first);
+ modeList.push_back(it->second);
+ }
- return modeList;
+ return modeList;
}
void ModeManager::attachObserver(ModeObserver *obs)
{
- observers.push_back(obs);
+ observers.push_back(obs);
}
void ModeManager::detachObserver(ModeObserver *obs)
{
- observers.remove(obs);
+ observers.remove(obs);
}
void ModeManager::notifyObservers(const string &modeID, ModeObserver::ModeState state)
{
- for (auto it = observers.begin(); it != observers.end(); ++it)
- (*it)->update(modeID, state);
+ for (auto it = observers.begin(); it != observers.end(); ++it)
+ (*it)->update(modeID, state);
}
bool ModeManager::makeModeMap(const string &dirPath)
{
- DBG("dirPath : [%s]", dirPath.c_str());
-
- DIR *dir;
- if ((dir = opendir(dirPath.c_str())) == NULL) {
- ERR("opendir(%s) Fail(%d)", dirPath.c_str(), errno);
- return false;
- }
-
- struct dirent *entry;
- while ((entry = readdir(dir)) != NULL) {
- string file(entry->d_name);
- const size_t suffixLen = sizeof(MODES_MODE_FILE_SUFFIX) - 1;
- if (file.length() < suffixLen
- || file.compare(file.length() - suffixLen, suffixLen, MODES_MODE_FILE_SUFFIX)) {
- continue;
- }
-
- string fileFullPath = dirPath + "/" + string(entry->d_name);
- try {
- ModeXMLParser modeParser(fileFullPath, ruleMgr);
- modeParser.validateMode(modeSyntaxFile);
- addModeAttributes(modeParser, fileFullPath);
- } catch (ModesEx &e) {
- ERR("parser(%s) Fail(%s)", fileFullPath.c_str(), e.what());
- } catch (std::invalid_argument &e) {
- ERR("parser Fail(%s)", e.what());
- }
- }
-
- closedir(dir);
- return true;
+ DBG("dirPath : [%s]", dirPath.c_str());
+
+ DIR *dir;
+ if ((dir = opendir(dirPath.c_str())) == NULL) {
+ ERR("opendir(%s) Fail(%d)", dirPath.c_str(), errno);
+ return false;
+ }
+
+ struct dirent *entry;
+ while ((entry = readdir(dir)) != NULL) {
+ string file(entry->d_name);
+ const size_t suffixLen = sizeof(MODES_MODE_FILE_SUFFIX) - 1;
+ if (file.length() < suffixLen
+ || file.compare(file.length() - suffixLen, suffixLen, MODES_MODE_FILE_SUFFIX)) {
+ continue;
+ }
+
+ string fileFullPath = dirPath + "/" + string(entry->d_name);
+ try {
+ ModeXMLParser modeParser(fileFullPath, ruleMgr);
+ modeParser.validateMode(modeSyntaxFile);
+ addModeAttributes(modeParser, fileFullPath);
+ } catch (ModesEx &e) {
+ ERR("parser(%s) Fail(%s)", fileFullPath.c_str(), e.what());
+ } catch (std::invalid_argument &e) {
+ ERR("parser Fail(%s)", e.what());
+ }
+ }
+
+ closedir(dir);
+ return true;
}
void ModeManager::addModeDirectory(const string &dirPath)
{
- auto result = modeDirList.find(dirPath);
- if (result != modeDirList.end())
- throw std::invalid_argument("Directory already exists(" + dirPath + ")");
+ auto result = modeDirList.find(dirPath);
+ if (result != modeDirList.end())
+ throw std::invalid_argument("Directory already exists(" + dirPath + ")");
- if (!makeModeMap(dirPath))
- throw std::invalid_argument("makeModeMap() Fail(" + dirPath + ")");
+ if (!makeModeMap(dirPath))
+ throw std::invalid_argument("makeModeMap() Fail(" + dirPath + ")");
- modeDirList.insert(dirPath);
+ modeDirList.insert(dirPath);
}
#pragma once
#include <map>
-#include <utility>
#include <set>
-#include "mdss.h"
+#include <utility>
+
+#include "ClientPrivilege.h"
+#include "ModeCareTaker.h"
#include "ModeInfo.h"
-#include "RuleManager.h"
#include "ModeObserver.h"
-#include "ModeCareTaker.h"
#include "ModeXMLParser.h"
-#include "ClientPrivilege.h"
+#include "RuleManager.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ModeManager {
-public:
- ModeManager(const std::set<std::string> &modeDirs, const std::string &xsdFile, RuleManager &rMgr);
-
- void init();
- void addModeDirectory(const std::string &dirPath);
- int applyMode(const std::string &modeName, ClientPrivilege &priv, bool isTest);
- int addMode(const Mode &mode);
- int removeMode(const std::string &modeName);
- int undoMode(const std::string &modeName);
- int undoMode(const std::string &modeName, ClientPrivilege &priv);
- std::list<ModeInfo> getModes();
- void attachObserver(ModeObserver *obs);
- void detachObserver(ModeObserver *obs);
-private:
- void notifyObservers(const std::string &modeName, ModeObserver::ModeState state);
- bool makeModeMap(const std::string &dirPath);
- void addModeAttributes(ModeXMLParser &parser, const std::string &path);
-
- std::map<std::string, ModeInfo> modeMap;
- std::set<std::string> modeDirList;
- std::string modeSyntaxFile;
- RuleManager &ruleMgr;
- ModeCareTaker careTaker;
- std::list<ModeObserver*> observers;
+ public:
+ ModeManager(const std::set<std::string> &modeDirs, const std::string &xsdFile,
+ RuleManager &rMgr);
+
+ void init();
+ void addModeDirectory(const std::string &dirPath);
+ int applyMode(const std::string &modeName, ClientPrivilege &priv, bool isTest);
+ int addMode(const Mode &mode);
+ int removeMode(const std::string &modeName);
+ int undoMode(const std::string &modeName);
+ int undoMode(const std::string &modeName, ClientPrivilege &priv);
+ std::list<ModeInfo> getModes();
+ void attachObserver(ModeObserver *obs);
+ void detachObserver(ModeObserver *obs);
+
+ private:
+ void notifyObservers(const std::string &modeName, ModeObserver::ModeState state);
+ bool makeModeMap(const std::string &dirPath);
+ void addModeAttributes(ModeXMLParser &parser, const std::string &path);
+
+ std::map<std::string, ModeInfo> modeMap;
+ std::set<std::string> modeDirList;
+ std::string modeSyntaxFile;
+ RuleManager &ruleMgr;
+ ModeCareTaker careTaker;
+ std::list<ModeObserver *> observers;
#ifdef MDS_TEST
- friend class ModeManagerTest;
+ friend class ModeManagerTest;
#endif
};
#pragma once
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ModeObserver {
-public:
- typedef enum {
- OFF = 0,
- ON = 1
- } ModeState;
- virtual void update(const std::string &mode, ModeState state) = 0;
+ public:
+ typedef enum { OFF = 0, ON = 1 } ModeState;
+ virtual void update(const std::string &mode, ModeState state) = 0;
};
MODES_NAMESPACE_END
* limitations under the License.
*/
#include "ModeXMLParser.h"
-#include <cstring>
-#include <string>
+
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
-#include "mdss.h"
+
+#include <cstring>
+#include <string>
+
#include "Mode.h"
#include "ModesEx.h"
+#include "ModesXMLTag.h"
#include "TAction.h"
#include "XMLParser.h"
-#include "ModesXMLTag.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
-
ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr)
- : XMLParser(modeFile), ruleMgr(rMgr)
+ : XMLParser(modeFile), ruleMgr(rMgr)
{
}
Mode ModeXMLParser::getMode()
{
- iterateElement(getRoot());
- return mode;
+ iterateElement(getRoot());
+ return mode;
}
void ModeXMLParser::validateMode(const std::string &xsd)
{
- try {
- validate(xsd);
- } catch (ModesEx &e) {
- ERR("validate() Fail(%s)", e.what());
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ try {
+ validate(xsd);
+ } catch (ModesEx &e) {
+ ERR("validate() Fail(%s)", e.what());
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
}
void ModeXMLParser::iterateElement(xmlNodePtr node)
{
- xmlNode *cur = NULL;
- for (cur = node; cur; cur = cur->next) {
- if (xmlIsBlankNode(cur))
- continue;
-
- if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::MODE)) {
- parseModeAttr(cur);
- } else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::ACTION)) {
- parseAction(cur);
- } else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::UNDO)) {
- parseUndo(cur);
- } else {
- DBG("Unhandled node : %s", node->name);
- }
-
- iterateElement(cur->children);
- }
+ xmlNode *cur = NULL;
+ for (cur = node; cur; cur = cur->next) {
+ if (xmlIsBlankNode(cur))
+ continue;
+
+ if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::MODE)) {
+ parseModeAttr(cur);
+ } else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::ACTION)) {
+ parseAction(cur);
+ } else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::UNDO)) {
+ parseUndo(cur);
+ } else {
+ DBG("Unhandled node : %s", node->name);
+ }
+
+ iterateElement(cur->children);
+ }
}
void ModeXMLParser::parseModeAttr(xmlNodePtr node)
{
- mode.setID(extractModeID(node));
- mode.setName(extractModeName(node));
- mode.setModeType(extractModeType(node));
- mode.setHidden(extractHidden(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);
+ return extractValueOfTag(node, ModesXMLTag::ID);
}
std::string ModeXMLParser::extractModeName(xmlNodePtr node)
{
- return extractValueOfTag(node, ModesXMLTag::NAME);
+ return extractValueOfTag(node, ModesXMLTag::NAME);
}
Mode::ModeType ModeXMLParser::extractModeType(xmlNodePtr node)
{
- std::string val = extractValueOfTag(node, ModesXMLTag::TYPE);
- Mode::ModeType type;
- if ("normal" == val)
- type = Mode::MODE_NORMAL;
- else
- type = Mode::MODE_ONESHOT;
- return type;
+ std::string val = extractValueOfTag(node, ModesXMLTag::TYPE);
+ Mode::ModeType type;
+ if ("normal" == val)
+ type = Mode::MODE_NORMAL;
+ else
+ type = Mode::MODE_ONESHOT;
+ return type;
}
bool ModeXMLParser::extractHidden(xmlNodePtr node)
{
- std::string hidden = extractValueOfTag(node, ModesXMLTag::HIDDEN);
- if ("true" == hidden)
- return true;
- else
- return false;
+ std::string hidden = extractValueOfTag(node, ModesXMLTag::HIDDEN);
+ if ("true" == hidden)
+ return true;
+ else
+ return false;
}
void ModeXMLParser::parseUndo(xmlNodePtr node)
{
- Action *action = parseActionInfo(node);
- mode.addUndo(action);
+ Action *action = parseActionInfo(node);
+ mode.addUndo(action);
}
void ModeXMLParser::parseActionAttr(xmlNodePtr node, Action *action)
{
- char *restictProp = (char*)xmlGetProp(node, ModesXMLTag::RESTRICT);
- action->setRestrict(Action::NONE);
- if (restictProp) {
- if (MDS_EQUAL == strcmp(restictProp, ModesXMLTag::RESTRICT_LOCK)) {
- action->setRestrict(Action::LOCK);
- } else if (MDS_EQUAL == strcmp(restictProp, ModesXMLTag::RESTRICT_ESSENTIAL)) {
- action->setRestrict(Action::ESSENTIAL);
- mode.setEssential(true);
- }
-
- xmlFree(restictProp);
- }
-
- xmlChar *stopOnErrProp = xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
- if (MDS_EQUAL == xmlStrcmp(stopOnErrProp, ModesXMLTag::TRUE))
- action->setStopOnErr(true);
- else
- action->setStopOnErr(false);
- xmlFree(stopOnErrProp);
-
- char *actionTypeProp = (char*)xmlGetProp(node, ModesXMLTag::TYPE);
- if (actionTypeProp && MDS_EQUAL == strcmp(actionTypeProp, "async"))
- action->setType(Action::ActionType::ASYNC);
- else
- action->setType(Action::ActionType::SYNC);
- xmlFree(actionTypeProp);
-
- if ((Action::ActionType::ASYNC == action->getType())
- && (true == action->getStopOnErr())) {
- ERR("Can NOT support stopOnErr in async");
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ char *restictProp = (char *)xmlGetProp(node, ModesXMLTag::RESTRICT);
+ action->setRestrict(Action::NONE);
+ if (restictProp) {
+ if (MDS_EQUAL == strcmp(restictProp, ModesXMLTag::RESTRICT_LOCK)) {
+ action->setRestrict(Action::LOCK);
+ } else if (MDS_EQUAL == strcmp(restictProp, ModesXMLTag::RESTRICT_ESSENTIAL)) {
+ action->setRestrict(Action::ESSENTIAL);
+ mode.setEssential(true);
+ }
+
+ xmlFree(restictProp);
+ }
+
+ xmlChar *stopOnErrProp = xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
+ if (MDS_EQUAL == xmlStrcmp(stopOnErrProp, ModesXMLTag::TRUE))
+ action->setStopOnErr(true);
+ else
+ action->setStopOnErr(false);
+ xmlFree(stopOnErrProp);
+
+ char *actionTypeProp = (char *)xmlGetProp(node, ModesXMLTag::TYPE);
+ if (actionTypeProp && MDS_EQUAL == strcmp(actionTypeProp, "async"))
+ action->setType(Action::ActionType::ASYNC);
+ else
+ action->setType(Action::ActionType::SYNC);
+ xmlFree(actionTypeProp);
+
+ if ((Action::ActionType::ASYNC == action->getType()) && (true == action->getStopOnErr())) {
+ ERR("Can NOT support stopOnErr in async");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
}
void ModeXMLParser::parseAction(xmlNodePtr node)
{
- Action *action = parseActionInfo(node);
- mode.addAction(action);
+ Action *action = parseActionInfo(node);
+ mode.addAction(action);
}
-Action* ModeXMLParser::parseActionInfo(xmlNodePtr node)
+Action *ModeXMLParser::parseActionInfo(xmlNodePtr node)
{
- char *ruleName = (char*)xmlGetProp(node, ModesXMLTag::RULE);
- if (ruleName == NULL) {
- ERR("rule attribute is null! [%s]", ModesXMLTag::RULE);
- throw ModesEx(ModesEx::PARSER_ERROR, "rule attribute is null!");
- }
-
- Action *action = ruleMgr.createAction(ruleName);
- if (action == nullptr) {
- ERR("ruleMgr createAction(%s) Fail", ruleName);
- xmlFree(ruleName);
- throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
- }
- xmlFree(ruleName);
-
- parseActionAttr(node, action);
-
- char *nodeContent = (char*)xmlNodeGetContent(node);
- if (nodeContent == NULL)
- ERR("Node Content is null!");
-
- int ret = action->setValue(nodeContent ? nodeContent : "");
- xmlFree(nodeContent);
-
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) setValue() Fail(%d)", action->getRuleName().c_str(), ret);
- throw ModesEx(ModesEx::PARSER_ERROR, "Invalid Action Value");
- }
-
- action->printInfo();
- return action;
+ char *ruleName = (char *)xmlGetProp(node, ModesXMLTag::RULE);
+ if (ruleName == NULL) {
+ ERR("rule attribute is null! [%s]", ModesXMLTag::RULE);
+ throw ModesEx(ModesEx::PARSER_ERROR, "rule attribute is null!");
+ }
+
+ Action *action = ruleMgr.createAction(ruleName);
+ if (action == nullptr) {
+ ERR("ruleMgr createAction(%s) Fail", ruleName);
+ xmlFree(ruleName);
+ throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
+ }
+ xmlFree(ruleName);
+
+ parseActionAttr(node, action);
+
+ char *nodeContent = (char *)xmlNodeGetContent(node);
+ if (nodeContent == NULL)
+ ERR("Node Content is null!");
+
+ int ret = action->setValue(nodeContent ? nodeContent : "");
+ xmlFree(nodeContent);
+
+ if (MODES_ERROR_NONE != ret) {
+ ERR("Action(%s) setValue() Fail(%d)", action->getRuleName().c_str(), ret);
+ throw ModesEx(ModesEx::PARSER_ERROR, "Invalid Action Value");
+ }
+
+ action->printInfo();
+ return action;
}
#pragma once
#include <libxml/tree.h>
-#include "mdss.h"
+
#include "Mode.h"
-#include "XMLParser.h"
#include "RuleManager.h"
+#include "XMLParser.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ModeXMLParser : public XMLParser {
-public:
- ModeXMLParser(const std::string &modeFile, RuleManager &mgr);
- ~ModeXMLParser() = default;
-
- Mode getMode();
- void validateMode(const std::string &xsd);
-
-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);
- void parseAction(xmlNodePtr node);
- void parseUndo(xmlNodePtr node);
- Action* parseActionInfo(xmlNodePtr node);
- void iterateElement(xmlNodePtr node);
-
- Mode mode;
- std::string filePath;
- RuleManager &ruleMgr;
+ public:
+ ModeXMLParser(const std::string &modeFile, RuleManager &mgr);
+ ~ModeXMLParser() = default;
+
+ Mode getMode();
+ void validateMode(const std::string &xsd);
+
+ 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);
+ void parseAction(xmlNodePtr node);
+ void parseUndo(xmlNodePtr node);
+ Action *parseActionInfo(xmlNodePtr node);
+ void iterateElement(xmlNodePtr node);
+
+ Mode mode;
+ std::string filePath;
+ RuleManager &ruleMgr;
};
MODES_NAMESPACE_END
#include <set>
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
struct ModesConfig {
- std::string pluginDir;
- std::set<std::string> modeXMLDirs;
- std::string actionRuleDir;
+ std::string pluginDir;
+ std::set<std::string> modeXMLDirs;
+ std::string actionRuleDir;
};
MODES_NAMESPACE_END
#include "ModesEx.h"
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_USE;
-ModesEx::ModesEx(ErrCode code)
- :err(code)
+ModesEx::ModesEx(ErrCode code) : err(code)
{
}
-ModesEx::ModesEx(ErrCode code, const std::string &msg)
- : err(code), extraMsg(msg)
+ModesEx::ModesEx(ErrCode code, const std::string &msg) : err(code), extraMsg(msg)
{
}
ModesEx::ErrCode ModesEx::getErrCode()
{
- return err;
+ return err;
}
std::string ModesEx::getExtraMsg()
{
- return extraMsg;
+ return extraMsg;
}
const char* ModesEx::what() const throw()
{
- switch (err) {
- case INVALID_ARG:
- return "Invalid Argument";
- case PARSER_ERROR:
- return "Parser Module Fail";
- case DBUS_ERROR:
- return "Dbus Fail";
- case SYSTEM_ERROR:
- return "System Fail";
- case NO_DATA:
- return "No data found";
- default:
- return "Unknown Error";
- }
+ switch (err) {
+ case INVALID_ARG:
+ return "Invalid Argument";
+ case PARSER_ERROR:
+ return "Parser Module Fail";
+ case DBUS_ERROR:
+ return "Dbus Fail";
+ case SYSTEM_ERROR:
+ return "System Fail";
+ case NO_DATA:
+ return "No data found";
+ default:
+ return "Unknown Error";
+ }
}
*/
#pragma once
-#include <string>
#include <exception>
+#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
-class ModesEx: public std::exception {
-public:
- typedef enum {
- INVALID_ARG,
- PARSER_ERROR,
- DBUS_ERROR,
- SYSTEM_ERROR,
- NO_DATA
- } ErrCode;
-
- ModesEx(ErrCode code);
- ModesEx(ErrCode code, const std::string &msg);
-
- ErrCode getErrCode();
- std::string getExtraMsg();
- virtual const char* what() const throw() override;
-private:
- ErrCode err;
- std::string extraMsg;
+class ModesEx : public std::exception {
+ public:
+ typedef enum { INVALID_ARG, PARSER_ERROR, DBUS_ERROR, SYSTEM_ERROR, NO_DATA } ErrCode;
+
+ ModesEx(ErrCode code);
+ ModesEx(ErrCode code, const std::string& msg);
+
+ ErrCode getErrCode();
+ std::string getExtraMsg();
+ virtual const char* what() const throw() override;
+
+ private:
+ ErrCode err;
+ std::string extraMsg;
};
MODES_NAMESPACE_END
MODES_NAMESPACE_USE;
-//common
+// common
const xmlChar* const ModesXMLTag::XML_VERSION = (xmlChar*)"1.0";
const xmlChar* const ModesXMLTag::XML_ENCODING = (xmlChar*)"utf-8";
const xmlChar* const ModesXMLTag::TIZENMODES = (xmlChar*)"tizenModes";
const xmlChar* const ModesXMLTag::TRUE = (xmlChar*)"true";
const xmlChar* const ModesXMLTag::FALSE = (xmlChar*)"false";
const xmlChar* const ModesXMLTag::ID = (xmlChar*)"ID";
-//Mode
+// Mode
const xmlChar* const ModesXMLTag::MODE = (xmlChar*)"mode";
const xmlChar* const ModesXMLTag::NAME = (xmlChar*)"name";
const xmlChar* const ModesXMLTag::HIDDEN = (xmlChar*)"hidden";
-//Action
+// Action
const xmlChar* const ModesXMLTag::ACTION = (xmlChar*)"action";
const xmlChar* const ModesXMLTag::UNDO = (xmlChar*)"undo";
const xmlChar* const ModesXMLTag::RULE = (xmlChar*)"rule";
const xmlChar* const ModesXMLTag::RESTRICT = (xmlChar*)"restrict";
const char* const ModesXMLTag::RESTRICT_LOCK = "lock";
const char* const ModesXMLTag::RESTRICT_ESSENTIAL = "essential";
-//UndoInfo
+// UndoInfo
const xmlChar* const ModesXMLTag::UNDO_INFO = (xmlChar*)"UndoInfo";
const xmlChar* const ModesXMLTag::INFO = (xmlChar*)"info";
const xmlChar* const ModesXMLTag::IGNORE = (xmlChar*)"ignore";
#pragma once
#include <libxml/tree.h>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
struct ModesXMLTag {
- //common
- static const xmlChar* const XML_VERSION;
- static const xmlChar* const XML_ENCODING;
- static const xmlChar* const TIZENMODES;
- static const xmlChar* const XMLNS;
- static const xmlChar* const XMLNS_STR;
- static const xmlChar* const VERSION;
- static const xmlChar* const CUR_VERSION;
- static const xmlChar* const TYPE;
- static const xmlChar* const TRUE;
- static const xmlChar* const FALSE;
- static const xmlChar* const ID;
+ // common
+ static const xmlChar* const XML_VERSION;
+ static const xmlChar* const XML_ENCODING;
+ static const xmlChar* const TIZENMODES;
+ static const xmlChar* const XMLNS;
+ static const xmlChar* const XMLNS_STR;
+ static const xmlChar* const VERSION;
+ static const xmlChar* const CUR_VERSION;
+ 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;
- static const xmlChar* const NAME;
- static const xmlChar* const HIDDEN;
- //Action
- static const xmlChar* const ACTION;
- static const xmlChar* const UNDO;
- static const xmlChar* const RULE;
- static const xmlChar* const STOP_ON_ERR;
- static const xmlChar* const RESTRICT;
- static const char* const RESTRICT_LOCK;
- static const char* const RESTRICT_ESSENTIAL;
- //UndoInfo
- static const xmlChar* const UNDO_INFO;
- static const xmlChar* const INFO;
- static const xmlChar* const IGNORE;
+ // Mode
+ static const xmlChar* const MODE;
+ static const xmlChar* const NAME;
+ static const xmlChar* const HIDDEN;
+ // Action
+ static const xmlChar* const ACTION;
+ static const xmlChar* const UNDO;
+ static const xmlChar* const RULE;
+ static const xmlChar* const STOP_ON_ERR;
+ static const xmlChar* const RESTRICT;
+ static const char* const RESTRICT_LOCK;
+ static const char* const RESTRICT_ESSENTIAL;
+ // UndoInfo
+ static const xmlChar* const UNDO_INFO;
+ static const xmlChar* const INFO;
+ static const xmlChar* const IGNORE;
};
MODES_NAMESPACE_END
*/
#include "PluginMapper.h"
-#include <stdlib.h>
-#include <string.h>
#include <dirent.h>
-#include <errno.h>
#include <dlfcn.h>
-#include "mdss.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "ModesEx.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
#define EMPTY_PLUGIN_PAIR std::make_pair(nullptr, nullptr)
-PluginMapper::PluginMapper(const std::string &dirPath)
- : pluginDir(dirPath)
+PluginMapper::PluginMapper(const std::string &dirPath) : pluginDir(dirPath)
{
}
int PluginMapper::loadPlugins()
{
- DIR *dir;
- if ((dir = opendir(pluginDir.c_str())) == nullptr) {
- ERR("opendir(%s) Fail(%d)", pluginDir.c_str(), errno);
- throw ModesEx(ModesEx::SYSTEM_ERROR);
- }
-
- struct dirent *entry;
- while ((entry = readdir(dir)) != NULL) {
- std::string file(entry->d_name);
- //library name validation check
- if (std::string::npos == file.find(MODES_PLUGIN_LIB_PREFIX))
- continue;
-
- std::string fileFullPath = pluginDir + "/" + file;
- try {
- PluginPair pluginPair = loadClass(fileFullPath);
- DBG("loadClass(%s) OK", pluginPair.second->getName().c_str());
-
- pluginMap[pluginPair.second->getName()] = pluginPair;
- }
- catch (ModesEx &e) {
- ERR("loadClass(%s) Fail", fileFullPath.c_str());
- }
- }
-
- closedir(dir);
-
- if (pluginMap.empty())
- return MODES_ERROR_NO_DATA;
-
- return MODES_ERROR_NONE;
+ DIR *dir;
+ if ((dir = opendir(pluginDir.c_str())) == nullptr) {
+ ERR("opendir(%s) Fail(%d)", pluginDir.c_str(), errno);
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
+ struct dirent *entry;
+ while ((entry = readdir(dir)) != NULL) {
+ std::string file(entry->d_name);
+ // library name validation check
+ if (std::string::npos == file.find(MODES_PLUGIN_LIB_PREFIX))
+ continue;
+
+ std::string fileFullPath = pluginDir + "/" + file;
+ try {
+ PluginPair pluginPair = loadClass(fileFullPath);
+ DBG("loadClass(%s) OK", pluginPair.second->getName().c_str());
+
+ pluginMap[pluginPair.second->getName()] = pluginPair;
+ } catch (ModesEx &e) {
+ ERR("loadClass(%s) Fail", fileFullPath.c_str());
+ }
+ }
+
+ closedir(dir);
+
+ if (pluginMap.empty())
+ return MODES_ERROR_NO_DATA;
+
+ return MODES_ERROR_NONE;
}
PluginMapper::PluginPair PluginMapper::loadClass(const std::string &pluginFile)
{
- void *handle = dlopen(pluginFile.c_str(), RTLD_LAZY | RTLD_LOCAL);
- if (NULL == handle) {
- ERR("dlopen(%s) Fail(%s)", pluginFile.c_str(), dlerror());
- throw ModesEx(ModesEx::SYSTEM_ERROR);
- }
-
- /* load the symbols */
- createFunc newPlugin = (createFunc)dlsym(handle, "objectCreate");
- if (nullptr == newPlugin) {
- ERR("dlsym(objectCreate) Fail(Plugin[%s] error[%s])", pluginFile.c_str(), dlerror());
- dlclose(handle);
- throw ModesEx(ModesEx::SYSTEM_ERROR);
- }
-
- /* create an instance of the class */
- Plugin *object = newPlugin();
- if (nullptr == object) {
- ERR("create_object_func(%s) Fail", pluginFile.c_str());
- dlclose(handle);
- throw ModesEx(ModesEx::SYSTEM_ERROR);
- }
-
- return std::make_pair(handle, object);
+ void *handle = dlopen(pluginFile.c_str(), RTLD_LAZY | RTLD_LOCAL);
+ if (NULL == handle) {
+ ERR("dlopen(%s) Fail(%s)", pluginFile.c_str(), dlerror());
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
+ /* load the symbols */
+ createFunc newPlugin = (createFunc)dlsym(handle, "objectCreate");
+ if (nullptr == newPlugin) {
+ ERR("dlsym(objectCreate) Fail(Plugin[%s] error[%s])", pluginFile.c_str(), dlerror());
+ dlclose(handle);
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
+ /* create an instance of the class */
+ Plugin *object = newPlugin();
+ if (nullptr == object) {
+ ERR("create_object_func(%s) Fail", pluginFile.c_str());
+ dlclose(handle);
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
+ return std::make_pair(handle, object);
}
int PluginMapper::unloadClass(const PluginPair &pluginPair)
{
- void *handle = pluginPair.first;
- Plugin *plugin = pluginPair.second;
- std::string pluginName = plugin->getName();
+ void *handle = pluginPair.first;
+ Plugin *plugin = pluginPair.second;
+ std::string pluginName = plugin->getName();
- RETVM_IF(nullptr == handle, MODES_ERROR_SYSTEM, "No handle(%s)", pluginName.c_str());
+ RETVM_IF(nullptr == handle, MODES_ERROR_SYSTEM, "No handle(%s)", pluginName.c_str());
- destroyFunc deletePlugin = (destroyFunc)dlsym(handle, "objectDelete");
- if (nullptr == deletePlugin) {
- ERR("dlsym(objectDelete) Fail(plugin[%s] error[%s])", pluginName.c_str(), dlerror());
- dlclose(handle);
- return MODES_ERROR_SYSTEM;
- }
+ destroyFunc deletePlugin = (destroyFunc)dlsym(handle, "objectDelete");
+ if (nullptr == deletePlugin) {
+ ERR("dlsym(objectDelete) Fail(plugin[%s] error[%s])", pluginName.c_str(), dlerror());
+ dlclose(handle);
+ return MODES_ERROR_SYSTEM;
+ }
- deletePlugin(plugin);
- dlclose(handle);
+ deletePlugin(plugin);
+ dlclose(handle);
- return MODES_ERROR_NONE;
+ return MODES_ERROR_NONE;
}
-
int PluginMapper::unloadPlugins()
{
- int ret = MODES_ERROR_NONE;
-
- for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) {
- int rc = unloadClass(it->second);
- if (rc != MODES_ERROR_NONE) {
- ERR("unloadClass(%s) Fail", (it->first).c_str());
- ret = MODES_ERROR_SYSTEM;
- }
- }
- pluginMap.clear();
-
- return ret;
+ int ret = MODES_ERROR_NONE;
+
+ for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) {
+ int rc = unloadClass(it->second);
+ if (rc != MODES_ERROR_NONE) {
+ ERR("unloadClass(%s) Fail", (it->first).c_str());
+ ret = MODES_ERROR_SYSTEM;
+ }
+ }
+ pluginMap.clear();
+
+ return ret;
}
std::list<std::string> PluginMapper::getPluginList()
{
- std::list<std::string> list;
- for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) {
- list.push_back(it->first);
- }
+ std::list<std::string> list;
+ for (auto it = pluginMap.begin(); it != pluginMap.end(); ++it) {
+ list.push_back(it->first);
+ }
- return list;
+ return list;
}
-Plugin* PluginMapper::getPlugin(std::string name)
+Plugin *PluginMapper::getPlugin(std::string name)
{
- return pluginMap[name].second;
+ return pluginMap[name].second;
}
#pragma once
#include <iostream>
-#include <new>
#include <list>
-#include <utility>
+#include <new>
#include <unordered_map>
-#include "mdss.h"
+#include <utility>
+
#include "ModesPlugin.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class PluginMapper {
-public:
- PluginMapper(const std::string &dirPath);
+ public:
+ PluginMapper(const std::string &dirPath);
- int loadPlugins();
- int unloadPlugins();
+ int loadPlugins();
+ int unloadPlugins();
- std::list<std::string> getPluginList();
- Plugin* getPlugin(std::string name);
+ std::list<std::string> getPluginList();
+ Plugin *getPlugin(std::string name);
- /*addDirChangeNotifier(); */
- /*dirChangeNotifierCallBack(); */
-private:
- typedef std::pair<void*, Plugin*> PluginPair;
+ /*addDirChangeNotifier(); */
+ /*dirChangeNotifierCallBack(); */
+ private:
+ typedef std::pair<void *, Plugin *> PluginPair;
- PluginPair loadClass(const std::string &pluginFile);
- int unloadClass(const PluginPair &pluginPair);
+ PluginPair loadClass(const std::string &pluginFile);
+ int unloadClass(const PluginPair &pluginPair);
- std::string pluginDir;
- std::unordered_map<std::string, PluginPair> pluginMap;
+ std::string pluginDir;
+ std::unordered_map<std::string, PluginPair> pluginMap;
#ifdef MDS_TEST
- friend class TestPluginBroker;
+ friend class TestPluginBroker;
#endif
};
#include <gcov.h>
}
#endif
-#include "mdss.h"
+#include "ClientPrivilege.h"
#include "ModesEx.h"
#include "common/dbus_def.h"
-#include "ClientPrivilege.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
void RequestHandler::setModeManager(ModeManager *mgr)
{
- modeMgr = mgr;
+ modeMgr = mgr;
}
void RequestHandler::setRuleManager(RuleManager *mgr)
{
- ruleMgr = mgr;
+ ruleMgr = mgr;
}
gboolean RequestHandler::canApplyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeID, gpointer userData)
+ const gchar *modeID, gpointer userData)
{
- RETV_IF(NULL == modeMgr, FALSE);
+ RETV_IF(NULL == modeMgr, FALSE);
- DBG("mode ID = %s", modeID);
+ DBG("mode ID = %s", modeID);
- ClientPrivilege privInfo(invocation);
- int ret = modeMgr->applyMode(modeID, privInfo, true);
+ ClientPrivilege privInfo(invocation);
+ int ret = modeMgr->applyMode(modeID, privInfo, true);
- mds_dbus_complete_can_apply(object, invocation, ret);
+ mds_dbus_complete_can_apply(object, invocation, ret);
#ifdef TIZEN_TEST_GCOV
- __gcov_flush();
+ __gcov_flush();
#endif
- return TRUE;
+ return TRUE;
}
gboolean RequestHandler::applyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeID, gpointer userData)
+ const gchar *modeID, gpointer userData)
{
- RETV_IF(NULL == modeMgr, FALSE);
- RETV_IF(NULL == modeID, FALSE);
+ RETV_IF(NULL == modeMgr, FALSE);
+ RETV_IF(NULL == modeID, FALSE);
- DBG("mode name = %s", modeID);
+ DBG("mode name = %s", modeID);
- ClientPrivilege privInfo(invocation);
- int ret = modeMgr->applyMode(modeID, privInfo, false);
+ ClientPrivilege privInfo(invocation);
+ int ret = modeMgr->applyMode(modeID, privInfo, false);
- mds_dbus_complete_apply_mode(object, invocation, ret);
+ mds_dbus_complete_apply_mode(object, invocation, ret);
#ifdef TIZEN_TEST_GCOV
- __gcov_flush();
+ __gcov_flush();
#endif
- return TRUE;
+ return TRUE;
}
gboolean RequestHandler::undoModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeID, gpointer userData)
+ const gchar *modeID, gpointer userData)
{
- RETV_IF(NULL == modeMgr, FALSE);
- RETV_IF(NULL == modeID, FALSE);
+ RETV_IF(NULL == modeMgr, FALSE);
+ RETV_IF(NULL == modeID, FALSE);
- DBG("mode ID = %s", modeID);
+ DBG("mode ID = %s", modeID);
- ClientPrivilege privInfo(invocation);
- int ret = modeMgr->undoMode(modeID, privInfo);
+ ClientPrivilege privInfo(invocation);
+ int ret = modeMgr->undoMode(modeID, privInfo);
- mds_dbus_complete_undo_mode(object, invocation, ret);
+ mds_dbus_complete_undo_mode(object, invocation, ret);
#ifdef TIZEN_TEST_GCOV
- __gcov_flush();
+ __gcov_flush();
#endif
- return TRUE;
+ return TRUE;
}
gboolean RequestHandler::addModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- GVariant *modeData, gpointer userData)
+ GVariant *modeData, gpointer userData)
{
- RETV_IF(NULL == modeMgr, FALSE);
- RETV_IF(NULL == modeData, FALSE);
-
- try {
- Mode mode = getModefromData(modeData);
- int ret = modeMgr->addMode(mode);
- mds_dbus_complete_add_mode(object, invocation, ret);
- } catch (ModesEx &e) {
- mds_dbus_complete_add_mode(object,
- invocation, MODES_ERROR_INVALID_PARAMETER);
- }
+ RETV_IF(NULL == modeMgr, FALSE);
+ RETV_IF(NULL == modeData, FALSE);
+
+ try {
+ Mode mode = getModefromData(modeData);
+ int ret = modeMgr->addMode(mode);
+ mds_dbus_complete_add_mode(object, invocation, ret);
+ } catch (ModesEx &e) {
+ mds_dbus_complete_add_mode(object, invocation, MODES_ERROR_INVALID_PARAMETER);
+ }
#ifdef TIZEN_TEST_GCOV
- __gcov_flush();
+ __gcov_flush();
#endif
- return TRUE;
+ return TRUE;
}
gboolean RequestHandler::removeModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeID, gpointer userData)
+ const gchar *modeID, gpointer userData)
{
- RETV_IF(NULL == modeMgr, FALSE);
- RETV_IF(NULL == modeID, FALSE);
+ RETV_IF(NULL == modeMgr, FALSE);
+ RETV_IF(NULL == modeID, FALSE);
- int ret = modeMgr->removeMode(modeID);
- mds_dbus_complete_remove_mode(object, invocation, ret);
+ int ret = modeMgr->removeMode(modeID);
+ mds_dbus_complete_remove_mode(object, invocation, ret);
- return TRUE;
+ return TRUE;
}
-gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation, gpointer userData)
+gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ gpointer userData)
{
- int ret = MODES_ERROR_NONE;
+ int ret = MODES_ERROR_NONE;
- RETV_IF(NULL == modeMgr, FALSE);
+ RETV_IF(NULL == modeMgr, FALSE);
- std::list<ModeInfo> modeList = modeMgr->getModes();
- if (modeList.empty()) {
- ERR("getModes() : No Data");
- ret = MODES_ERROR_NO_DATA;
- }
+ std::list<ModeInfo> modeList = modeMgr->getModes();
+ if (modeList.empty()) {
+ ERR("getModes() : No Data");
+ ret = MODES_ERROR_NO_DATA;
+ }
- GVariantBuilder *modeListBuilder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_GET_MODES_SIG));
- for (auto it = modeList.begin(); it != modeList.end(); ++it) {
- g_variant_builder_add(modeListBuilder, MODES_DBUS_GET_MODES_MODE_SIG, it->id.c_str(),
- it->name.c_str(), it->type, it->state);
- }
+ GVariantBuilder *modeListBuilder =
+ g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_GET_MODES_SIG));
+ for (auto it = modeList.begin(); it != modeList.end(); ++it) {
+ 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);
- g_variant_builder_unref(modeListBuilder);
+ GVariant *outList = g_variant_new(MODES_DBUS_GET_MODES_SIG, modeListBuilder);
+ g_variant_builder_unref(modeListBuilder);
- mds_dbus_complete_get_modes(object, invocation, outList, ret);
+ mds_dbus_complete_get_modes(object, invocation, outList, ret);
#ifdef TIZEN_TEST_GCOV
- __gcov_flush();
+ __gcov_flush();
#endif
- return TRUE;
+ return TRUE;
}
Mode RequestHandler::getModefromData(GVariant *inData)
{
- GVariant *actionList;
- gchar *modeID, *modeName;
- gchar *id, *actName, *value;
- gint32 type;
- GVariantIter *iter;
- Mode mode;
- Mode::ModeType modeType;
- gboolean modeHidden;
-
- 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:
- modeType = Mode::MODE_NORMAL;
- break;
- // Exclusive mode is not allowed on making by user.
- //case MODES_TYPE_MODE_EXCLUSIVE:
- // type = MODE_EXCLUSIVE;
- // break;
- case MODES_TYPE_MODE_ONESHOT:
- default:
- 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);
-
- try {
- while (g_variant_iter_loop(iter, MODES_DBUS_ACTION_SIG, &id, &actName, &value)) {
- DBG("id(%s) action_name(%s) value(%s)", id[0] != '\0' ? id : "NULL", actName, value);
-
- Action *action = createAction(id, actName, value);
-
- mode.addAction(action);
- }
- } catch (ModesEx &e) {
- ERR("createAction(%s, %s, %s) Fail(%s)", id, actName, value, e.what());
- g_variant_iter_free(iter);
- g_variant_unref(actionList);
- //g_variant_iter_loop() need to free at breaking out of this loop
- free(id);
- free(actName);
- free(value);
- throw ModesEx(ModesEx::INVALID_ARG, "Action is null!");
- }
- g_variant_iter_free(iter);
- g_variant_unref(actionList);
-
- return mode;
+ GVariant *actionList;
+ gchar *modeID, *modeName;
+ gchar *id, *actName, *value;
+ gint32 type;
+ GVariantIter *iter;
+ Mode mode;
+ Mode::ModeType modeType;
+ gboolean modeHidden;
+
+ 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:
+ modeType = Mode::MODE_NORMAL;
+ break;
+ // Exclusive mode is not allowed on making by user.
+ // case MODES_TYPE_MODE_EXCLUSIVE:
+ // type = MODE_EXCLUSIVE;
+ // break;
+ case MODES_TYPE_MODE_ONESHOT:
+ default:
+ 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);
+
+ try {
+ while (g_variant_iter_loop(iter, MODES_DBUS_ACTION_SIG, &id, &actName, &value)) {
+ DBG("id(%s) action_name(%s) value(%s)", id[0] != '\0' ? id : "NULL", actName, value);
+
+ Action *action = createAction(id, actName, value);
+
+ mode.addAction(action);
+ }
+ } catch (ModesEx &e) {
+ ERR("createAction(%s, %s, %s) Fail(%s)", id, actName, value, e.what());
+ g_variant_iter_free(iter);
+ g_variant_unref(actionList);
+ // g_variant_iter_loop() need to free at breaking out of this loop
+ free(id);
+ free(actName);
+ free(value);
+ throw ModesEx(ModesEx::INVALID_ARG, "Action is null!");
+ }
+ g_variant_iter_free(iter);
+ g_variant_unref(actionList);
+
+ return mode;
}
-Action* RequestHandler::createAction(char *id, char *ruleName, char *val)
+Action *RequestHandler::createAction(char *id, char *ruleName, char *val)
{
- std::string pluginName;
+ std::string pluginName;
- Action *action = ruleMgr->createAction(ruleName);
- if (action == nullptr) {
- ERR("Action is null");
- throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
- }
+ Action *action = ruleMgr->createAction(ruleName);
+ if (action == nullptr) {
+ ERR("Action is null");
+ throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
+ }
- if (id)
- action->setID(id);
- action->setRestrict(Action::NONE); //It is not allowed to set Restrict of Action by API.
- action->setValue(val);
+ if (id)
+ action->setID(id);
+ action->setRestrict(Action::NONE); // It is not allowed to set Restrict of Action by API.
+ action->setValue(val);
- action->printInfo();
+ action->printInfo();
- return action;
+ return action;
}
*/
#pragma once
-#include "mdss.h"
-#include "common/dbus.h"
#include "ModeManager.h"
#include "RuleManager.h"
+#include "common/dbus.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class RequestHandler {
-public:
- static gboolean canApplyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeName, gpointer userData);
- static gboolean applyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeName, gpointer userData);
- static gboolean undoModeHandler(mdsDbus * object, GDBusMethodInvocation *invocation,
- const gchar *modeName, gpointer userData);
- static gboolean addModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- GVariant *arg_modeData, gpointer userData);
- static gboolean removeModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- const gchar *modeName, gpointer userData);
- static gboolean getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
- gpointer userData);
+ public:
+ static gboolean canApplyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ const gchar *modeName, gpointer userData);
+ static gboolean applyModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ const gchar *modeName, gpointer userData);
+ static gboolean undoModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ const gchar *modeName, gpointer userData);
+ static gboolean addModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ GVariant *arg_modeData, gpointer userData);
+ static gboolean removeModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ const gchar *modeName, gpointer userData);
+ static gboolean getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+ gpointer userData);
- static void setModeManager(ModeManager *mgr);
- static void setRuleManager(RuleManager *mgr);
+ static void setModeManager(ModeManager *mgr);
+ static void setRuleManager(RuleManager *mgr);
-private:
- static Mode getModefromData(GVariant *inData);
- static Action* createAction(char *id, char *act_name, char *contents);
+ private:
+ static Mode getModefromData(GVariant *inData);
+ static Action *createAction(char *id, char *act_name, char *contents);
- static ModeManager *modeMgr;
- static RuleManager *ruleMgr;
+ static ModeManager *modeMgr;
+ static RuleManager *ruleMgr;
};
MODES_NAMESPACE_END
#include "RuleManager.h"
#include <dirent.h>
+
#include <cstring>
-#include "mdss.h"
-#include "TActionRule.h"
+
#include "ModesEx.h"
+#include "TActionRule.h"
+#include "mdss.h"
using std::string;
MODES_NAMESPACE_USE;
-const xmlChar* const RuleManager::ACTION_RULE_TAG = (xmlChar*)"actionRule";
-const xmlChar* const RuleManager::ACTION_RULE_TAG_RULE = (xmlChar*)"rule";
-const xmlChar* const RuleManager::RULE_TAGS[] = {
- (xmlChar*)"name",
- (xmlChar*)"type",
- (xmlChar*)"plugin",
- (xmlChar*)"life",
- (xmlChar*)"alias",
- (xmlChar*)"conflict",
- (xmlChar*)"privilege",
+const xmlChar *const RuleManager::ACTION_RULE_TAG = (xmlChar *)"actionRule";
+const xmlChar *const RuleManager::ACTION_RULE_TAG_RULE = (xmlChar *)"rule";
+const xmlChar *const RuleManager::RULE_TAGS[] = {
+ (xmlChar *)"name",
+ (xmlChar *)"type",
+ (xmlChar *)"plugin",
+ (xmlChar *)"life",
+ (xmlChar *)"alias",
+ (xmlChar *)"conflict",
+ (xmlChar *)"privilege",
};
-RuleManager::RuleManager(const std::string &actionRuleDir, const std::string &actionRuleXsd, const std::string &pluginDir)
- : ruleDir(actionRuleDir), ruleXsd(actionRuleXsd), piMapper(pluginDir)
+RuleManager::RuleManager(const std::string &actionRuleDir, const std::string &actionRuleXsd,
+ const std::string &pluginDir)
+ : ruleDir(actionRuleDir), ruleXsd(actionRuleXsd), piMapper(pluginDir)
{
}
void RuleManager::start()
{
- piMapper.loadPlugins();
- makeRuleMap();
+ piMapper.loadPlugins();
+ makeRuleMap();
}
void RuleManager::stop()
{
- freeRuleMap();
- piMapper.unloadPlugins();
+ freeRuleMap();
+ piMapper.unloadPlugins();
}
void RuleManager::makeRuleMap()
{
- if (ruleDir.empty()) {
- ERR("No ruleDir");
- ruleDir = MODES_ACTIONRULE_DEFAULT_DIR;
- }
-
- DIR *dir;
- if ((dir = opendir(ruleDir.c_str())) == NULL)
- ERR("opendir(%s) Fail(%d)", ruleDir.c_str(), errno);
-
- struct dirent *entry;
- while ((entry = readdir(dir)) != NULL) {
- string file(entry->d_name);
- const size_t suffixLen = sizeof(MODES_ACTIONRULE_FILE_SUFFIX) - 1;
- if (file.length() < suffixLen
- || file.compare(file.length() - suffixLen, suffixLen, MODES_ACTIONRULE_FILE_SUFFIX)) {
- continue;
- }
-
- string fileFullPath = ruleDir + "/" + string(entry->d_name);
- try {
- parseActionRule(fileFullPath);
- DBG("Action Rule(size=%zu) Load", ruleMap.size());
- } catch (ModesEx &e) {
- ERR("parseActionRule(%s) Fail(%s) : It will be ignored", fileFullPath.c_str(), e.what());
- }
- }
- closedir(dir);
+ if (ruleDir.empty()) {
+ ERR("No ruleDir");
+ ruleDir = MODES_ACTIONRULE_DEFAULT_DIR;
+ }
+
+ DIR *dir;
+ if ((dir = opendir(ruleDir.c_str())) == NULL)
+ ERR("opendir(%s) Fail(%d)", ruleDir.c_str(), errno);
+
+ struct dirent *entry;
+ while ((entry = readdir(dir)) != NULL) {
+ string file(entry->d_name);
+ const size_t suffixLen = sizeof(MODES_ACTIONRULE_FILE_SUFFIX) - 1;
+ if (file.length() < suffixLen
+ || file.compare(file.length() - suffixLen, suffixLen, MODES_ACTIONRULE_FILE_SUFFIX)) {
+ continue;
+ }
+
+ string fileFullPath = ruleDir + "/" + string(entry->d_name);
+ try {
+ parseActionRule(fileFullPath);
+ DBG("Action Rule(size=%zu) Load", ruleMap.size());
+ } catch (ModesEx &e) {
+ ERR("parseActionRule(%s) Fail(%s) : It will be ignored", fileFullPath.c_str(),
+ e.what());
+ }
+ }
+ closedir(dir);
}
void RuleManager::freeRuleMap()
{
- for (auto it = ruleMap.begin(); it != ruleMap.end(); ++it)
- delete it->second;
+ for (auto it = ruleMap.begin(); it != ruleMap.end(); ++it)
+ delete it->second;
}
-
void RuleManager::parseElement(xmlNodePtr cur, ActionRule *actionRule)
{
- RET_IF(NULL == actionRule);
-
- if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemAlias])) {
- char *alias = (char*)xmlGetProp(cur, RULE_TAGS[TagAttName]);
- if (NULL == alias) {
- ERR("%s : No %s", RULE_TAGS[TagElemAlias], RULE_TAGS[TagAttName]);
- return;
- }
-
- char *value = (char*)xmlNodeGetContent(cur);
- if (NULL == value) {
- ERR("%s(%s) : No value", RULE_TAGS[TagElemAlias], alias);
- xmlFree(alias);
- return;
- }
-
- int ret = actionRule->addAlias(alias, value);
- if (MODES_ERROR_NONE != ret) {
- ERR("Rule(%s) %s(%s) Fail(%d)", actionRule->getName().c_str(), alias, value, ret);
- xmlFree(value);
- xmlFree(alias);
- throw ModesEx(ModesEx::NO_DATA, "Invalid Alias Value");
- }
-
- xmlFree(value);
- xmlFree(alias);
- } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemPrivilege])) {
- char *value = (char*)xmlNodeGetContent(cur);
- if (NULL == value) {
- ERR("%s : No value", RULE_TAGS[TagElemPrivilege]);
- return;
- }
- actionRule->addPrivilege(value);
- } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemConflict])) {
- // TODO: enhanced feature
- DBG("TBD(%s)", cur->name);
- } else {
- DBG("Invalid node(%s)", cur->name);
- }
+ RET_IF(NULL == actionRule);
+
+ if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemAlias])) {
+ char *alias = (char *)xmlGetProp(cur, RULE_TAGS[TagAttName]);
+ if (NULL == alias) {
+ ERR("%s : No %s", RULE_TAGS[TagElemAlias], RULE_TAGS[TagAttName]);
+ return;
+ }
+
+ char *value = (char *)xmlNodeGetContent(cur);
+ if (NULL == value) {
+ ERR("%s(%s) : No value", RULE_TAGS[TagElemAlias], alias);
+ xmlFree(alias);
+ return;
+ }
+
+ int ret = actionRule->addAlias(alias, value);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("Rule(%s) %s(%s) Fail(%d)", actionRule->getName().c_str(), alias, value, ret);
+ xmlFree(value);
+ xmlFree(alias);
+ throw ModesEx(ModesEx::NO_DATA, "Invalid Alias Value");
+ }
+
+ xmlFree(value);
+ xmlFree(alias);
+ } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemPrivilege])) {
+ char *value = (char *)xmlNodeGetContent(cur);
+ if (NULL == value) {
+ ERR("%s : No value", RULE_TAGS[TagElemPrivilege]);
+ return;
+ }
+ actionRule->addPrivilege(value);
+ } else if (MDS_EQUAL == xmlStrcmp(cur->name, RULE_TAGS[TagElemConflict])) {
+ // TODO: enhanced feature
+ DBG("TBD(%s)", cur->name);
+ } else {
+ DBG("Invalid node(%s)", cur->name);
+ }
}
-Action* RuleManager::createAction(const string &ruleName)
+Action *RuleManager::createAction(const string &ruleName)
{
- std::map<std::string, ActionRule*>::iterator it = ruleMap.find(ruleName);
- if (ruleMap.end() != it) {
- ActionRule *rule = it->second;
- return rule->makeAction();
- } else {
- ERR("No rule(%s)", ruleName.c_str());
- return nullptr;
- }
+ std::map<std::string, ActionRule *>::iterator it = ruleMap.find(ruleName);
+ if (ruleMap.end() != it) {
+ ActionRule *rule = it->second;
+ return rule->makeAction();
+ } else {
+ ERR("No rule(%s)", ruleName.c_str());
+ return nullptr;
+ }
}
void RuleManager::addBoolAlias(ActionRule *actionRule)
{
- actionRule->addAlias("true", "1");
- actionRule->addAlias("false", "0");
+ actionRule->addAlias("true", "1");
+ actionRule->addAlias("false", "0");
}
-ActionRule* RuleManager::makeRule(xmlNodePtr node)
+ActionRule *RuleManager::makeRule(xmlNodePtr node)
{
- string type, name, pluginName;
- ActionRule *actionRule = NULL;
- Action::ActionRuleLife life = Action::PERMANENT;
-
- try {
- name = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttName]);
- type = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttType]);
- pluginName = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttPlugin]);
- if (XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttLife]) == "")
- life = Action::VOLATILE;
- } catch (ModesEx &e) {
- ERR("extractValueOfTag() Fail(%s)", e.what());
- throw;
- }
-
- if (MDS_EQUAL == type.compare("int")) {
- actionRule = new TActionRule<int>(name);
- } else if (MDS_EQUAL == type.compare("float")) {
- actionRule = new TActionRule<double>(name);
- } else if (MDS_EQUAL == type.compare("bool")) {
- actionRule = new TActionRule<bool>(name);
- addBoolAlias(actionRule);
- } else {
- actionRule = new TActionRule<string>(name);
- }
-
- if (pluginName.empty())
- pluginName = name.substr(0, name.find_first_of("."));
-
- Plugin *plugin = piMapper.getPlugin(pluginName);
- if (nullptr == plugin) {
- ERR("Unknown plugin Name(%s)", pluginName.c_str());
- throw ModesEx(ModesEx::NO_DATA, "Unknown plugin Name");
- }
-
- actionRule->setPlugin(plugin);
- actionRule->setLife(life);
- for (xmlNode *cur = node->children; cur; cur = cur->next) {
- if (xmlIsBlankNode(cur))
- continue;
- parseElement(cur, actionRule);
- }
-
- return actionRule;
+ string type, name, pluginName;
+ ActionRule *actionRule = NULL;
+ Action::ActionRuleLife life = Action::PERMANENT;
+
+ try {
+ name = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttName]);
+ type = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttType]);
+ pluginName = XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttPlugin]);
+ if (XMLParser::extractValueOfTag(node, RULE_TAGS[TagAttLife]) == "")
+ life = Action::VOLATILE;
+ } catch (ModesEx &e) {
+ ERR("extractValueOfTag() Fail(%s)", e.what());
+ throw;
+ }
+
+ if (MDS_EQUAL == type.compare("int")) {
+ actionRule = new TActionRule<int>(name);
+ } else if (MDS_EQUAL == type.compare("float")) {
+ actionRule = new TActionRule<double>(name);
+ } else if (MDS_EQUAL == type.compare("bool")) {
+ actionRule = new TActionRule<bool>(name);
+ addBoolAlias(actionRule);
+ } else {
+ actionRule = new TActionRule<string>(name);
+ }
+
+ if (pluginName.empty())
+ pluginName = name.substr(0, name.find_first_of("."));
+
+ Plugin *plugin = piMapper.getPlugin(pluginName);
+ if (nullptr == plugin) {
+ ERR("Unknown plugin Name(%s)", pluginName.c_str());
+ throw ModesEx(ModesEx::NO_DATA, "Unknown plugin Name");
+ }
+
+ actionRule->setPlugin(plugin);
+ actionRule->setLife(life);
+ for (xmlNode *cur = node->children; cur; cur = cur->next) {
+ if (xmlIsBlankNode(cur))
+ continue;
+ parseElement(cur, actionRule);
+ }
+
+ return actionRule;
}
void RuleManager::parseRule(xmlNodePtr node)
{
- std::map<std::string, ActionRule*> tmpRuleMap;
-
- for (xmlNodePtr cur = node; cur; cur = cur->next) {
- if (xmlIsBlankNode(cur))
- continue;
-
- if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_RULE_TAG_RULE)) {
- ActionRule *rule = makeRule(cur);
-
- std::pair<std::map<string, ActionRule*>::iterator, bool> ret;
- ret = tmpRuleMap.insert(std::pair<string, ActionRule*>(rule->getName(), rule));
- if (false == ret.second) {
- ERR("parseRule() Fail : Rule(%s) already exists", rule->getName().c_str());
- delete rule;
- throw ModesEx(ModesEx::PARSER_ERROR, "Invalid Rule");
- } else {
- DBG("Action(%s) Added", rule->getName().c_str());
- }
- } else {
- DBG("Invalid node(%s)", cur->name);
- parseRule(cur->children);
- }
- }
- ruleMap.insert(tmpRuleMap.begin(), tmpRuleMap.end());
+ std::map<std::string, ActionRule *> tmpRuleMap;
+
+ for (xmlNodePtr cur = node; cur; cur = cur->next) {
+ if (xmlIsBlankNode(cur))
+ continue;
+
+ if (MDS_EQUAL == xmlStrcmp(cur->name, ACTION_RULE_TAG_RULE)) {
+ ActionRule *rule = makeRule(cur);
+
+ std::pair<std::map<string, ActionRule *>::iterator, bool> ret;
+ ret = tmpRuleMap.insert(std::pair<string, ActionRule *>(rule->getName(), rule));
+ if (false == ret.second) {
+ ERR("parseRule() Fail : Rule(%s) already exists", rule->getName().c_str());
+ delete rule;
+ throw ModesEx(ModesEx::PARSER_ERROR, "Invalid Rule");
+ } else {
+ DBG("Action(%s) Added", rule->getName().c_str());
+ }
+ } else {
+ DBG("Invalid node(%s)", cur->name);
+ parseRule(cur->children);
+ }
+ }
+ ruleMap.insert(tmpRuleMap.begin(), tmpRuleMap.end());
}
void RuleManager::parseActionRule(const string &xmlFile)
{
- try {
- XMLParser parser(xmlFile);
- parser.validate(ruleXsd);
-
- xmlNodePtr root = parser.getRoot();
- if (MDS_EQUAL != xmlStrcmp(root->name, (xmlChar*)MODES_XML_ROOT)) {
- ERR("Invalid root element(%s, %s)", root->name, xmlFile.c_str());
- throw ModesEx(ModesEx::PARSER_ERROR, "Invalid file");
- }
-
- parseRule(root);
- } catch (ModesEx &e) {
- ERR("parsing(%s) Fail(%s)", xmlFile.c_str(), e.what());
- throw;
- }
+ try {
+ XMLParser parser(xmlFile);
+ parser.validate(ruleXsd);
+
+ xmlNodePtr root = parser.getRoot();
+ if (MDS_EQUAL != xmlStrcmp(root->name, (xmlChar *)MODES_XML_ROOT)) {
+ ERR("Invalid root element(%s, %s)", root->name, xmlFile.c_str());
+ throw ModesEx(ModesEx::PARSER_ERROR, "Invalid file");
+ }
+
+ parseRule(root);
+ } catch (ModesEx &e) {
+ ERR("parsing(%s) Fail(%s)", xmlFile.c_str(), e.what());
+ throw;
+ }
}
*/
#pragma once
+#include <libxml/tree.h>
+
#include <map>
#include <string>
-#include <libxml/tree.h>
-#include "mdss.h"
-#include "ActionRule.h"
+
#include "Action.h"
-#include "XMLParser.h"
+#include "ActionRule.h"
#include "PluginMapper.h"
+#include "XMLParser.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class RuleManager {
-public:
- enum {
- TagAttName,
- TagAttType,
- TagAttPlugin,
- TagAttLife,
- TagElemAlias,
- TagElemConflict,
- TagElemPrivilege,
- TagMax
- };
+ public:
+ enum {
+ TagAttName,
+ TagAttType,
+ TagAttPlugin,
+ TagAttLife,
+ TagElemAlias,
+ TagElemConflict,
+ TagElemPrivilege,
+ TagMax
+ };
+
+ RuleManager(const std::string &actionRuleDir, const std::string &actionRuleXsd,
+ const std::string &pluginDir);
- RuleManager(const std::string &actionRuleDir, const std::string &actionRuleXsd, const std::string &pluginDir);
+ void start();
+ void stop();
+ Action *createAction(const std::string &actionName);
- void start();
- void stop();
- Action* createAction(const std::string &actionName);
-private:
- static const xmlChar* const ACTION_RULE_TAG;
- static const xmlChar* const ACTION_RULE_TAG_RULE;
- static const xmlChar* const RULE_TAGS[];
+ private:
+ static const xmlChar *const ACTION_RULE_TAG;
+ static const xmlChar *const ACTION_RULE_TAG_RULE;
+ static const xmlChar *const RULE_TAGS[];
- void makeRuleMap();
- void freeRuleMap();
- ActionRule* makeRule(xmlNodePtr node);
- void parseRule(xmlNodePtr node);
- void addBoolAlias(ActionRule *actionRule);
- void parseActionRule(const std::string &xmlFile);
- void parseElement(xmlNodePtr node, ActionRule *actionRule);
+ void makeRuleMap();
+ void freeRuleMap();
+ ActionRule *makeRule(xmlNodePtr node);
+ void parseRule(xmlNodePtr node);
+ void addBoolAlias(ActionRule *actionRule);
+ void parseActionRule(const std::string &xmlFile);
+ void parseElement(xmlNodePtr node, ActionRule *actionRule);
- std::map<std::string, ActionRule*> ruleMap;
- std::string ruleDir;
- std::string ruleXsd;
- PluginMapper piMapper;
+ std::map<std::string, ActionRule *> ruleMap;
+ std::string ruleDir;
+ std::string ruleXsd;
+ PluginMapper piMapper;
#ifdef MDS_TEST
- friend class RuleManagerTest;
- friend class ParserTest;
+ friend class RuleManagerTest;
+ friend class ParserTest;
#endif
};
*/
#include "Supervisor.h"
-#include "mdss.h"
-#include "ModesEx.h"
+#include "ArgumentParser.h"
+#include "EssentialHandler.h"
#include "ModeManager.h"
+#include "ModesEx.h"
#include "RequestHandler.h"
-#include "EssentialHandler.h"
-#include "ArgumentParser.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
Supervisor::Supervisor(const ModesConfig &config)
- : ruleMgr(config.actionRuleDir, MODES_RULE_DEFAULT_XSD_PATH, config.pluginDir),
- modeMgr(config.modeXMLDirs, MODES_MODE_DEFAULT_XSD_PATH, ruleMgr)
+ : ruleMgr(config.actionRuleDir, MODES_RULE_DEFAULT_XSD_PATH, config.pluginDir),
+ modeMgr(config.modeXMLDirs, MODES_MODE_DEFAULT_XSD_PATH, ruleMgr)
{
}
void Supervisor::init()
{
- RequestHandler::setModeManager(&modeMgr);
- RequestHandler::setRuleManager(&ruleMgr);
- EssentialHandler::setModeManager(&modeMgr);
+ RequestHandler::setModeManager(&modeMgr);
+ RequestHandler::setRuleManager(&ruleMgr);
+ EssentialHandler::setModeManager(&modeMgr);
- try {
- clientConn.startDbus();
- ruleMgr.start();
- modeMgr.init();
- modeMgr.attachObserver(&clientConn);
- }
- catch (ModesEx &e) {
- ERR("Supervisor init() Fail(%s)", e.what());
- }
+ try {
+ clientConn.startDbus();
+ ruleMgr.start();
+ modeMgr.init();
+ modeMgr.attachObserver(&clientConn);
+ } catch (ModesEx &e) {
+ ERR("Supervisor init() Fail(%s)", e.what());
+ }
}
void Supervisor::deInit()
{
- modeMgr.detachObserver(&clientConn);
- ruleMgr.stop();
- clientConn.stopDbus();
- RequestHandler::setModeManager(NULL);
- RequestHandler::setRuleManager(NULL);
+ modeMgr.detachObserver(&clientConn);
+ ruleMgr.stop();
+ clientConn.stopDbus();
+ RequestHandler::setModeManager(NULL);
+ RequestHandler::setRuleManager(NULL);
}
void Supervisor::registerHandler()
{
- clientConn.addRequestHandler("handle-can-apply", (GCallback)&RequestHandler::canApplyModeHandler);
- clientConn.addRequestHandler("handle-apply-mode", (GCallback)&RequestHandler::applyModeHandler);
- clientConn.addRequestHandler("handle-undo-mode", (GCallback)&RequestHandler::undoModeHandler);
- clientConn.addRequestHandler("handle-add-mode", (GCallback)&RequestHandler::addModeHandler);
- clientConn.addRequestHandler("handle-remove-mode", (GCallback)&RequestHandler::removeModeHandler);
- clientConn.addRequestHandler("handle-get-modes", (GCallback)&RequestHandler::getModesHandler);
+ clientConn.addRequestHandler("handle-can-apply",
+ (GCallback)&RequestHandler::canApplyModeHandler);
+ clientConn.addRequestHandler("handle-apply-mode", (GCallback)&RequestHandler::applyModeHandler);
+ clientConn.addRequestHandler("handle-undo-mode", (GCallback)&RequestHandler::undoModeHandler);
+ clientConn.addRequestHandler("handle-add-mode", (GCallback)&RequestHandler::addModeHandler);
+ clientConn.addRequestHandler("handle-remove-mode",
+ (GCallback)&RequestHandler::removeModeHandler);
+ clientConn.addRequestHandler("handle-get-modes", (GCallback)&RequestHandler::getModesHandler);
}
#pragma once
#include <string>
-#include "mdss.h"
+
+#include "ClientConnection.h"
#include "ModeManager.h"
#include "ModesConfig.h"
-#include "ClientConnection.h"
#include "RuleManager.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class Supervisor {
-public:
- Supervisor(const ModesConfig &config);
+ public:
+ Supervisor(const ModesConfig &config);
+
+ void init();
+ void deInit();
+ void registerHandler();
- void init();
- void deInit();
- void registerHandler();
-private:
- ClientConnection clientConn;
- RuleManager ruleMgr;
- ModeManager modeMgr;
+ private:
+ ClientConnection clientConn;
+ RuleManager ruleMgr;
+ ModeManager modeMgr;
};
MODES_NAMESPACE_END
#include <map>
#include <mutex>
-#include <string>
#include <sstream>
+#include <string>
#include <thread>
-#include "mdss.h"
+
#include "Action.h"
#include "ModesEx.h"
#include "ValueChecker.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
template <typename T>
class TAction : public Action {
-public:
- TAction(const std::string &name, std::shared_ptr<PluginAction> pluginAction)
- : Action(name, pluginAction)
- {
- if (nullptr == pluginAction)
- throw ModesEx(ModesEx::INVALID_ARG);
- }
-
- ~TAction()
- {
- unsubscribeChanges();
- }
-
- void setValueAliases(const std::map<std::string, T> &list)
- {
- valueAliases.clear();
- valueAliases.insert(list.begin(), list.end());
- }
-
- T getValue() const
- {
- return value;
- }
-
- std::string getStringOfValue()
- {
- std::ostringstream ostr;
-
- ostr << value;
- return ostr.str();
- }
-
- int setValue(const std::string &val) override
- {
- auto it = valueAliases.find(val);
- if (valueAliases.end() != it) {
- value = it->second;
- } else {
- ValueChecker checker;
- if (checker.checkValue(T(), val)) {
- std::istringstream iss(val);
- iss >> value;
- } else {
- ERR("Action(%s) has Invalid val(%s)", ruleName.c_str(), val.c_str());
- return MODES_ERROR_NOT_SUPPORTED;
- }
- }
-
- return MODES_ERROR_NONE;
- }
-
- bool checkChanged() override
- {
- if (false == piAction->IsCurrentValue(value)) {
- INFO("Action(%s) is changed", ruleName.c_str());
- return true;
- }
- return false;
- }
-
- int apply() override
- {
- std::lock_guard<std::mutex> lock(actionMutex);
-
- int ret = applySub();
- if (MODES_ERROR_NONE != ret) {
- ignoreUndo = true;
- if (MODES_ERROR_ALREADY == ret)
- return MODES_ERROR_NONE;
- ERR("applySub(%s) Fail(%d)", ruleName.c_str(), ret);
- return ret;
- }
-
- subscribeChanges();
- return MODES_ERROR_NONE;
- }
-
- int applyOneShot() override
- {
- std::lock_guard<std::mutex> lock(actionMutex);
-
- int ret = applySub();
- if (MODES_ERROR_NONE != ret) {
- ignoreUndo = true;
- if (MODES_ERROR_ALREADY != ret) {
- ERR("applySub(%s) Fail(%d)", ruleName.c_str(), ret);
- return ret;
- }
- }
-
- return MODES_ERROR_NONE;
- }
-
- void undo() override
- {
- std::lock_guard<std::mutex> lock(actionMutex);
-
- if (ignoreUndo) {
- INFO("Action(%s) : value changed", ruleName.c_str());
- } else {
- unsubscribeChanges();
- piAction->undo();
- }
- }
-
-private:
- struct CaseIndependentLess {
- struct Compare {
- bool operator()(const unsigned char &c1, const unsigned char &c2) const
- {
- return tolower(c1) < tolower(c2);
- }
- };
- bool operator()(const std::string &s1, const std::string &s2) const
- {
- return std::lexicographical_compare(s1.begin(), s1.end(),
- s2.begin(), s2.end(), Compare());
- }
- };
-
- int applySub()
- {
- if (piAction->IsCurrentValue(value)) {
- INFO("Action(%s) is Ignored because it is equal to current value", ruleName.c_str());
- return MODES_ERROR_ALREADY;
- }
-
- invokeChangedCB();
-
- int ret = piAction->set(value);
- if (MODES_ERROR_NONE != ret) {
- ERR("piAction(%s) set() Fail(%d)", piAction->getKey().c_str(), ret);
- return ret;
- }
-
- return MODES_ERROR_NONE;
- }
-
- std::map<std::string, T, CaseIndependentLess> valueAliases;
- std::mutex actionMutex;
- T value{};
+ public:
+ TAction(const std::string &name, std::shared_ptr<PluginAction> pluginAction)
+ : Action(name, pluginAction)
+ {
+ if (nullptr == pluginAction)
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ ~TAction() { unsubscribeChanges(); }
+
+ void setValueAliases(const std::map<std::string, T> &list)
+ {
+ valueAliases.clear();
+ valueAliases.insert(list.begin(), list.end());
+ }
+
+ T getValue() const { return value; }
+
+ std::string getStringOfValue()
+ {
+ std::ostringstream ostr;
+
+ ostr << value;
+ return ostr.str();
+ }
+
+ int setValue(const std::string &val) override
+ {
+ auto it = valueAliases.find(val);
+ if (valueAliases.end() != it) {
+ value = it->second;
+ } else {
+ ValueChecker checker;
+ if (checker.checkValue(T(), val)) {
+ std::istringstream iss(val);
+ iss >> value;
+ } else {
+ ERR("Action(%s) has Invalid val(%s)", ruleName.c_str(), val.c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ }
+
+ return MODES_ERROR_NONE;
+ }
+
+ bool checkChanged() override
+ {
+ if (false == piAction->IsCurrentValue(value)) {
+ INFO("Action(%s) is changed", ruleName.c_str());
+ return true;
+ }
+ return false;
+ }
+
+ int apply() override
+ {
+ std::lock_guard<std::mutex> lock(actionMutex);
+
+ int ret = applySub();
+ if (MODES_ERROR_NONE != ret) {
+ ignoreUndo = true;
+ if (MODES_ERROR_ALREADY == ret)
+ return MODES_ERROR_NONE;
+ ERR("applySub(%s) Fail(%d)", ruleName.c_str(), ret);
+ return ret;
+ }
+
+ subscribeChanges();
+ return MODES_ERROR_NONE;
+ }
+
+ int applyOneShot() override
+ {
+ std::lock_guard<std::mutex> lock(actionMutex);
+
+ int ret = applySub();
+ if (MODES_ERROR_NONE != ret) {
+ ignoreUndo = true;
+ if (MODES_ERROR_ALREADY != ret) {
+ ERR("applySub(%s) Fail(%d)", ruleName.c_str(), ret);
+ return ret;
+ }
+ }
+
+ return MODES_ERROR_NONE;
+ }
+
+ void undo() override
+ {
+ std::lock_guard<std::mutex> lock(actionMutex);
+
+ if (ignoreUndo) {
+ INFO("Action(%s) : value changed", ruleName.c_str());
+ } else {
+ unsubscribeChanges();
+ piAction->undo();
+ }
+ }
+
+ private:
+ struct CaseIndependentLess {
+ struct Compare {
+ bool operator()(const unsigned char &c1, const unsigned char &c2) const
+ {
+ return tolower(c1) < tolower(c2);
+ }
+ };
+ bool operator()(const std::string &s1, const std::string &s2) const
+ {
+ return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(),
+ Compare());
+ }
+ };
+
+ int applySub()
+ {
+ if (piAction->IsCurrentValue(value)) {
+ INFO("Action(%s) is Ignored because it is equal to current value", ruleName.c_str());
+ return MODES_ERROR_ALREADY;
+ }
+
+ invokeChangedCB();
+
+ int ret = piAction->set(value);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("piAction(%s) set() Fail(%d)", piAction->getKey().c_str(), ret);
+ return ret;
+ }
+
+ return MODES_ERROR_NONE;
+ }
+
+ std::map<std::string, T, CaseIndependentLess> valueAliases;
+ std::mutex actionMutex;
+ T value{};
};
MODES_NAMESPACE_END
*/
#pragma once
-#include <map>
+#include <functional>
#include <list>
-#include <string>
+#include <map>
#include <sstream>
-#include <functional>
-#include "mdss.h"
-#include "TAction.h"
+#include <string>
+
#include "ActionRule.h"
+#include "TAction.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
template <typename T>
class TActionRule : public ActionRule {
-public:
- TActionRule(const std::string &name)
- {
- ruleName = name;
- }
+ public:
+ TActionRule(const std::string &name) { ruleName = name; }
+
+ Action *makeAction() override
+ {
+ int pos = ruleName.find_first_of(".");
+ std::string actionKey = ruleName.substr(pos + 1);
+ std::shared_ptr<PluginAction> piAction(plugin->newAction(actionKey),
+ std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
- Action* makeAction() override
- {
- int pos = ruleName.find_first_of(".");
- std::string actionKey = ruleName.substr(pos + 1);
- std::shared_ptr<PluginAction> piAction(plugin->newAction(actionKey),
- std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+ try {
+ TAction<T> *action = new TAction<T>(ruleName, piAction);
+ action->setValueAliases(valueAliasList);
+ action->setPrivileges(privileges);
+ action->setLife(life);
- try {
- TAction<T> *action = new TAction<T>(ruleName, piAction);
- action->setValueAliases(valueAliasList);
- action->setPrivileges(privileges);
- action->setLife(life);
+ return action;
+ } catch (ModesEx &e) {
+ ERR("makeAction() Fail(%s)", e.what());
+ }
- return action;
- } catch (ModesEx &e) {
- ERR("makeAction() Fail(%s)", e.what());
- }
+ return nullptr;
+ }
- return nullptr;
- }
+ int addAlias(const std::string &alias, const std::string &value) override
+ {
+ ValueChecker checker;
+ if (false == checker.checkValue(T(), value)) {
+ ERR("checkValue(Rule:%s, Alias:%s, Val:%s) Fail", ruleName.c_str(), alias.c_str(),
+ value.c_str());
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
- int addAlias(const std::string &alias, const std::string &value) override
- {
- ValueChecker checker;
- if (false == checker.checkValue(T(), value)) {
- ERR("checkValue(Rule:%s, Alias:%s, Val:%s) Fail",
- ruleName.c_str(), alias.c_str(), value.c_str());
- return MODES_ERROR_NOT_SUPPORTED;
- }
+ T realVal;
+ std::istringstream iss(value);
+ iss >> realVal;
+ valueAliasList.insert(std::pair<std::string, T>(alias, realVal));
- T realVal;
- std::istringstream iss(value);
- iss >> realVal;
- valueAliasList.insert(std::pair<std::string, T>(alias, realVal));
+ return MODES_ERROR_NONE;
+ }
- return MODES_ERROR_NONE;
- }
-private:
- std::map<std::string, T> valueAliasList;
+ private:
+ std::map<std::string, T> valueAliasList;
};
MODES_NAMESPACE_END
* limitations under the License.
*/
#include "UndoInfoParser.h"
-#include <cstring>
-#include <string>
-#include <algorithm>
+
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
-#include "mdss.h"
+
+#include <algorithm>
+#include <cstring>
+#include <string>
+
#include "ModesEx.h"
-#include "XMLParser.h"
#include "ModesXMLTag.h"
+#include "XMLParser.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
-UndoInfoParser::UndoInfoParser(const std::string &file)
- : XMLParser(file)
+UndoInfoParser::UndoInfoParser(const std::string &file) : XMLParser(file)
{
}
void UndoInfoParser::putUndoInfo(Mode &mode)
{
- std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
- iterateElement(getRoot(), actionList);
+ iterateElement(getRoot(), actionList);
}
-void UndoInfoParser::iterateElement(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList)
+void UndoInfoParser::iterateElement(xmlNodePtr node,
+ const std::list<std::shared_ptr<Action>> &actionList)
{
- xmlNode *cur = NULL;
- for (cur = node; cur; cur = cur->next) {
- if (xmlIsBlankNode(cur))
- continue;
- else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::INFO))
- parseInfo(cur, actionList);
- else
- DBG("Unhandled node : %s", node->name);
-
- iterateElement(cur->children, actionList);
- }
+ xmlNode *cur = NULL;
+ for (cur = node; cur; cur = cur->next) {
+ if (xmlIsBlankNode(cur))
+ continue;
+ else if (MDS_EQUAL == xmlStrcmp(cur->name, ModesXMLTag::INFO))
+ parseInfo(cur, actionList);
+ else
+ DBG("Unhandled node : %s", node->name);
+
+ iterateElement(cur->children, actionList);
+ }
}
-void UndoInfoParser::parseInfo(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList)
+void UndoInfoParser::parseInfo(xmlNodePtr node,
+ const std::list<std::shared_ptr<Action>> &actionList)
{
- char *ruleName = (char*)xmlGetProp(node, ModesXMLTag::RULE);
- if (nullptr == ruleName) {
- ERR("No value of (%s)", ModesXMLTag::RULE);
- throw ModesEx(ModesEx::PARSER_ERROR, "No Rule Name");
- }
-
- auto it = std::find_if(actionList.begin(), actionList.end(),
- [&ruleName](std::shared_ptr<Action> a) {return (a->getRuleName() == ruleName);});
-
- std::shared_ptr<Action> action = *it;
- if (nullptr == action) {
- ERR("Find Action(%s) Fail", ruleName);
- xmlFree(ruleName);
- throw ModesEx(ModesEx::PARSER_ERROR, "No Action");
- }
-
- xmlChar *isIgnored = xmlGetProp(node, ModesXMLTag::IGNORE);
- if (MDS_EQUAL == xmlStrcmp(isIgnored, ModesXMLTag::TRUE))
- action->setIgnoreUndo(true);
-
- char *nodeContent = (char*)xmlNodeGetContent(node);
- if (nullptr == nodeContent)
- ERR("No undo Info for Action(%s)", ruleName);
-
- int ret = action->restoreUndoInfo(nodeContent ? nodeContent : "");
- xmlFree(ruleName);
- xmlFree(nodeContent);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) setValue() Fail(%d)", action->getRuleName().c_str(), ret);
- throw ModesEx(ModesEx::PARSER_ERROR, "Invalid UndoInfo");
- }
-
- action->printInfo();
+ char *ruleName = (char *)xmlGetProp(node, ModesXMLTag::RULE);
+ if (nullptr == ruleName) {
+ ERR("No value of (%s)", ModesXMLTag::RULE);
+ throw ModesEx(ModesEx::PARSER_ERROR, "No Rule Name");
+ }
+
+ auto it = std::find_if(actionList.begin(), actionList.end(),
+ [&ruleName](std::shared_ptr<Action> a) { return (a->getRuleName() == ruleName); });
+
+ std::shared_ptr<Action> action = *it;
+ if (nullptr == action) {
+ ERR("Find Action(%s) Fail", ruleName);
+ xmlFree(ruleName);
+ throw ModesEx(ModesEx::PARSER_ERROR, "No Action");
+ }
+
+ xmlChar *isIgnored = xmlGetProp(node, ModesXMLTag::IGNORE);
+ if (MDS_EQUAL == xmlStrcmp(isIgnored, ModesXMLTag::TRUE))
+ action->setIgnoreUndo(true);
+
+ char *nodeContent = (char *)xmlNodeGetContent(node);
+ if (nullptr == nodeContent)
+ ERR("No undo Info for Action(%s)", ruleName);
+
+ int ret = action->restoreUndoInfo(nodeContent ? nodeContent : "");
+ xmlFree(ruleName);
+ xmlFree(nodeContent);
+ if (MODES_ERROR_NONE != ret) {
+ ERR("Action(%s) setValue() Fail(%d)", action->getRuleName().c_str(), ret);
+ throw ModesEx(ModesEx::PARSER_ERROR, "Invalid UndoInfo");
+ }
+
+ action->printInfo();
}
#pragma once
#include <libxml/tree.h>
-#include "mdss.h"
+
#include "Mode.h"
#include "XMLParser.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class UndoInfoParser : public XMLParser {
-public:
- UndoInfoParser(const std::string &file);
- ~UndoInfoParser() = default;
+ public:
+ UndoInfoParser(const std::string &file);
+ ~UndoInfoParser() = default;
+
+ void putUndoInfo(Mode &mode);
- void putUndoInfo(Mode &mode);
-private:
- void iterateElement(xmlNodePtr node, const std::list<std::shared_ptr<Action>>& actionList);
- void parseInfo(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList);
+ private:
+ void iterateElement(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList);
+ void parseInfo(xmlNodePtr node, const std::list<std::shared_ptr<Action>> &actionList);
- std::string filePath;
+ std::string filePath;
};
MODES_NAMESPACE_END
bool ValueChecker::checkValue(int, const std::string &val)
{
- auto it = val.begin();
- if ((it != val.end()) && ('-' == *it))
- ++it;
+ auto it = val.begin();
+ if ((it != val.end()) && ('-' == *it))
+ ++it;
- while (it != val.end()) {
- if (*it < '0' || '9' < *it)
- return false;
- ++it;
- }
+ while (it != val.end()) {
+ if (*it < '0' || '9' < *it)
+ return false;
+ ++it;
+ }
- return true;
+ return true;
}
bool ValueChecker::checkValue(double, const std::string &val)
{
- int dotNum = 0;
- auto it = val.begin();
- if ((it != val.end()) && ('-' == *it))
- ++it;
+ int dotNum = 0;
+ auto it = val.begin();
+ if ((it != val.end()) && ('-' == *it))
+ ++it;
- while (it != val.end()) {
- if (*it < '0' || '9' < *it) {
- if ('.' != *it)
- return false;
- else if (dotNum)
- return false;
- else
- dotNum++;
- }
- ++it;
- }
+ while (it != val.end()) {
+ if (*it < '0' || '9' < *it) {
+ if ('.' != *it)
+ return false;
+ else if (dotNum)
+ return false;
+ else
+ dotNum++;
+ }
+ ++it;
+ }
- return true;
+ return true;
}
bool ValueChecker::checkValue(bool, const std::string &val)
{
- if (MDS_EQUAL == val.compare("1"))
- return true;
- if (MDS_EQUAL == val.compare("0"))
- return true;
+ if (MDS_EQUAL == val.compare("1"))
+ return true;
+ if (MDS_EQUAL == val.compare("0"))
+ return true;
- return false;
+ return false;
}
bool ValueChecker::checkValue(std::string, const std::string &val)
{
- return true;
+ return true;
}
#pragma once
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
class ValueChecker {
-public:
- ValueChecker() = default;
- ~ValueChecker() = default;
+ public:
+ ValueChecker() = default;
+ ~ValueChecker() = default;
- bool checkValue(int, const std::string &val);
- bool checkValue(double, const std::string &val);
- bool checkValue(bool, const std::string &val);
- bool checkValue(std::string, const std::string &val);
+ bool checkValue(int, const std::string &val);
+ bool checkValue(double, const std::string &val);
+ bool checkValue(bool, const std::string &val);
+ bool checkValue(std::string, const std::string &val);
};
MODES_NAMESPACE_END
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <stdio.h>
+#include "XMLGenerator.h"
+
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
+#include <stdio.h>
+
#include "Action.h"
-#include "ModesXMLTag.h"
#include "ModesEx.h"
-#include "XMLGenerator.h"
+#include "ModesXMLTag.h"
MODES_NAMESPACE_USE;
-XMLGenerator::XMLGenerator()
- : doc(NULL), rootNode(NULL)
+XMLGenerator::XMLGenerator() : doc(NULL), rootNode(NULL)
{
}
void XMLGenerator::createRootNode()
{
- doc = xmlNewDoc(ModesXMLTag::XML_VERSION);
- doc->encoding = ModesXMLTag::XML_ENCODING;
- doc->charset = 1;
-
- rootNode = xmlNewNode(NULL, ModesXMLTag::TIZENMODES);
- xmlSetProp(rootNode, ModesXMLTag::XMLNS, ModesXMLTag::XMLNS_STR);
- xmlSetProp(rootNode, ModesXMLTag::VERSION, ModesXMLTag::CUR_VERSION);
- xmlDocSetRootElement(doc, rootNode);
- return;
+ doc = xmlNewDoc(ModesXMLTag::XML_VERSION);
+ doc->encoding = ModesXMLTag::XML_ENCODING;
+ doc->charset = 1;
+
+ rootNode = xmlNewNode(NULL, ModesXMLTag::TIZENMODES);
+ xmlSetProp(rootNode, ModesXMLTag::XMLNS, ModesXMLTag::XMLNS_STR);
+ xmlSetProp(rootNode, ModesXMLTag::VERSION, ModesXMLTag::CUR_VERSION);
+ xmlDocSetRootElement(doc, rootNode);
+ return;
}
void XMLGenerator::saveToFile(const std::string &path)
{
- //check validation of file : It should be nothing
- FILE *file = fopen(path.c_str(), "wx");
- if (nullptr == file) {
- ERR("Abnormal Situation!! File(%s) exist", path.c_str());
- throw ModesEx(ModesEx::SYSTEM_ERROR);
- }
-
- int ret = xmlDocFormatDump(file, doc, 1);
- fclose(file);
- if (-1 == ret) {
- ERR("xmlSaveFormatFile(%s) Fail(%d)", path.c_str(), errno);
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ // check validation of file : It should be nothing
+ FILE *file = fopen(path.c_str(), "wx");
+ if (nullptr == file) {
+ ERR("Abnormal Situation!! File(%s) exist", path.c_str());
+ throw ModesEx(ModesEx::SYSTEM_ERROR);
+ }
+
+ int ret = xmlDocFormatDump(file, doc, 1);
+ fclose(file);
+ if (-1 == ret) {
+ ERR("xmlSaveFormatFile(%s) Fail(%d)", path.c_str(), errno);
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
}
const std::string XMLGenerator::getModeTypeStr(Mode::ModeType t)
{
- switch (t) {
- case Mode::MODE_ONESHOT:
- return "oneshot";
- case Mode::MODE_NORMAL:
- default:
- return "normal";
- }
+ switch (t) {
+ case Mode::MODE_ONESHOT:
+ return "oneshot";
+ case Mode::MODE_NORMAL:
+ default:
+ return "normal";
+ }
}
void XMLGenerator::makeModeXML(const std::string &path, const Mode &mode)
{
- if (path.empty()) {
- ERR("NULL path");
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ if (path.empty()) {
+ ERR("NULL path");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
- createRootNode();
+ createRootNode();
- const std::string modeType = getModeTypeStr(mode.getModeType());
- std::string modeName = mode.getName();
- std::string modeID = mode.getID();
+ const std::string modeType = getModeTypeStr(mode.getModeType());
+ std::string modeName = mode.getName();
+ std::string modeID = mode.getID();
- xmlNodePtr modeNode = xmlNewNode(NULL, ModesXMLTag::MODE);
+ 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())
- xmlSetProp(modeNode, ModesXMLTag::HIDDEN, ModesXMLTag::TRUE);
- xmlAddChild(rootNode, modeNode);
+ 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())
+ xmlSetProp(modeNode, ModesXMLTag::HIDDEN, ModesXMLTag::TRUE);
+ xmlAddChild(rootNode, modeNode);
- std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
- for (auto it = actionList.begin(); it != actionList.end(); it++) {
- xmlNodePtr actionNode;
- Action::ActionRestrict restriction = (*it)->getRestrict();
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+ for (auto it = actionList.begin(); it != actionList.end(); it++) {
+ xmlNodePtr actionNode;
+ Action::ActionRestrict restriction = (*it)->getRestrict();
- actionNode = xmlNewNode(NULL, ModesXMLTag::ACTION);
+ actionNode = xmlNewNode(NULL, ModesXMLTag::ACTION);
- if (!(*it)->getID().empty())
- xmlSetProp(actionNode, ModesXMLTag::ID, (xmlChar*)(*it)->getID().c_str());
+ if (!(*it)->getID().empty())
+ xmlSetProp(actionNode, ModesXMLTag::ID, (xmlChar *)(*it)->getID().c_str());
- xmlSetProp(actionNode, ModesXMLTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
+ xmlSetProp(actionNode, ModesXMLTag::RULE, (xmlChar *)(*it)->getRuleName().c_str());
- if (restriction == Action::ActionRestrict::LOCK)
- xmlSetProp(actionNode, ModesXMLTag::RESTRICT, (xmlChar*)ModesXMLTag::RESTRICT_LOCK);
+ if (restriction == Action::ActionRestrict::LOCK)
+ xmlSetProp(actionNode, ModesXMLTag::RESTRICT, (xmlChar *)ModesXMLTag::RESTRICT_LOCK);
- xmlNodeSetContent(actionNode, (xmlChar*)(*it)->getStringOfValue().c_str());
+ xmlNodeSetContent(actionNode, (xmlChar *)(*it)->getStringOfValue().c_str());
- xmlAddChild(modeNode, actionNode);
- }
+ xmlAddChild(modeNode, actionNode);
+ }
- saveToFile(path);
+ saveToFile(path);
- doc->encoding = NULL;
- xmlFreeDoc(doc);
- return;
+ doc->encoding = NULL;
+ xmlFreeDoc(doc);
+ return;
}
void XMLGenerator::makeUndoInfoXML(const std::string &path, const Mode &mode)
{
- if (path.empty()) {
- ERR("NULL path");
- throw ModesEx(ModesEx::INVALID_ARG);
- }
-
- createRootNode();
-
- xmlNodePtr undoInfoNode = xmlNewNode(NULL, ModesXMLTag::UNDO_INFO);
- xmlSetProp(undoInfoNode, ModesXMLTag::NAME, (xmlChar*)mode.getName().c_str());
- xmlAddChild(rootNode, undoInfoNode);
-
- std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
- for (auto it = actionList.begin(); it != actionList.end(); it++) {
- if ((*it)->getLife() == Action::VOLATILE || (*it)->backupUndoInfo().empty())
- continue;
-
- xmlNodePtr infoNode = xmlNewNode(NULL, ModesXMLTag::INFO);
- xmlSetProp(infoNode, ModesXMLTag::RULE, (xmlChar*)(*it)->getRuleName().c_str());
- if ((*it)->isIgnored())
- xmlSetProp(infoNode, ModesXMLTag::IGNORE, ModesXMLTag::TRUE);
- else
- xmlSetProp(infoNode, ModesXMLTag::IGNORE, ModesXMLTag::FALSE);
- xmlNodeSetContent(infoNode, (xmlChar*)(*it)->backupUndoInfo().c_str());
- xmlAddChild(undoInfoNode, infoNode);
- }
-
- saveToFile(path);
-
- doc->encoding = NULL;
- xmlFreeDoc(doc);
- return;
+ if (path.empty()) {
+ ERR("NULL path");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ createRootNode();
+
+ xmlNodePtr undoInfoNode = xmlNewNode(NULL, ModesXMLTag::UNDO_INFO);
+ xmlSetProp(undoInfoNode, ModesXMLTag::NAME, (xmlChar *)mode.getName().c_str());
+ xmlAddChild(rootNode, undoInfoNode);
+
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+ for (auto it = actionList.begin(); it != actionList.end(); it++) {
+ if ((*it)->getLife() == Action::VOLATILE || (*it)->backupUndoInfo().empty())
+ continue;
+
+ xmlNodePtr infoNode = xmlNewNode(NULL, ModesXMLTag::INFO);
+ xmlSetProp(infoNode, ModesXMLTag::RULE, (xmlChar *)(*it)->getRuleName().c_str());
+ if ((*it)->isIgnored())
+ xmlSetProp(infoNode, ModesXMLTag::IGNORE, ModesXMLTag::TRUE);
+ else
+ xmlSetProp(infoNode, ModesXMLTag::IGNORE, ModesXMLTag::FALSE);
+ xmlNodeSetContent(infoNode, (xmlChar *)(*it)->backupUndoInfo().c_str());
+ xmlAddChild(undoInfoNode, infoNode);
+ }
+
+ saveToFile(path);
+
+ doc->encoding = NULL;
+ xmlFreeDoc(doc);
+ return;
}
*/
#pragma once
-#include <string>
#include <libxml/tree.h>
-#include "mdss.h"
+
+#include <string>
+
#include "Mode.h"
+#include "mdss.h"
MODES_NAMESPACE_BEGIN
class XMLGenerator {
-public:
- XMLGenerator();
- ~XMLGenerator();
+ public:
+ XMLGenerator();
+ ~XMLGenerator();
- void makeModeXML(const std::string &filename, const Mode &mode);
- void makeUndoInfoXML(const std::string &filename, const Mode &mode);
+ void makeModeXML(const std::string &filename, const Mode &mode);
+ void makeUndoInfoXML(const std::string &filename, const Mode &mode);
-private:
- void createRootNode();
- void saveToFile(const std::string &filename);
- const std::string getModeTypeStr(Mode::ModeType t);
+ private:
+ void createRootNode();
+ void saveToFile(const std::string &filename);
+ const std::string getModeTypeStr(Mode::ModeType t);
- xmlDocPtr doc;
- xmlNodePtr rootNode;
+ xmlDocPtr doc;
+ xmlNodePtr rootNode;
};
MODES_NAMESPACE_END
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
-#include "mdss.h"
+
#include "ModesEx.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
XMLParser::XMLParser(const std::string &modeFile)
{
- doc = xmlParseFile(modeFile.c_str());
- if (NULL == doc) {
- ERR("xmlParseFile(%s) Fail", modeFile.c_str());
- throw ModesEx(ModesEx::INVALID_ARG);
- }
-
- root = xmlDocGetRootElement(doc);
- if (NULL == root) {
- xmlFreeDoc(doc);
- ERR("xmlDocGetRootElement() Fail");
- throw ModesEx(ModesEx::PARSER_ERROR, "xmlDocGetRootElement() Fail");
- }
+ doc = xmlParseFile(modeFile.c_str());
+ if (NULL == doc) {
+ ERR("xmlParseFile(%s) Fail", modeFile.c_str());
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ root = xmlDocGetRootElement(doc);
+ if (NULL == root) {
+ xmlFreeDoc(doc);
+ ERR("xmlDocGetRootElement() Fail");
+ throw ModesEx(ModesEx::PARSER_ERROR, "xmlDocGetRootElement() Fail");
+ }
}
XMLParser::~XMLParser()
{
- xmlFreeDoc(doc);
+ xmlFreeDoc(doc);
}
xmlNodePtr XMLParser::getRoot()
{
- return root;
+ return root;
}
void XMLParser::validate(const std::string &xsd)
{
- xmlSchemaPtr xsdSchema;
- xmlSchemaParserCtxtPtr ctxt;
- xmlSchemaValidCtxtPtr cvtxt;
+ xmlSchemaPtr xsdSchema;
+ xmlSchemaParserCtxtPtr ctxt;
+ xmlSchemaValidCtxtPtr cvtxt;
- ctxt = xmlSchemaNewParserCtxt(xsd.c_str());
- if (NULL == ctxt) {
- ERR("xmlSchemaNewParserCtxt(%s) Fail", xsd.c_str());
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ ctxt = xmlSchemaNewParserCtxt(xsd.c_str());
+ if (NULL == ctxt) {
+ ERR("xmlSchemaNewParserCtxt(%s) Fail", xsd.c_str());
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
- xsdSchema = xmlSchemaParse(ctxt);
- if (NULL == xsdSchema) {
- ERR("xmlSchemaParse() Fail");
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ xsdSchema = xmlSchemaParse(ctxt);
+ if (NULL == xsdSchema) {
+ ERR("xmlSchemaParse() Fail");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
- xmlSchemaFreeParserCtxt(ctxt);
+ xmlSchemaFreeParserCtxt(ctxt);
- cvtxt = xmlSchemaNewValidCtxt(xsdSchema);
+ cvtxt = xmlSchemaNewValidCtxt(xsdSchema);
- if (NULL == cvtxt ) {
- ERR("xmlSchemaNewValidCtxt() Fail");
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ if (NULL == cvtxt) {
+ ERR("xmlSchemaNewValidCtxt() Fail");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
- if (0 != xmlSchemaValidateDoc(cvtxt, doc)) {
- ERR("xmlSchemaValidateDoc() Fail");
- throw ModesEx(ModesEx::INVALID_ARG);
- }
+ if (0 != xmlSchemaValidateDoc(cvtxt, doc)) {
+ ERR("xmlSchemaValidateDoc() Fail");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
- xmlSchemaFreeValidCtxt(cvtxt);
- xmlSchemaFree(xsdSchema);
+ xmlSchemaFreeValidCtxt(cvtxt);
+ xmlSchemaFree(xsdSchema);
- // TODO: call xmlSchemaCleanupTypes() when end of this deamon.
+ // TODO: call xmlSchemaCleanupTypes() when end of this daemon.
- return;
+ return;
}
std::string XMLParser::extractValueOfTag(xmlNodePtr node, const xmlChar *tag)
{
- char *value;
+ char *value;
- value = (char*)xmlGetProp(node, tag);
- if (value == NULL) {
- WARN("attribute(%s) is NULL. ", tag);
- return std::string();
- }
+ value = (char *)xmlGetProp(node, tag);
+ if (value == NULL) {
+ WARN("attribute(%s) is NULL. ", tag);
+ return std::string();
+ }
- std::string valueStr = value;
- xmlFree(value);
- return valueStr;
+ std::string valueStr = value;
+ xmlFree(value);
+ return valueStr;
}
#pragma once
#include <libxml/tree.h>
+
#include <string>
+
#include "mdss.h"
MODES_NAMESPACE_BEGIN
class XMLParser {
-public:
- XMLParser(const std::string &xmlFile);
- ~XMLParser();
-
- xmlNodePtr getRoot();
- void validate(const std::string &xsd);
- static std::string extractValueOfTag(xmlNodePtr node, const xmlChar *tag);
-private:
- xmlDocPtr doc;
- xmlNodePtr root;
+ public:
+ XMLParser(const std::string &xmlFile);
+ ~XMLParser();
+
+ xmlNodePtr getRoot();
+ void validate(const std::string &xsd);
+ static std::string extractValueOfTag(xmlNodePtr node, const xmlChar *tag);
+
+ private:
+ xmlDocPtr doc;
+ xmlNodePtr root;
};
MODES_NAMESPACE_END
* limitations under the License.
*/
#include <stdlib.h>
+
#include <exception>
-#include "mdss.h"
-#include "Supervisor.h"
+
#include "ArgumentParser.h"
+#include "Supervisor.h"
+#include "mdss.h"
MODES_NAMESPACE_USE;
int main(int argc, char **argv)
{
#ifdef TIZEN_TEST_GCOV
- setenv("GCOV_PREFIX", "/opt/usr/daemon", 1);
+ setenv("GCOV_PREFIX", "/opt/usr/daemon", 1);
#endif
- GMainLoop *loop = g_main_loop_new(NULL, FALSE);
+ GMainLoop *loop = g_main_loop_new(NULL, FALSE);
- try {
- ArgumentParser argParser;
- ModesConfig config = argParser.parse(argc, argv);
+ try {
+ ArgumentParser argParser;
+ ModesConfig config = argParser.parse(argc, argv);
- Supervisor supervisor(config);
- supervisor.init();
- supervisor.registerHandler();
+ Supervisor supervisor(config);
+ supervisor.init();
+ supervisor.registerHandler();
- g_main_loop_run(loop);
+ g_main_loop_run(loop);
- supervisor.deInit();
- }
- catch (...) {
- ERR("Initialization Fail");
- return -1;
- }
+ supervisor.deInit();
+ } catch (...) {
+ ERR("Initialization Fail");
+ return -1;
+ }
- g_main_loop_unref(loop);
+ g_main_loop_unref(loop);
- return 0;
+ return 0;
}
-
#pragma once
extern "C" {
- #include "modes_errors.h"
- #include "common/log.h"
- #include "common/definitions.h"
+#include "common/definitions.h"
+#include "common/log.h"
+#include "modes_errors.h"
}
static gboolean apply_idler(gpointer data)
{
- int ret = modes_apply_mode(_handle, data);
- if (MODES_ERROR_NONE != ret)
- PERR("modes_apply_mode() Fail(%d)", ret);
+ int ret = modes_apply_mode(_handle, data);
+ if (MODES_ERROR_NONE != ret)
+ PERR("modes_apply_mode() Fail(%d)", ret);
- g_main_loop_quit(_modes_loop);
- return G_SOURCE_REMOVE;
+ g_main_loop_quit(_modes_loop);
+ return G_SOURCE_REMOVE;
}
static gboolean can_apply_idler(gpointer data)
{
- int ret = modes_can_apply(_handle, data);
- if (MODES_ERROR_NONE != ret)
- PERR("modes_can_apply() Fail(%d)", ret);
+ int ret = modes_can_apply(_handle, data);
+ if (MODES_ERROR_NONE != ret)
+ PERR("modes_can_apply() Fail(%d)", ret);
- g_main_loop_quit(_modes_loop);
- return G_SOURCE_REMOVE;
+ g_main_loop_quit(_modes_loop);
+ return G_SOURCE_REMOVE;
}
static gboolean undo_idler(gpointer data)
{
- int ret = modes_undo_mode(_handle, data);
- if (MODES_ERROR_NONE != ret)
- PERR("modes_undo_mode() Fail(%d)", ret);
+ int ret = modes_undo_mode(_handle, data);
+ if (MODES_ERROR_NONE != ret)
+ PERR("modes_undo_mode() Fail(%d)", ret);
- g_main_loop_quit(_modes_loop);
- return G_SOURCE_REMOVE;
+ g_main_loop_quit(_modes_loop);
+ return G_SOURCE_REMOVE;
}
static void print_usage(const char *exec_name)
{
- printf("Usage)\n");
- printf("\t%s can_apply ModeName\n", exec_name);
- printf("\t%s apply ModeName\n", exec_name);
- printf("\t%s undo ModeName\n", exec_name);
+ printf("Usage)\n");
+ printf("\t%s can_apply ModeName\n", exec_name);
+ printf("\t%s apply ModeName\n", exec_name);
+ printf("\t%s undo ModeName\n", exec_name);
}
int main(int argc, char **argv)
{
- if (3 != argc) {
- print_usage(argv[0]);
- return -1;
- }
- _handle = modes_connect();
- _modes_loop = g_main_loop_new(NULL, FALSE);
- if (0 == strcasecmp(argv[1], "apply")) {
- g_idle_add(apply_idler, argv[2]);
- } else if (0 == strcasecmp(argv[1], "can_apply")) {
- g_idle_add(can_apply_idler, argv[2]);
- } else if (0 == strcasecmp(argv[1], "undo")) {
- g_idle_add(undo_idler, argv[2]);
- } else {
- PERR("Invalid option(%s)", argv[1]);
- print_usage(argv[0]);
- }
+ if (3 != argc) {
+ print_usage(argv[0]);
+ return -1;
+ }
+ _handle = modes_connect();
+ _modes_loop = g_main_loop_new(NULL, FALSE);
+ if (0 == strcasecmp(argv[1], "apply")) {
+ g_idle_add(apply_idler, argv[2]);
+ } else if (0 == strcasecmp(argv[1], "can_apply")) {
+ g_idle_add(can_apply_idler, argv[2]);
+ } else if (0 == strcasecmp(argv[1], "undo")) {
+ g_idle_add(undo_idler, argv[2]);
+ } else {
+ PERR("Invalid option(%s)", argv[1]);
+ print_usage(argv[0]);
+ }
- g_main_loop_run(_modes_loop);
- g_main_loop_unref(_modes_loop);
+ g_main_loop_run(_modes_loop);
+ g_main_loop_unref(_modes_loop);
- modes_disconnect(_handle);
- _handle = NULL;
- return 0;
+ modes_disconnect(_handle);
+ _handle = NULL;
+ return 0;
}
#include <modes.h>
class AsyncTest : public ::testing::Test {
-protected:
- void SetUp() override
- {
- loop = g_main_loop_new(NULL, FALSE);
- handle = modes_connect();
- }
+ protected:
+ void SetUp() override
+ {
+ loop = g_main_loop_new(NULL, FALSE);
+ handle = modes_connect();
+ }
- void TearDown() override
- {
- g_main_loop_unref(loop);
- loop = NULL;
- modes_disconnect(handle);
- handle = NULL;
- }
+ void TearDown() override
+ {
+ g_main_loop_unref(loop);
+ loop = NULL;
+ modes_disconnect(handle);
+ handle = NULL;
+ }
- static gboolean ModeIdler(gpointer data)
- {
- int ret;
- ret = modes_apply_mode(handle, (char*)data);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
- sleep(1);
- ret = modes_undo_mode(handle, (char*)data);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ static gboolean ModeIdler(gpointer data)
+ {
+ int ret;
+ ret = modes_apply_mode(handle, (char *)data);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
+ sleep(1);
+ ret = modes_undo_mode(handle, (char *)data);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
- static gboolean failIdler(gpointer data)
- {
- int ret;
- ret = modes_apply_mode(handle, (char*)data);
- EXPECT_EQ(MODES_ERROR_SYSTEM, ret);
- sleep(1);
- ret = modes_undo_mode(handle, (char*)data);
- EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
+ static gboolean failIdler(gpointer data)
+ {
+ int ret;
+ ret = modes_apply_mode(handle, (char *)data);
+ EXPECT_EQ(MODES_ERROR_SYSTEM, ret);
+ sleep(1);
+ ret = modes_undo_mode(handle, (char *)data);
+ EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
- static modes_h handle;
- static GMainLoop *loop;
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+ static modes_h handle;
+ static GMainLoop *loop;
};
modes_h AsyncTest::handle = NULL;
TEST_F(AsyncTest, normalAsync)
{
- 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);
+ 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 *modeID = "http://tizen.org/mode/example.asyncEx2";
- int ret = modes_apply_mode(handle, modeID);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ 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 *modeID = "http://tizen.org/mode/example.asyncFail1";
- modes_undo_mode(handle, modeID);
- g_idle_add(failIdler, (gpointer)modeID);
- g_main_loop_run(loop);
+ 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 *modeID = "http://tizen.org/mode/example.asyncFail2";
- g_idle_add(failIdler, (gpointer)modeID);
- g_main_loop_run(loop);
+ const char *modeID = "http://tizen.org/mode/example.asyncFail2";
+ g_idle_add(failIdler, (gpointer)modeID);
+ g_main_loop_run(loop);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <iostream>
-#include <string>
#include <glib.h>
#include <gtest/gtest.h>
#include <modes.h>
+
+#include <iostream>
+#include <string>
+
#include "common/definitions.h"
class ClientTest : public ::testing::Test {
-protected:
- void SetUp() override
- {
- handle = modes_connect();
- loop = g_main_loop_new(NULL, FALSE);
- }
-
- void TearDown() override
- {
- g_main_loop_unref(loop);
- loop = NULL;
- modes_disconnect(handle);
- handle = NULL;
- }
-
- static gboolean applyModeIdler(gpointer data)
- {
- result = modes_apply_mode(handle, (char*)data);
-
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
-
- static gboolean undoModeIdler(gpointer data)
- {
- result = modes_apply_mode(handle, (char*)data);
- EXPECT_EQ(MODES_ERROR_NONE, result);
- sleep(1);
- result = modes_undo_mode(handle, (char*)data);
-
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
-
- static void addModeTest(std::string name)
- {
- 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");
-
- for (int i = 0; i < 2; i++) {
- result = modes_mode_insert_action(created_mode, action_handle[i]);
- modes_free_action(action_handle[i]); //For abnormal case
- EXPECT_EQ(MODES_ERROR_NONE, result);
- }
-
- result = modes_set_hidden(created_mode, true);
- EXPECT_EQ(MODES_ERROR_NONE, result);
-
- result = modes_add_mode(handle, created_mode);
- modes_free_mode(created_mode);
- EXPECT_EQ(MODES_ERROR_NONE, result);
-
- result = modes_apply_mode(handle, id.c_str());
- EXPECT_EQ(MODES_ERROR_NONE, result);
- }
-
- static gboolean addModeIdler(gpointer 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;
- }
-
- static gboolean removeModeIdler(gpointer data)
- {
- addModeTest((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, id.c_str());
- result = modes_remove_mode(handle, id.c_str());
- EXPECT_EQ(MODES_ERROR_NONE, result);
-
- g_main_loop_quit(loop);
- return G_SOURCE_REMOVE;
- }
-
- static modes_h handle;
- static int result;
- static GMainLoop *loop;
+ protected:
+ void SetUp() override
+ {
+ handle = modes_connect();
+ loop = g_main_loop_new(NULL, FALSE);
+ }
+
+ void TearDown() override
+ {
+ g_main_loop_unref(loop);
+ loop = NULL;
+ modes_disconnect(handle);
+ handle = NULL;
+ }
+
+ static gboolean applyModeIdler(gpointer data)
+ {
+ result = modes_apply_mode(handle, (char *)data);
+
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+
+ static gboolean undoModeIdler(gpointer data)
+ {
+ result = modes_apply_mode(handle, (char *)data);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+ sleep(1);
+ result = modes_undo_mode(handle, (char *)data);
+
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+
+ static void addModeTest(std::string name)
+ {
+ 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");
+
+ for (int i = 0; i < 2; i++) {
+ result = modes_mode_insert_action(created_mode, action_handle[i]);
+ modes_free_action(action_handle[i]); // For abnormal case
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+ }
+
+ result = modes_set_hidden(created_mode, true);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ result = modes_add_mode(handle, created_mode);
+ modes_free_mode(created_mode);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ result = modes_apply_mode(handle, id.c_str());
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+ }
+
+ static gboolean addModeIdler(gpointer 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;
+ }
+
+ static gboolean removeModeIdler(gpointer data)
+ {
+ addModeTest((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, id.c_str());
+ result = modes_remove_mode(handle, id.c_str());
+ EXPECT_EQ(MODES_ERROR_NONE, result);
+
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+
+ static modes_h handle;
+ static int result;
+ static GMainLoop *loop;
};
modes_h ClientTest::handle = NULL;
TEST_F(ClientTest, applyModeP)
{
- 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);
+ 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)"http://tizen.org/mode/example.non_ex2");
- g_main_loop_run(loop);
- EXPECT_EQ(MODES_ERROR_NO_DATA, result);
+ 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, "http://tizen.org/mode/example.ex1");
- int ret = modes_can_apply(handle, "http://tizen.org/mode/example.ex1");
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ 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, "http://tizen.org/mode/example.ex4");
- EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
+ int ret = modes_can_apply(handle, "http://tizen.org/mode/example.ex4");
+ EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
}
TEST_F(ClientTest, addMode)
{
- g_idle_add(addModeIdler, (gpointer)"created");
- g_main_loop_run(loop);
- EXPECT_EQ(MODES_ERROR_NONE, result);
+ g_idle_add(addModeIdler, (gpointer) "created");
+ g_main_loop_run(loop);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
}
TEST_F(ClientTest, removeMode)
{
- g_idle_add(removeModeIdler, (gpointer)"deltest");
- g_main_loop_run(loop);
- EXPECT_EQ(MODES_ERROR_NONE, result);
+ g_idle_add(removeModeIdler, (gpointer) "deltest");
+ g_main_loop_run(loop);
+ EXPECT_EQ(MODES_ERROR_NONE, result);
- int ret = modes_remove_mode(handle, "deltestN");
- EXPECT_EQ(MODES_ERROR_INVALID_PARAMETER, ret);
+ int ret = modes_remove_mode(handle, "deltestN");
+ EXPECT_EQ(MODES_ERROR_INVALID_PARAMETER, ret);
}
TEST_F(ClientTest, undoModeEx1)
{
- 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);
+ 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, "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);
+ 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);
}
TEST_F(ClientTest, getModes)
{
- const char* const typeList[2] = {
- "MODES_TYPE_MODE_NORMAL",
- "MODES_TYPE_MODE_ONESHOT"
- };
+ const char *const typeList[2] = {"MODES_TYPE_MODE_NORMAL", "MODES_TYPE_MODE_ONESHOT"};
- GList *list, *cur;
- int ret = modes_get_modes(handle, &list);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ 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)) {
- EXPECT_NE(nullptr, cur->data);
+ 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 *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);
+ 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 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);
+ int state = modes_get_mode_state((mode_list_data_h)cur->data);
+ EXPECT_NE(MODES_ERROR_INVALID_PARAMETER, state);
- std::cout << id << " "<< name << " " << typeList[type] << "(" << type << ") :state(" << state << ")" << std::endl;
- }
- modes_free_modes(list);
+ std::cout << id << " " << name << " " << typeList[type] << "(" << type << ") :state("
+ << state << ")" << std::endl;
+ }
+ modes_free_modes(list);
}
* limitations under the License.
*/
#include <gtest/gtest.h>
+
#include "common/definitions.h"
-#include "supervisor/ModeXMLParser.h"
#include "supervisor/ModeCareTaker.h"
+#include "supervisor/ModeXMLParser.h"
MODES_NAMESPACE_USE;
MODES_NAMESPACE_BEGIN
class ConflictTest : public ::testing::Test {
-public:
- ConflictTest();
-protected:
- void SetUp() override
- {
- ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
- careTaker.pushMode(modeparser.getMode());
- }
+ public:
+ ConflictTest();
+
+ protected:
+ void SetUp() override
+ {
+ ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
+ careTaker.pushMode(modeparser.getMode());
+ }
- void TearDown() override
- {
- Mode mode;
- careTaker.popMode("http://tizen.org/mode/example.conflict1", mode);
- }
+ void TearDown() override
+ {
+ Mode mode;
+ careTaker.popMode("http://tizen.org/mode/example.conflict1", mode);
+ }
- bool checkConflictAction(const Mode &mode)
- {
- return careTaker.checkConflictAction(mode);
- }
+ bool checkConflictAction(const Mode &mode) { return careTaker.checkConflictAction(mode); }
- RuleManager ruleMgr;
- ModeCareTaker careTaker;
+ RuleManager ruleMgr;
+ ModeCareTaker careTaker;
};
MODES_NAMESPACE_END
ConflictTest::ConflictTest()
- : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR), careTaker(".")
+ : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
+ careTaker(".")
{
- ruleMgr.start();
+ ruleMgr.start();
}
TEST_F(ConflictTest, isSavedMode)
{
- ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
- EXPECT_TRUE(careTaker.isSavedMode(mode.getID()));
+ ModeXMLParser modeparser("tizen_conflictErrBase_mode.xml", ruleMgr);
+ Mode mode = modeparser.getMode();
+ EXPECT_TRUE(careTaker.isSavedMode(mode.getID()));
}
TEST_F(ConflictTest, checkConflictAction)
{
- ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
+ ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
- EXPECT_TRUE(checkConflictAction(mode));
+ Mode mode = modeparser.getMode();
+ EXPECT_TRUE(checkConflictAction(mode));
}
TEST_F(ConflictTest, isConflict)
{
- ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
- EXPECT_TRUE(careTaker.isConflict(modeparser.getMode()));
+ ModeXMLParser modeparser("tizen_conflictErr_mode.xml", ruleMgr);
+ EXPECT_TRUE(careTaker.isConflict(modeparser.getMode()));
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <gtest/gtest.h>
#include <memory.h>
+
#include <iostream>
-#include <gtest/gtest.h>
+
#include "supervisor/Mode.h"
+#include "supervisor/ModeXMLParser.h"
#include "supervisor/ModesEx.h"
#include "supervisor/RuleManager.h"
#include "supervisor/XMLGenerator.h"
-#include "supervisor/ModeXMLParser.h"
using namespace std;
MODES_NAMESPACE_USE;
MODES_NAMESPACE_BEGIN
class GeneratorTest : public ::testing::Test {
-public:
- GeneratorTest();
-
-protected:
- void SetUp() override
- {
- }
-
- void TearDown() override
- {
- if (0 != remove(genXmlPath.c_str()) && ENOENT != errno) {
- ERR("remove(%s) Fail(%d)", genXmlPath.c_str(), errno);
- FAIL();
- }
- }
-
- RuleManager ruleMgr;
- const string genXmlPath;
+ public:
+ GeneratorTest();
+
+ protected:
+ void SetUp() override {}
+
+ void TearDown() override
+ {
+ if (0 != remove(genXmlPath.c_str()) && ENOENT != errno) {
+ ERR("remove(%s) Fail(%d)", genXmlPath.c_str(), errno);
+ FAIL();
+ }
+ }
+
+ RuleManager ruleMgr;
+ const string genXmlPath;
};
MODES_NAMESPACE_END
GeneratorTest::GeneratorTest()
- : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
- genXmlPath("tizen_generatedEx1_mode.xml")
+ : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
+ genXmlPath("tizen_generatedEx1_mode.xml")
{
- ruleMgr.start();
+ ruleMgr.start();
}
TEST_F(GeneratorTest, makeModeXML)
{
- ModeXMLParser modeParser("tizen_normalEx1_mode.xml", ruleMgr);
- Mode mode = modeParser.getMode();
-
- try {
- XMLGenerator xmlGenerator;
- xmlGenerator.makeModeXML(genXmlPath, mode);
- } catch (ModesEx &e) {
- ERR("XMLGenerator(%s) Fail(%s)", genXmlPath.c_str(), e.what());
- FAIL();
- }
-
- ModeXMLParser genModeParser(genXmlPath, ruleMgr);
- Mode genMode = genModeParser.getMode();
-
- EXPECT_EQ("ex1", genMode.getName());
- std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
- EXPECT_FALSE(actionList.empty());
-
- for (std::list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
- cout << "* Action : " << (*it)->getRuleName() << endl;
- cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
- cout << "\t\t- Content : " << (*it)->getStringOfValue() << endl;
- }
-
- try {
- XMLGenerator xmlGenerator;
- xmlGenerator.makeModeXML(genXmlPath, mode);
- } catch (ModesEx &e) {
- if (e.getErrCode() != ModesEx::SYSTEM_ERROR) {
- ERR("XMLGenerator(%s) Fail(%s)", genXmlPath.c_str(), e.what());
- FAIL();
- }
-
- return;
- }
- FAIL();
+ ModeXMLParser modeParser("tizen_normalEx1_mode.xml", ruleMgr);
+ Mode mode = modeParser.getMode();
+
+ try {
+ XMLGenerator xmlGenerator;
+ xmlGenerator.makeModeXML(genXmlPath, mode);
+ } catch (ModesEx &e) {
+ ERR("XMLGenerator(%s) Fail(%s)", genXmlPath.c_str(), e.what());
+ FAIL();
+ }
+
+ ModeXMLParser genModeParser(genXmlPath, ruleMgr);
+ Mode genMode = genModeParser.getMode();
+
+ EXPECT_EQ("ex1", genMode.getName());
+ std::list<std::shared_ptr<Action>> actionList = mode.getActionList();
+ EXPECT_FALSE(actionList.empty());
+
+ for (std::list<std::shared_ptr<Action>>::iterator it = actionList.begin();
+ it != actionList.end(); ++it) {
+ cout << "* Action : " << (*it)->getRuleName() << endl;
+ cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
+ cout << "\t\t- Content : " << (*it)->getStringOfValue() << endl;
+ }
+
+ try {
+ XMLGenerator xmlGenerator;
+ xmlGenerator.makeModeXML(genXmlPath, mode);
+ } catch (ModesEx &e) {
+ if (e.getErrCode() != ModesEx::SYSTEM_ERROR) {
+ ERR("XMLGenerator(%s) Fail(%s)", genXmlPath.c_str(), e.what());
+ FAIL();
+ }
+
+ return;
+ }
+ FAIL();
}
TEST_F(GeneratorTest, exFileName)
{
- ModeXMLParser modeParser("tizen_normalEx1_mode.xml", ruleMgr);
- Mode mode = modeParser.getMode();
+ ModeXMLParser modeParser("tizen_normalEx1_mode.xml", ruleMgr);
+ Mode mode = modeParser.getMode();
- EXPECT_THROW({
- XMLGenerator xmlGenerator;
- xmlGenerator.makeModeXML("", mode);
- }, ModesEx);
+ EXPECT_THROW(
+ {
+ XMLGenerator xmlGenerator;
+ xmlGenerator.makeModeXML("", mode);
+ },
+ ModesEx);
}
*/
#include <gtest/gtest.h>
-int main(int argc, char **argv) {
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <iostream>
-#include <exception>
#include <gtest/gtest.h>
+
+#include <exception>
+#include <iostream>
+
#include "supervisor/ModeManager.h"
using namespace std;
MODES_NAMESPACE_BEGIN
class ModeManagerTest {
-public:
- ModeManagerTest();
- RuleManager rMgr;
- ModeManager mdMgr;
-
- set<string> getDirectories();
- bool emptyModeMap();
- void printModeMap();
+ public:
+ ModeManagerTest();
+ RuleManager rMgr;
+ ModeManager mdMgr;
+
+ set<string> getDirectories();
+ bool emptyModeMap();
+ void printModeMap();
};
MODES_NAMESPACE_END
ModeManagerTest::ModeManagerTest()
- : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
- mdMgr(set<string>(), "./" MODES_MODE_DEFAULT_XSD_FILE, rMgr)
+ : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR),
+ mdMgr(set<string>(), "./" MODES_MODE_DEFAULT_XSD_FILE, rMgr)
{
- rMgr.start();
- mdMgr.modeDirList.insert(".");
- mdMgr.init();
+ rMgr.start();
+ mdMgr.modeDirList.insert(".");
+ mdMgr.init();
}
-set<string> ModeManagerTest::getDirectories()
+set<string> ModeManagerTest::getDirectories()
{
- return mdMgr.modeDirList;
+ return mdMgr.modeDirList;
}
bool ModeManagerTest::emptyModeMap()
{
- return mdMgr.modeMap.empty();
+ return mdMgr.modeMap.empty();
}
void ModeManagerTest::printModeMap()
{
- static const char* const mode_type[3] = {
- "MODE_NORMAL",
- "MODE_ONESHOT",
- "MODE_EXCLUSIVE" };
-
- if (!mdMgr.modeMap.empty()) {
- 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(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";
- cout << endl;
- }
- }
+ static const char *const mode_type[3] = {"MODE_NORMAL", "MODE_ONESHOT", "MODE_EXCLUSIVE"};
+
+ if (!mdMgr.modeMap.empty()) {
+ 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(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";
+ cout << endl;
+ }
+ }
}
TEST(ModeManager, setOptions)
{
- ModeManagerTest mdMgrTest;
+ ModeManagerTest mdMgrTest;
- EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
+ EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
- mdMgrTest.printModeMap();
+ mdMgrTest.printModeMap();
}
TEST(ModeManager, addModeDirectory)
{
- ModeManagerTest mdMgrTest;
+ ModeManagerTest mdMgrTest;
- string dir_extra = "./extra";
- try {
- mdMgrTest.mdMgr.addModeDirectory(dir_extra);
- }
- catch (exception &e) {
- ADD_FAILURE() << "Fail to append : " << e.what() << endl;
- return;
- }
+ string dir_extra = "./extra";
+ try {
+ mdMgrTest.mdMgr.addModeDirectory(dir_extra);
+ } catch (exception &e) {
+ ADD_FAILURE() << "Fail to append : " << e.what() << endl;
+ return;
+ }
- EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
+ EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
- mdMgrTest.printModeMap();
+ mdMgrTest.printModeMap();
}
TEST(ModeManager, addModeDirectory_withwrongdir)
{
- ModeManagerTest mdMgrTest;
-
- string dir_wrong = "./dir_wrong";
- try {
- mdMgrTest.mdMgr.addModeDirectory(dir_wrong);
- }
- catch (exception &e) {
- cout << "Fail to append : " << e.what() << endl;
- return;
- }
-
- ADD_FAILURE() << "addModeDirectory() did not detect a wrong directory!" << endl;
+ ModeManagerTest mdMgrTest;
+
+ string dir_wrong = "./dir_wrong";
+ try {
+ mdMgrTest.mdMgr.addModeDirectory(dir_wrong);
+ } catch (exception &e) {
+ cout << "Fail to append : " << e.what() << endl;
+ return;
+ }
+
+ ADD_FAILURE() << "addModeDirectory() did not detect a wrong directory!" << endl;
}
TEST(ModeManager, addModeDirectory_withappendeddir)
{
- ModeManagerTest mdMgrTest;
-
- string dir_extra = "./extra";
- try {
- mdMgrTest.mdMgr.addModeDirectory(dir_extra);
- }
- catch (exception &e) {
- cout << "Fail to append : " << e.what() << endl;
- ADD_FAILURE();
- return;
- }
- EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
- mdMgrTest.printModeMap();
-
- string dir_appended = dir_extra;
- try {
- mdMgrTest.mdMgr.addModeDirectory(dir_appended);
- }
- catch (exception &e) {
- cout << "Fail to append : " << e.what() << endl;
- return;
- }
-
- ADD_FAILURE() << "addModeDirectory() did not detect a directory that is already attached!" << endl;
+ ModeManagerTest mdMgrTest;
+
+ string dir_extra = "./extra";
+ try {
+ mdMgrTest.mdMgr.addModeDirectory(dir_extra);
+ } catch (exception &e) {
+ cout << "Fail to append : " << e.what() << endl;
+ ADD_FAILURE();
+ return;
+ }
+ EXPECT_FALSE(mdMgrTest.emptyModeMap()) << "Mode Map is empty!" << endl;
+ mdMgrTest.printModeMap();
+
+ string dir_appended = dir_extra;
+ try {
+ mdMgrTest.mdMgr.addModeDirectory(dir_appended);
+ } catch (exception &e) {
+ cout << "Fail to append : " << e.what() << endl;
+ return;
+ }
+
+ ADD_FAILURE() << "addModeDirectory() did not detect a directory that is already attached!"
+ << endl;
}
#include <modes.h>
class ClientNotiTest : public ::testing::Test {
-protected:
- void SetUp() override
- {
- handle = modes_connect();
- loop = g_main_loop_new(NULL, FALSE);
- }
-
- void TearDown() override
- {
- g_main_loop_unref(loop);
- loop = NULL;
- modes_disconnect(handle);
- handle = NULL;
- }
-
- static gboolean undoTimeout(gpointer data)
- {
- expectedState = 0;
- int ret = modes_undo_mode(handle, (const char*)data);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
-
- return G_SOURCE_REMOVE;
- }
-
- static int notiFunc(const char *modeID, int state, void *user_data)
- {
- char *requestMode = (char*)user_data;
-
- std::cout << "notiFunc Changed Mode : " << modeID << std::endl;
- EXPECT_EQ(requestMode, std::string(modeID));
- std::cout << "state : " << state << std::endl;
- EXPECT_EQ(expectedState, state);
-
- if (0 == expectedState)
- g_main_loop_quit(loop);
- return MODES_ERROR_NONE;
- }
-
- static int changeFn(const char *modeID, int state, void *user_data)
- {
- char *requestMode = (char*)user_data;
-
- std::cout << "changeFn Changed Mode : " << modeID << std::endl;
- EXPECT_EQ(requestMode, std::string(modeID));
- std::cout << "state : " << state << std::endl;
-
- if (0 == state)
- g_main_loop_quit(loop);
-
- return MODES_ERROR_NONE;
- }
-
- static int notiMultiFunc1(const char *modeID, int state, void *user_data)
- {
- std::cout << "notiMultiFunc1 Changed Mode : " << modeID << std::endl;
- std::cout << "state : " << state << std::endl;
-
- calledbit1 |= 0x1 << state;
-
- return MODES_ERROR_NONE;
- }
-
- static int notiMultiFunc2(const char *modeID, int state, void *user_data)
- {
- std::cout << "notiMultiFunc2 Changed Mode : " << modeID << std::endl;
- std::cout << "state : " << state << std::endl;
-
- calledbit2 |= 0x1 << state;
-
- return MODES_ERROR_NONE;
- }
-
- static int notiMultiFunc3(const char *modeID, int state, void *user_data)
- {
- std::cout << "notiMultiFunc3 Changed Mode : " << modeID << std::endl;
- std::cout << "state : " << state << std::endl;
-
- EXPECT_TRUE(NULL == user_data || notiTestMode == user_data);
-
- if (NULL == user_data)
- calledbit3 |= 0x1 << state;
- if (notiTestMode == user_data)
- calledbit4 |= 0x1 << state;
-
- if (0x3 == calledbit3 && 0x3 == calledbit4)
- g_main_loop_quit(loop);
-
- return MODES_ERROR_NONE;
- }
-
-
- static modes_h handle;
- static int expectedState;
- static GMainLoop *loop;
- static unsigned char calledbit1;
- static unsigned char calledbit2;
- static unsigned char calledbit3;
- static unsigned char calledbit4;
- static const char *notiTestMode;
+ protected:
+ void SetUp() override
+ {
+ handle = modes_connect();
+ loop = g_main_loop_new(NULL, FALSE);
+ }
+
+ void TearDown() override
+ {
+ g_main_loop_unref(loop);
+ loop = NULL;
+ modes_disconnect(handle);
+ handle = NULL;
+ }
+
+ static gboolean undoTimeout(gpointer data)
+ {
+ expectedState = 0;
+ int ret = modes_undo_mode(handle, (const char *)data);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+ return G_SOURCE_REMOVE;
+ }
+
+ static int notiFunc(const char *modeID, int state, void *user_data)
+ {
+ char *requestMode = (char *)user_data;
+
+ std::cout << "notiFunc Changed Mode : " << modeID << std::endl;
+ EXPECT_EQ(requestMode, std::string(modeID));
+ std::cout << "state : " << state << std::endl;
+ EXPECT_EQ(expectedState, state);
+
+ if (0 == expectedState)
+ g_main_loop_quit(loop);
+ return MODES_ERROR_NONE;
+ }
+
+ static int changeFn(const char *modeID, int state, void *user_data)
+ {
+ char *requestMode = (char *)user_data;
+
+ std::cout << "changeFn Changed Mode : " << modeID << std::endl;
+ EXPECT_EQ(requestMode, std::string(modeID));
+ std::cout << "state : " << state << std::endl;
+
+ if (0 == state)
+ g_main_loop_quit(loop);
+
+ return MODES_ERROR_NONE;
+ }
+
+ static int notiMultiFunc1(const char *modeID, int state, void *user_data)
+ {
+ std::cout << "notiMultiFunc1 Changed Mode : " << modeID << std::endl;
+ std::cout << "state : " << state << std::endl;
+
+ calledbit1 |= 0x1 << state;
+
+ return MODES_ERROR_NONE;
+ }
+
+ static int notiMultiFunc2(const char *modeID, int state, void *user_data)
+ {
+ std::cout << "notiMultiFunc2 Changed Mode : " << modeID << std::endl;
+ std::cout << "state : " << state << std::endl;
+
+ calledbit2 |= 0x1 << state;
+
+ return MODES_ERROR_NONE;
+ }
+
+ static int notiMultiFunc3(const char *modeID, int state, void *user_data)
+ {
+ std::cout << "notiMultiFunc3 Changed Mode : " << modeID << std::endl;
+ std::cout << "state : " << state << std::endl;
+
+ EXPECT_TRUE(NULL == user_data || notiTestMode == user_data);
+
+ if (NULL == user_data)
+ calledbit3 |= 0x1 << state;
+ if (notiTestMode == user_data)
+ calledbit4 |= 0x1 << state;
+
+ if (0x3 == calledbit3 && 0x3 == calledbit4)
+ g_main_loop_quit(loop);
+
+ return MODES_ERROR_NONE;
+ }
+
+ static modes_h handle;
+ static int expectedState;
+ static GMainLoop *loop;
+ static unsigned char calledbit1;
+ static unsigned char calledbit2;
+ static unsigned char calledbit3;
+ static unsigned char calledbit4;
+ static const char *notiTestMode;
};
modes_h ClientNotiTest::handle = NULL;
TEST_F(ClientNotiTest, subscribeCB)
{
- 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);
+ 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);
- ClientNotiTest::expectedState = 1;
- int ret = modes_apply_mode(handle, testMode);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ ClientNotiTest::expectedState = 1;
+ int ret = modes_apply_mode(handle, testMode);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
- g_timeout_add_seconds(1, undoTimeout, (void*)testMode);
+ g_timeout_add_seconds(1, undoTimeout, (void *)testMode);
- g_main_loop_run(loop);
+ g_main_loop_run(loop);
- modes_unsubscribe_mode_changes(handle, id);
+ modes_unsubscribe_mode_changes(handle, id);
}
TEST_F(ClientNotiTest, subscribeMultiCb)
{
- calledbit1 = 0;
- calledbit2 = 0;
- calledbit3 = 0;
+ calledbit1 = 0;
+ calledbit2 = 0;
+ calledbit3 = 0;
- modes_noti_ID id1 = modes_subscribe_mode_changes(handle, notiMultiFunc1, NULL);
- EXPECT_NE(nullptr, id1);
+ modes_noti_ID id1 = modes_subscribe_mode_changes(handle, notiMultiFunc1, NULL);
+ EXPECT_NE(nullptr, id1);
- modes_noti_ID id2 = modes_subscribe_mode_changes(handle, notiMultiFunc2, NULL);
- EXPECT_NE(nullptr, id2);
+ modes_noti_ID id2 = modes_subscribe_mode_changes(handle, notiMultiFunc2, NULL);
+ EXPECT_NE(nullptr, id2);
- modes_noti_ID id3 = modes_subscribe_mode_changes(handle, notiMultiFunc3, (void*)notiTestMode);
- EXPECT_NE(nullptr, id3);
+ modes_noti_ID id3 = modes_subscribe_mode_changes(handle, notiMultiFunc3, (void *)notiTestMode);
+ EXPECT_NE(nullptr, id3);
- modes_noti_ID id4 = modes_subscribe_mode_changes(handle, notiMultiFunc3, NULL);
- EXPECT_NE(nullptr, id4);
+ modes_noti_ID id4 = modes_subscribe_mode_changes(handle, notiMultiFunc3, NULL);
+ EXPECT_NE(nullptr, id4);
- int ret = modes_apply_mode(handle, notiTestMode);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ int ret = modes_apply_mode(handle, notiTestMode);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
- g_timeout_add_seconds(1, undoTimeout, (void*)notiTestMode);
- g_main_loop_run(loop);
+ g_timeout_add_seconds(1, undoTimeout, (void *)notiTestMode);
+ g_main_loop_run(loop);
- modes_unsubscribe_mode_changes(handle, id1);
- modes_unsubscribe_mode_changes(handle, id2);
- modes_unsubscribe_mode_changes(handle, id3);
- modes_unsubscribe_mode_changes(handle, id4);
+ modes_unsubscribe_mode_changes(handle, id1);
+ modes_unsubscribe_mode_changes(handle, id2);
+ modes_unsubscribe_mode_changes(handle, id3);
+ modes_unsubscribe_mode_changes(handle, id4);
- EXPECT_EQ(calledbit1, 1 << 0 | 1 << 1);
- EXPECT_EQ(calledbit2, 1 << 0 | 1 << 1);
- EXPECT_EQ(calledbit3, 1 << 0 | 1 << 1);
- EXPECT_EQ(calledbit4, 1 << 0 | 1 << 1);
+ EXPECT_EQ(calledbit1, 1 << 0 | 1 << 1);
+ EXPECT_EQ(calledbit2, 1 << 0 | 1 << 1);
+ EXPECT_EQ(calledbit3, 1 << 0 | 1 << 1);
+ EXPECT_EQ(calledbit4, 1 << 0 | 1 << 1);
}
TEST_F(ClientNotiTest, essentialAction)
{
- 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);
+ 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);
- int ret = modes_apply_mode(handle, testMode);
- EXPECT_EQ(MODES_ERROR_NONE, ret);
+ int ret = modes_apply_mode(handle, testMode);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
- g_main_loop_run(loop);
+ g_main_loop_run(loop);
- modes_unsubscribe_mode_changes(handle, id);
+ modes_unsubscribe_mode_changes(handle, id);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <gtest/gtest.h>
+
#include <iostream>
#include <memory>
-#include <gtest/gtest.h>
+
#include "supervisor/Mode.h"
+#include "supervisor/ModeXMLParser.h"
#include "supervisor/ModesEx.h"
#include "supervisor/RuleManager.h"
-#include "supervisor/ModeXMLParser.h"
using namespace std;
MODES_NAMESPACE_USE;
MODES_NAMESPACE_BEGIN
class ParserTest : public ::testing::Test {
-public:
- ParserTest();
+ public:
+ ParserTest();
- void parserTest(const string &fileName);
- list<shared_ptr<Action>> getActionList(Mode& m);
+ void parserTest(const string& fileName);
+ list<shared_ptr<Action>> getActionList(Mode& m);
-protected:
- void SetUp() override
- {
- }
+ protected:
+ void SetUp() override {}
- void TearDown() override
- {
- }
+ void TearDown() override {}
- RuleManager ruleMgr;
+ RuleManager ruleMgr;
};
MODES_NAMESPACE_END
ParserTest::ParserTest()
- : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
+ : ruleMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
{
- ruleMgr.start();
+ ruleMgr.start();
}
list<shared_ptr<Action>> ParserTest::getActionList(Mode& m)
{
- return m.actionList;
+ return m.actionList;
}
TEST_F(ParserTest, modeGetName)
{
- ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
- EXPECT_EQ("ex2", mode.getName());
+ ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
+ Mode mode = modeparser.getMode();
+ EXPECT_EQ("ex2", mode.getName());
}
TEST_F(ParserTest, isHiddenTrue)
{
- ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
- EXPECT_EQ(true, mode.isHidden());
+ ModeXMLParser modeparser("tizen_normalEx2_mode.xml", ruleMgr);
+ Mode mode = modeparser.getMode();
+ EXPECT_EQ(true, mode.isHidden());
}
TEST_F(ParserTest, isHiddenFalse)
{
- ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
- EXPECT_EQ(false, mode.isHidden());
+ ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
+ Mode mode = modeparser.getMode();
+ EXPECT_EQ(false, mode.isHidden());
}
TEST_F(ParserTest, getModeType)
{
- ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
- EXPECT_EQ(Mode::MODE_NORMAL, mode.getModeType());
+ ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
+ Mode mode = modeparser.getMode();
+ EXPECT_EQ(Mode::MODE_NORMAL, mode.getModeType());
}
TEST_F(ParserTest, printAction)
{
- ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
- Mode mode = modeparser.getMode();
-
- list<std::shared_ptr<Action>> actionList = getActionList(mode);
- EXPECT_FALSE(actionList.empty());
-
- for (list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end(); ++it) {
- cout << "* Action : " << (*it)->getRuleName() << endl;
- cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
- //cout << "\t\t- Content : " << (*it)->getValue() << endl;
- }
+ ModeXMLParser modeparser("tizen_normalEx1_mode.xml", ruleMgr);
+ Mode mode = modeparser.getMode();
+
+ list<std::shared_ptr<Action>> actionList = getActionList(mode);
+ EXPECT_FALSE(actionList.empty());
+
+ for (list<std::shared_ptr<Action>>::iterator it = actionList.begin(); it != actionList.end();
+ ++it) {
+ cout << "* Action : " << (*it)->getRuleName() << endl;
+ cout << "\t\t- Restrict : " << (*it)->getRestrict() << endl;
+ // cout << "\t\t- Content : " << (*it)->getValue() << endl;
+ }
}
TEST_F(ParserTest, invalidActionValue)
{
- ModeXMLParser modeparser1("tizen_invalidValErr1_mode.xml", ruleMgr);
- EXPECT_THROW(modeparser1.getMode(), ModesEx);
+ ModeXMLParser modeparser1("tizen_invalidValErr1_mode.xml", ruleMgr);
+ EXPECT_THROW(modeparser1.getMode(), ModesEx);
- ModeXMLParser modeparser2("tizen_invalidValErr2_mode.xml", ruleMgr);
- EXPECT_THROW(modeparser2.getMode(), ModesEx);
+ ModeXMLParser modeparser2("tizen_invalidValErr2_mode.xml", ruleMgr);
+ EXPECT_THROW(modeparser2.getMode(), ModesEx);
}
TEST_F(ParserTest, validateAsyncStopOnErr)
{
- ModeXMLParser modeparser("tizen_asyncValidErr_mode.xml", ruleMgr);
+ ModeXMLParser modeparser("tizen_asyncValidErr_mode.xml", ruleMgr);
- EXPECT_THROW(modeparser.getMode(), ModesEx);
+ EXPECT_THROW(modeparser.getMode(), ModesEx);
}
TEST_F(ParserTest, printError)
{
- EXPECT_NO_THROW(
- std::cout << "MODES_ERROR_NONE " << MODES_ERROR_NONE << std::endl;
- std::cout << "MODES_ERROR_ALREADY " << MODES_ERROR_ALREADY << std::endl;
- std::cout << "MODES_ERROR_NO_DATA " << MODES_ERROR_NO_DATA << std::endl;
- std::cout << "MODES_ERROR_TIMEOUT " << MODES_ERROR_TIMEOUT << std::endl;
- std::cout << "MODES_ERROR_IO_ERROR " << MODES_ERROR_IO_ERROR << std::endl;
- std::cout << "MODES_ERROR_NOT_SUPPORTED " << MODES_ERROR_NOT_SUPPORTED << std::endl;
- std::cout << "MODES_ERROR_OUT_OF_MEMORY " << MODES_ERROR_OUT_OF_MEMORY << std::endl;
- std::cout << "MODES_ERROR_PERMISSION_DENIED " << MODES_ERROR_PERMISSION_DENIED << std::endl;
- std::cout << "MODES_ERROR_INVALID_PARAMETER " << MODES_ERROR_INVALID_PARAMETER << std::endl;
- std::cout << "MODES_ERROR_SYSTEM " << MODES_ERROR_SYSTEM << std::endl;
- std::cout << "MODES_ERROR_CONFLICT " << MODES_ERROR_CONFLICT << std::endl;
- );
+ EXPECT_NO_THROW(
+ std::cout << "MODES_ERROR_NONE " << MODES_ERROR_NONE << std::endl;
+ std::cout << "MODES_ERROR_ALREADY " << MODES_ERROR_ALREADY << std::endl;
+ std::cout << "MODES_ERROR_NO_DATA " << MODES_ERROR_NO_DATA << std::endl;
+ std::cout << "MODES_ERROR_TIMEOUT " << MODES_ERROR_TIMEOUT << std::endl;
+ std::cout << "MODES_ERROR_IO_ERROR " << MODES_ERROR_IO_ERROR << std::endl;
+ std::cout << "MODES_ERROR_NOT_SUPPORTED " << MODES_ERROR_NOT_SUPPORTED << std::endl;
+ std::cout << "MODES_ERROR_OUT_OF_MEMORY " << MODES_ERROR_OUT_OF_MEMORY << std::endl;
+ std::cout << "MODES_ERROR_PERMISSION_DENIED " << MODES_ERROR_PERMISSION_DENIED
+ << std::endl;
+ std::cout << "MODES_ERROR_INVALID_PARAMETER " << MODES_ERROR_INVALID_PARAMETER
+ << std::endl;
+ std::cout << "MODES_ERROR_SYSTEM " << MODES_ERROR_SYSTEM << std::endl;
+ std::cout << "MODES_ERROR_CONFLICT " << MODES_ERROR_CONFLICT << std::endl;);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <iostream>
#include <gtest/gtest.h>
-#include "supervisor/PluginMapper.h"
-#include "supervisor/ModesEx.h"
+
+#include <iostream>
+
#include "ModesPlugin.h"
+#include "supervisor/ModesEx.h"
+#include "supervisor/PluginMapper.h"
using namespace std;
MODES_NAMESPACE_BEGIN
class TestPluginBroker {
-public:
- TestPluginBroker();
+ public:
+ TestPluginBroker();
- bool emptyPluginMap();
- string getpluginDir();
- void checkTestPlugin(Plugin *plugin);
+ bool emptyPluginMap();
+ string getpluginDir();
+ void checkTestPlugin(Plugin *plugin);
- PluginMapper piMapper;
+ PluginMapper piMapper;
};
class TmpPlugin : public Plugin {
-private:
- int count;
- struct TmpAction : public PluginAction {
- int &ref;
- TmpAction(int &count)
- : PluginAction("tmp"), ref(count)
- {
- ref++;
- }
- ~TmpAction()
- {
- ref--;
- }
- };
-public:
- TmpPlugin()
- {
- count = 0;
- setName("temp");
- }
- ~TmpPlugin() override = default;
-
- PluginAction* newAction(const std::string &key) override
- {
- return new TmpAction(count);
- }
- int getCount()
- {
- return count;
- }
+ private:
+ int count;
+ struct TmpAction : public PluginAction {
+ int &ref;
+ TmpAction(int &count) : PluginAction("tmp"), ref(count) { ref++; }
+ ~TmpAction() { ref--; }
+ };
+
+ public:
+ TmpPlugin()
+ {
+ count = 0;
+ setName("temp");
+ }
+ ~TmpPlugin() override = default;
+
+ PluginAction *newAction(const std::string &key) override { return new TmpAction(count); }
+ int getCount() { return count; }
};
MODES_NAMESPACE_END
MODES_NAMESPACE_USE;
-TestPluginBroker::TestPluginBroker()
- : piMapper("../../.." MODES_PLUGIN_DEFAULT_DIR)
+TestPluginBroker::TestPluginBroker() : piMapper("../../.." MODES_PLUGIN_DEFAULT_DIR)
{
}
bool TestPluginBroker::emptyPluginMap()
{
- return piMapper.pluginMap.empty();
+ return piMapper.pluginMap.empty();
}
string TestPluginBroker::getpluginDir()
{
- return piMapper.pluginDir;
+ return piMapper.pluginDir;
}
void TestPluginBroker::checkTestPlugin(Plugin *plugin)
{
- PluginAction *piAction = plugin->newAction("changeAccuracy");
- EXPECT_EQ(piAction->set(0), MODES_ERROR_NONE);
- EXPECT_EQ(piAction->set(false), MODES_ERROR_NOT_SUPPORTED);
- EXPECT_EQ(piAction->getUndoInfo(), string("changeAccuracy"));
- EXPECT_EQ(piAction->setUndoInfo("test"), MODES_ERROR_NONE);
- plugin->deleteAction(piAction);
-
- piAction = plugin->newAction("printBool");
- EXPECT_EQ(piAction->set(false), MODES_ERROR_NONE);
- EXPECT_EQ(piAction->set(3), MODES_ERROR_NOT_SUPPORTED);
- EXPECT_EQ(piAction->set(3.3), MODES_ERROR_NOT_SUPPORTED);
- plugin->deleteAction(piAction);
-
- piAction = plugin->newAction("alwaysSameValue");
- EXPECT_EQ(piAction->IsCurrentValue(string("Always true")), true);
- EXPECT_EQ(piAction->set(string("String value")), MODES_ERROR_NOT_SUPPORTED);
- plugin->deleteAction(piAction);
-
- piAction = plugin->newAction("exactness");
- EXPECT_EQ(piAction->set(0), MODES_ERROR_NONE);
- plugin->deleteAction(piAction);
-
- piAction = plugin->newAction("nightLight");
- EXPECT_EQ(piAction->set(0), MODES_ERROR_NONE);
- plugin->deleteAction(piAction);
+ PluginAction *piAction = plugin->newAction("changeAccuracy");
+ EXPECT_EQ(piAction->set(0), MODES_ERROR_NONE);
+ EXPECT_EQ(piAction->set(false), MODES_ERROR_NOT_SUPPORTED);
+ EXPECT_EQ(piAction->getUndoInfo(), string("changeAccuracy"));
+ EXPECT_EQ(piAction->setUndoInfo("test"), MODES_ERROR_NONE);
+ plugin->deleteAction(piAction);
+
+ piAction = plugin->newAction("printBool");
+ EXPECT_EQ(piAction->set(false), MODES_ERROR_NONE);
+ EXPECT_EQ(piAction->set(3), MODES_ERROR_NOT_SUPPORTED);
+ EXPECT_EQ(piAction->set(3.3), MODES_ERROR_NOT_SUPPORTED);
+ plugin->deleteAction(piAction);
+
+ piAction = plugin->newAction("alwaysSameValue");
+ EXPECT_EQ(piAction->IsCurrentValue(string("Always true")), true);
+ EXPECT_EQ(piAction->set(string("String value")), MODES_ERROR_NOT_SUPPORTED);
+ plugin->deleteAction(piAction);
+
+ piAction = plugin->newAction("exactness");
+ EXPECT_EQ(piAction->set(0), MODES_ERROR_NONE);
+ plugin->deleteAction(piAction);
+
+ piAction = plugin->newAction("nightLight");
+ EXPECT_EQ(piAction->set(0), MODES_ERROR_NONE);
+ plugin->deleteAction(piAction);
}
TEST(PluginMapper, readLibraryList)
{
- TestPluginBroker broker;
-
- EXPECT_NO_THROW(broker.piMapper.loadPlugins());
- EXPECT_FALSE(broker.emptyPluginMap());
-
- list<string> pluginList = broker.piMapper.getPluginList();
- if (pluginList.empty()) {
- FAIL() << "getPluginList() Fail:This should never be reached";
- } else {
- for (auto it = pluginList.begin(); it != pluginList.end(); ++it)
- printf("plugin library : %s\n", it->c_str());
- }
+ TestPluginBroker broker;
+
+ EXPECT_NO_THROW(broker.piMapper.loadPlugins());
+ EXPECT_FALSE(broker.emptyPluginMap());
+
+ list<string> pluginList = broker.piMapper.getPluginList();
+ if (pluginList.empty()) {
+ FAIL() << "getPluginList() Fail:This should never be reached";
+ } else {
+ for (auto it = pluginList.begin(); it != pluginList.end(); ++it)
+ printf("plugin library : %s\n", it->c_str());
+ }
}
TEST(PluginMapper, unloadClassMap)
{
- TestPluginBroker broker;
+ TestPluginBroker broker;
- int ret = broker.piMapper.unloadPlugins();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_TRUE(broker.emptyPluginMap());
+ int ret = broker.piMapper.unloadPlugins();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_TRUE(broker.emptyPluginMap());
}
TEST(PluginMapper, getPluginTest)
{
- int ret;
- TestPluginBroker broker;
+ int ret;
+ TestPluginBroker broker;
- EXPECT_NO_THROW(broker.piMapper.loadPlugins());
- EXPECT_FALSE(broker.emptyPluginMap());
+ EXPECT_NO_THROW(broker.piMapper.loadPlugins());
+ EXPECT_FALSE(broker.emptyPluginMap());
- Plugin *plugin = broker.piMapper.getPlugin("test");
- ASSERT_TRUE(plugin);
+ Plugin *plugin = broker.piMapper.getPlugin("test");
+ ASSERT_TRUE(plugin);
- broker.checkTestPlugin(plugin);
+ broker.checkTestPlugin(plugin);
- ret = broker.piMapper.unloadPlugins();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_TRUE(broker.emptyPluginMap());
+ ret = broker.piMapper.unloadPlugins();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_TRUE(broker.emptyPluginMap());
}
TEST(PluginMapper, defaultDeleteAction)
{
- TmpPlugin plugin;
- EXPECT_EQ(plugin.getCount(), 0);
+ TmpPlugin plugin;
+ EXPECT_EQ(plugin.getCount(), 0);
- PluginAction *action = plugin.newAction("test");
- EXPECT_EQ(plugin.getCount(), 1);
+ PluginAction *action = plugin.newAction("test");
+ EXPECT_EQ(plugin.getCount(), 1);
- plugin.deleteAction(action);
- EXPECT_EQ(plugin.getCount(), 0);
+ plugin.deleteAction(action);
+ EXPECT_EQ(plugin.getCount(), 0);
}
TEST(PluginMapper, ActionDefaultMethod)
{
- TmpPlugin plugin;
- PluginAction *action = plugin.newAction("test");
-
- EXPECT_EQ(action->IsCurrentValue(1), false);
- EXPECT_EQ(action->IsCurrentValue(1.1), false);
- EXPECT_EQ(action->IsCurrentValue(true), false);
- EXPECT_EQ(action->IsCurrentValue(string("test")), false);
-
- EXPECT_EQ(action->set(1), MODES_ERROR_NOT_SUPPORTED);
- EXPECT_EQ(action->set(1.1), MODES_ERROR_NOT_SUPPORTED);
- EXPECT_EQ(action->set(true), MODES_ERROR_NOT_SUPPORTED);
- EXPECT_EQ(action->set(string("test")), MODES_ERROR_NOT_SUPPORTED);
-
- EXPECT_EQ(action->getUndoInfo().empty(), true);
- EXPECT_EQ(action->setUndoInfo("test"), MODES_ERROR_NOT_SUPPORTED);
- EXPECT_EQ(action->setChangedCallback(nullptr, nullptr), MODES_ERROR_NOT_SUPPORTED);
-
- action->unSetChangedCallback(nullptr);
- action->undo();
- plugin.deleteAction(action);
- EXPECT_EQ(plugin.getCount(), 0);
+ TmpPlugin plugin;
+ PluginAction *action = plugin.newAction("test");
+
+ EXPECT_EQ(action->IsCurrentValue(1), false);
+ EXPECT_EQ(action->IsCurrentValue(1.1), false);
+ EXPECT_EQ(action->IsCurrentValue(true), false);
+ EXPECT_EQ(action->IsCurrentValue(string("test")), false);
+
+ EXPECT_EQ(action->set(1), MODES_ERROR_NOT_SUPPORTED);
+ EXPECT_EQ(action->set(1.1), MODES_ERROR_NOT_SUPPORTED);
+ EXPECT_EQ(action->set(true), MODES_ERROR_NOT_SUPPORTED);
+ EXPECT_EQ(action->set(string("test")), MODES_ERROR_NOT_SUPPORTED);
+
+ EXPECT_EQ(action->getUndoInfo().empty(), true);
+ EXPECT_EQ(action->setUndoInfo("test"), MODES_ERROR_NOT_SUPPORTED);
+ EXPECT_EQ(action->setChangedCallback(nullptr, nullptr), MODES_ERROR_NOT_SUPPORTED);
+
+ action->unSetChangedCallback(nullptr);
+ action->undo();
+ plugin.deleteAction(action);
+ EXPECT_EQ(plugin.getCount(), 0);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <functional>
#include <gtest/gtest.h>
+
+#include <functional>
+
#include "ModesPlugin.h"
#include "supervisor/ModesEx.h"
#include "supervisor/TAction.h"
using namespace std;
MODES_NAMESPACE_USE;
-extern "C" Plugin* objectCreate(void);
+extern "C" Plugin *objectCreate(void);
extern "C" void objectDelete(Plugin *plugin);
MODES_NAMESPACE_BEGIN
class PolicyTest : public ::testing::Test {
-protected:
- void SetUp() override
- {
- plugin = objectCreate();
- }
-
- void TearDown() override
- {
- objectDelete(plugin);
- }
-
- bool isSubscribed(Action *action)
- {
- return !(action->isIgnored());
- }
-
- Plugin *plugin;
+ protected:
+ void SetUp() override { plugin = objectCreate(); }
+
+ void TearDown() override { objectDelete(plugin); }
+
+ bool isSubscribed(Action *action) { return !(action->isIgnored()); }
+
+ Plugin *plugin;
};
MODES_NAMESPACE_END
TEST_F(PolicyTest, OnlyOneSubscribe)
{
- int ret;
- string ruleName = "test.printInt";
-
- int pos = ruleName.find_first_of(".");
- std::string actionKey = ruleName.substr(pos + 1);
- std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
- std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-
- Action *action1 = nullptr;
- ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
-
- ret = action1->setValue("4");
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = action1->apply();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(isSubscribed(action1), true);
-
- std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
- std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
- Action *action2 = nullptr;
- ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
-
- ret = action2->setValue("2");
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = action2->apply();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(isSubscribed(action2), true);
- EXPECT_EQ(isSubscribed(action1), false);
+ int ret;
+ string ruleName = "test.printInt";
+
+ int pos = ruleName.find_first_of(".");
+ std::string actionKey = ruleName.substr(pos + 1);
+ std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
+ std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+
+ Action *action1 = nullptr;
+ ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
+
+ ret = action1->setValue("4");
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = action1->apply();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(isSubscribed(action1), true);
+
+ std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
+ std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+ Action *action2 = nullptr;
+ ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
+
+ ret = action2->setValue("2");
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = action2->apply();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(isSubscribed(action2), true);
+ EXPECT_EQ(isSubscribed(action1), false);
}
TEST_F(PolicyTest, ignoreSameValue)
{
- int ret;
- string ruleName = "test.printInt";
-
- int pos = ruleName.find_first_of(".");
- std::string actionKey = ruleName.substr(pos + 1);
- std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
- std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-
- Action *action1 = nullptr;
- ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
-
- ret = action1->setValue("4");
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = action1->apply();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(isSubscribed(action1), true);
-
- std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
- std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
- Action *action2 = nullptr;
- ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
-
- ret = action2->setValue("4");
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = action2->apply();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(isSubscribed(action2), false);
- EXPECT_EQ(isSubscribed(action1), true);
+ int ret;
+ string ruleName = "test.printInt";
+
+ int pos = ruleName.find_first_of(".");
+ std::string actionKey = ruleName.substr(pos + 1);
+ std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
+ std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+
+ Action *action1 = nullptr;
+ ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
+
+ ret = action1->setValue("4");
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = action1->apply();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(isSubscribed(action1), true);
+
+ std::shared_ptr<PluginAction> piAction2(plugin->newAction(actionKey),
+ std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+ Action *action2 = nullptr;
+ ASSERT_NO_THROW(action2 = new TAction<int>(ruleName, piAction2));
+
+ ret = action2->setValue("4");
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = action2->apply();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(isSubscribed(action2), false);
+ EXPECT_EQ(isSubscribed(action1), true);
}
TEST_F(PolicyTest, oneShotNoSubscribe)
{
- int ret;
- string ruleName = "test.printInt";
-
- int pos = ruleName.find_first_of(".");
- std::string actionKey = ruleName.substr(pos + 1);
- std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
- std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
-
- Action *action1 = nullptr;
- ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
-
- ret = action1->setValue("4");
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = action1->applyOneShot();
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- EXPECT_EQ(isSubscribed(action1), false);
+ int ret;
+ string ruleName = "test.printInt";
+
+ int pos = ruleName.find_first_of(".");
+ std::string actionKey = ruleName.substr(pos + 1);
+ std::shared_ptr<PluginAction> piAction1(plugin->newAction(actionKey),
+ std::bind(&Plugin::deleteAction, plugin, std::placeholders::_1));
+
+ Action *action1 = nullptr;
+ ASSERT_NO_THROW(action1 = new TAction<int>(ruleName, piAction1));
+
+ ret = action1->setValue("4");
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ ret = action1->applyOneShot();
+ EXPECT_EQ(ret, MODES_ERROR_NONE);
+ EXPECT_EQ(isSubscribed(action1), false);
}
* limitations under the License.
*/
#include <gtest/gtest.h>
+
#include "supervisor/ModesEx.h"
#include "supervisor/RuleManager.h"
MODES_NAMESPACE_BEGIN
class RuleManagerTest {
-public:
- RuleManagerTest();
+ public:
+ RuleManagerTest();
- RuleManager rMgr;
- void parseActionRule(const string &xmlFile)
- {
- rMgr.parseActionRule(xmlFile);
- }
- bool emptyRuleMap()
- {
- return rMgr.ruleMap.empty();
- }
+ RuleManager rMgr;
+ void parseActionRule(const string &xmlFile) { rMgr.parseActionRule(xmlFile); }
+ bool emptyRuleMap() { return rMgr.ruleMap.empty(); }
};
MODES_NAMESPACE_END
MODES_NAMESPACE_USE;
RuleManagerTest::RuleManagerTest()
- : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
+ : rMgr(".", "./" MODES_RULE_DEFAULT_XSD_FILE, "../../.." MODES_PLUGIN_DEFAULT_DIR)
{
- rMgr.piMapper.loadPlugins();
+ rMgr.piMapper.loadPlugins();
}
TEST(RuleManagerTest, makeRuleMapP)
{
- RuleManagerTest testBroker;
- EXPECT_NO_THROW(testBroker.rMgr.start());
+ RuleManagerTest testBroker;
+ EXPECT_NO_THROW(testBroker.rMgr.start());
}
TEST(RuleManagerTest, parseActionRuleP)
{
- RuleManagerTest testBroker;
- EXPECT_NO_THROW(testBroker.parseActionRule("./tizen_test_rule.xml"));
+ RuleManagerTest testBroker;
+ EXPECT_NO_THROW(testBroker.parseActionRule("./tizen_test_rule.xml"));
}
TEST(RuleManagerTest, DuplicatedRule)
{
- RuleManagerTest testBroker;
- EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
+ RuleManagerTest testBroker;
+ EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
}
TEST(RuleManagerTest, InvalidValue)
{
- RuleManagerTest testBroker;
- EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
+ RuleManagerTest testBroker;
+ EXPECT_THROW(testBroker.parseActionRule("./tizen_uniqueRuleErr_rule.xml"), ModesEx);
}
// If there are any errors in a file, the file will be ignored.
TEST(RuleManagerTest, CheckAtomicity)
{
- RuleManagerTest testBroker;
- EXPECT_THROW(testBroker.parseActionRule("./tizen_aliasValueErr.xml"), ModesEx);
- EXPECT_TRUE(testBroker.emptyRuleMap());
+ RuleManagerTest testBroker;
+ EXPECT_THROW(testBroker.parseActionRule("./tizen_aliasValueErr.xml"), ModesEx);
+ EXPECT_TRUE(testBroker.emptyRuleMap());
}
TEST(RuleManagerTest, UnknownPlugin1)
{
- RuleManagerTest testBroker;
- EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr1_rule.xml"), ModesEx);
+ RuleManagerTest testBroker;
+ EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr1_rule.xml"), ModesEx);
}
TEST(RuleManagerTest, UnknownPlugin2)
{
- RuleManagerTest testBroker;
- EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr2_rule.xml"), ModesEx);
+ RuleManagerTest testBroker;
+ EXPECT_THROW(testBroker.parseActionRule("./tizen_pluginErr2_rule.xml"), ModesEx);
}