Apply -fvisibility to decrease binary size
[platform/core/uifw/ise-engine-sunpinyin.git] / src / ime-core / imi_option_event.h
1 // -*- mode: c++ -*-
2 #ifndef _IMI_SESSION_H
3 #define _IMI_SESSION_H
4
5 #include <list>
6 #include <string>
7 #include <vector>
8
9 #include "utils.h"
10
11 class COptionEventBus;
12
13 struct COptionEvent {
14     template<typename ValueType>COptionEvent(const std::string& k,
15                                              const ValueType& v)
16         : name(k), value(v)
17     {}
18
19     int get_int() const;
20     bool get_bool() const;
21     std::string get_string() const;
22     std::vector<std::string> get_string_list() const;
23     std::vector<string_pair> get_string_pair_list() const;
24
25     /* TODO:
26      * string_pair get_string_pair() const;
27      * std::vector<bool> get_bool_list() const;
28      * std::vector<int> get_int_list() const;
29      */
30
31     int type;
32     std::string name;
33
34     struct variant_ {
35         variant_(int);
36         variant_(const std::string&);
37         variant_(bool);
38         variant_(const std::vector<std::string>&);
39         variant_(const std::vector<string_pair>&);
40         struct val_ {
41             int d_int;
42             std::string d_string;
43             bool d_bool;
44             std::vector<std::string> d_strings;
45             std::vector<string_pair> d_string_pair_list;
46         } data;
47         enum {
48             VAL_INTEGER,
49             VAL_INTEGER_LIST,
50             VAL_STRING,
51             VAL_STRING_LIST,
52             VAL_STRING_PAIR,
53             VAL_STRING_PAIR_LIST,
54             VAL_BOOL,
55             VAL_BOOL_LIST,
56         } type;
57     } value;
58 };
59
60 class EXPORTED IConfigurable
61 {
62 public:
63     IConfigurable();
64     ~IConfigurable();
65     /**
66      * onConfigChanged will be called whenever an option is changed
67      * @param event presents the changed option
68      * @return true if the event is consumed, and not intented to be
69      *         sent to another event listener, false otherwise.
70      */
71     virtual bool onConfigChanged(const COptionEvent&) { return false; }
72 };
73
74 class COptionEventBus
75 {
76 public:
77     /**
78      * listener will receive a message whenever an option is changed
79      * @param listener who is interested in a change of options
80      */
81     void registerAsListener(IConfigurable* listener);
82
83     /**
84      * remove listener from the subscriber list
85      * @param listener who is no more interested in a change of options
86      */
87     void unregisterAsListener(IConfigurable* listener);
88
89     /**
90      * publish an event to all listeners of this event bus
91      * @param event the event which presents an option change
92      */
93     void publishEvent(const COptionEvent& event);
94     template<class> friend class SingletonHolder;
95
96 private:
97     COptionEventBus() {}
98
99     typedef std::list<IConfigurable*> Subscribers;
100     Subscribers m_listeners;
101 };
102
103 typedef SingletonHolder<COptionEventBus> AOptionEventBus;
104
105 #endif // _IMI_SESSION_H