#include "mdsc.h"
#include "mdsc_dbus.h"
#include "common/dbus.h"
+#include "common/dbus_def.h"
struct mds_action_handle {
char *id;
char *action;
char *value;
- int restriction;
};
struct mds_handle {
char *name;
- char *type;
+ modes_type_mode_e type;
GList *action_list;
};
{
RETV_IF(NULL == mode, NULL);
- GVariantBuilder *action_builder = g_variant_builder_new(G_VARIANT_TYPE("a(sssi)"));
+ 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, "(sssi)", action_data->id,
- action_data->action, action_data->value, action_data->restriction);
+ g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG, action_data->id,
+ action_data->action, action_data->value);
it = g_list_next(it);
}
- GVariant *action = g_variant_new("a(sssi)", action_builder);
- GVariant *mode_data = g_variant_new("(ssv)", mode->name, mode->type, action);
+ GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
+ GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->name, mode->type, action);
g_variant_builder_unref(action_builder);
return mode_data;
}
-API modes_h modes_create_mode(const char *name, const char *type)
+API modes_h modes_create_mode(const char *name, modes_type_mode_e type)
{
struct mds_handle *mode;
RETV_IF(NULL == name, NULL);
- RETV_IF(NULL == type, NULL);
mode = malloc(sizeof(struct mds_handle));
RETV_IF(NULL == mode, NULL);
mode->name = strdup(name);
- mode->type = strdup(type);
+ mode->type = type;
mode->action_list = NULL;
return mode;
action->action = strdup(name);
action->value = strdup(value);
action->id = NULL;
- action->restriction = MODES_RESTRICTION_NONE;
return action;
}
RET_IF(NULL == mode);
free(mode->name);
- free(mode->type);
g_list_free_full(mode->action_list, _mdsc_free_action);
<arg type="i" name="ret" direction="out"/>
</method>
<method name="registerMode">
- <arg type="(ssv)" name="modeData" direction="in"/>
+ <arg type="(siv)" name="modeData" direction="in"/>
<arg type="i" name="ret" direction="out"/>
</method>
</interface>
#endif
#define MODES_DBUS_OBJPATH "/org/tizen/modes/dbus"
+
+#define MODES_DBUS_MODE_SIG "(siv)"
+#define MODES_DBUS_ACTION_SIG "(sss)"
+#define MODES_DBUS_ACTION_LIST_SIG "a" MODES_DBUS_ACTION_SIG
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="normal"/>
- <xs:enumeration value="exclusive"/>
<xs:enumeration value="oneshot"/>
+ <xs:enumeration value="exclusive"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
* otherwise NULL value
* @retval NULL Failed to create the mode handler
*/
-modes_h modes_create_mode(const char *name, const char *type);
+modes_h modes_create_mode(const char *name, modes_type_mode_e type);
/**
* @brief Create Action.
/**
- * @brief Enumeration for type of observation.
+ * @brief Enumeration for mode type.
* @since_tizen 5.5
*/
typedef enum {
- MODES_TEMP_0 = 0, /**< Indicates no option */
- MODES_TEMP_1 = 1, /**< Indicates 1*/
-} modes_temp_e;
-
-
-/**
- * @brief Enumeration for policy.
- * @since_tizen 5.5
- */
-typedef enum {
- MODES_POLICY_NO = 0, /**< Indicates resource uninitialized */
- MODES_POLICY_1 = (1 << 0), /**< Indicates resource that is allowed to be discovered */
- MODES_POLICY_2 = (1 << 1), /**< Indicates resource that is allowed to be observed */
- MODES_POLICY_3 = (1 << 2), /**< Indicates resource initialized and activated */
- MODES_POLICY_4 = (1 << 3), /**< Indicates resource which takes some delay to respond */
-} modes_policy_e;
+ 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) */
+ // Exclusive is not valide type on making by user.
+ //MODES_TYPE_MODE_EXCLUSIVE = (1 << 1), /**< Indicates exclusive mode that is only allowed to undo */
+} modes_type_mode_e;
/**
* limitations under the License.
*/
#include "Mode.h"
+#include "modes_constants.h"
#include "ModesEx.h"
MODES_NAMESPACE_USE;
name = data;
}
-std::string Mode::getName() const
+const std::string Mode::getName() const
{
return name;
}
type = MODE_ONESHOT;
}
-Mode::ModeType Mode::getModeType() const
+void Mode::setModeType(int val)
+{
+ switch (val) {
+ case MODES_TYPE_MODE_NORMAL:
+ type = 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:
+ type = MODE_ONESHOT;
+ }
+}
+
+const Mode::ModeType Mode::getModeType() const
{
return type;
}
customized = data;
}
-bool Mode::getCustomized() const
+const bool Mode::getCustomized() const
{
return customized;
}
public:
typedef enum {
MODE_NORMAL,
- MODE_EXCLUSIVE,
- MODE_ONESHOT
+ MODE_ONESHOT,
+ MODE_EXCLUSIVE
}ModeType;
Mode();
~Mode();
void setName(const std::string &data);
- std::string getName() const;
+ const std::string getName() const;
void setModeType(const std::string &data);
- ModeType getModeType() const;
+ void setModeType(int val);
+ const ModeType getModeType() const;
void setCustomized(bool data);
- bool getCustomized() const;
+ const bool getCustomized() const;
void addAction(Action *action);
std::list<std::shared_ptr<Action>> getActionList() const;
#include "RequestHandler.h"
#include "mdss.h"
#include "ModesEx.h"
+#include "common/dbus_def.h"
MODES_NAMESPACE_USE;
Mode RequestHandler::getModefromData(GVariant *inData)
{
GVariant *actionList;
- gchar *name, *type;
- gchar *id, *act_name, *value;
- gint32 restriction;
+ gchar *modeName;
+ gchar *id, *actName, *value;
+ gint32 type;
GVariantIter *iter;
Mode mode;
- g_variant_get(inData, "(ssv)", &name, &type, &actionList);
- DBG("mode_name : %s // type : %s", name, type);
+ g_variant_get(inData, MODES_DBUS_MODE_SIG, &modeName, &type, &actionList);
+ DBG("mode_name : %s // type : %d", modeName, type);
- mode.setName(name);
+ mode.setName(modeName);
mode.setModeType(type);
mode.setCustomized(true);
- g_free(name);
- g_free(type);
+ g_free(modeName);
- g_variant_get(actionList, "a(sssi)", &iter);
+ g_variant_get(actionList, MODES_DBUS_ACTION_LIST_SIG, &iter);
try {
- while (g_variant_iter_loop(iter, "(sssi)", &id, &act_name, &value, &restriction)) {
- DBG("id : %s action_name : %s value : %s restiction : %d",
- id[0] != '\0' ? id : "NULL", act_name, value, restriction);
+ 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, act_name, value, restriction);
+ Action *action = createAction(id, actName, value);
mode.addAction(action);
}
} catch (ModesEx &e) {
- ERR("createAction(%s, %s, %s, %d) Fail(%s)", id, act_name, value, restriction, e.what());
+ ERR("createAction(%s, %s, %s) Fail(%s)", id, actName, value, e.what());
g_variant_iter_free(iter);
g_variant_unref(actionList);
throw ModesEx(ModesEx::INVALID_ARG, "Action is null!");
return mode;
}
-Action* RequestHandler::createAction(char *id, char *ruleName, char *contents, int restriction)
+Action* RequestHandler::createAction(char *id, char *ruleName, char *val)
{
std::string pluginName;
throw ModesEx(ModesEx::PARSER_ERROR, "Action is null!");
}
- if (restriction)
- action->setRestrict(Action::REQ_LOCK);
- else
- action->setRestrict(Action::REQ_NONE);
+ if (id)
+ action->setID(id);
+ action->setRestrict(Action::REQ_NONE); //It is not allowed to set Restrict of Action by API.
+ action->setValue(val);
- action->setID(id);
- action->setValue(contents);
action->printInfo();
return action;
private:
static Mode getModefromData(GVariant *inData);
- static Action* createAction(char *id, char *act_name, char *contents, int restriction);
+ static Action* createAction(char *id, char *act_name, char *contents);
static ModeManager *modeMgr;
static RuleManager *ruleMgr;
static gboolean request_register_mode_idler(gpointer data)
{
- modes_h mode_handle = modes_create_mode("created", "normal");
+ modes_h mode_handle = modes_create_mode("created", MODES_TYPE_MODE_NORMAL);
action_h action_handle[2];
action_handle[0] = modes_create_action("wifi.power", "on");
modes_action_set_id(action_handle[0], "WiFiOn");