Change EventBase::SetVal to virtual
[platform/core/appfw/app-core.git] / tizen-cpp / app-core-cpp / app_core_base.hh
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef TIZEN_CPP_APP_CORE_CPP_APP_CORE_BASE_HH_
18 #define TIZEN_CPP_APP_CORE_CPP_APP_CORE_BASE_HH_
19
20 #include <memory>
21 #include <string>
22
23 #include <interface_app_core.hh>
24 #include <interface_main_loop.hh>
25
26 #undef EXPORT_API
27 #define EXPORT_API __attribute__((visibility("default")))
28
29 namespace tizen_cpp {
30
31 class EXPORT_API AppCoreBase : public IAppCore, public IMainLoop {
32  public:
33   enum RotationState {
34     ROTATION_UNKNOWN,
35     ROTATION_PORTRAIT_NORMAL,
36     ROTATION_PORTRAIT_REVERSE,
37     ROTATION_LANDSCAPE_NORMAL,
38     ROTATION_LANDSCAPE_REVERSE,
39   };
40
41   enum SuspendedState {
42     SUSPENDED_STATE_WILL_ENTER_SUSPEND = 0,
43     SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND
44   };
45
46   enum DisplayState {
47     DISPLAY_STATE_UNKNOWN,
48     DISPLAY_STATE_ON,
49     DISPLAY_STATE_OFF
50   };
51
52   enum Feature {
53     FEATURE_BACKGROUND_MANAGEMENT = 0x1,
54     FEATURE_CHARGER_STATUS = 0x2
55   };
56
57   class EventBase : public IEvent {
58    public:
59     explicit EventBase(Type type);
60     virtual ~EventBase();
61     Type GetType() const override;
62     std::string GetVal(std::string cur) const;
63     int GetVal(int cur) const;
64     virtual void SetVal(std::string val);
65     virtual void SetVal(int val);
66
67    private:
68     class Impl;
69     std::unique_ptr<Impl> impl_;
70   };
71
72   AppCoreBase();
73   virtual ~AppCoreBase();
74   static AppCoreBase* GetContext();
75
76   virtual void Run(int argc, char** argv);
77   virtual void Exit();
78   virtual void Dispose();
79   void Init(int argc, char** argv);
80   void Fini();
81   int OnReceive(aul_type type, tizen_base::Bundle b) override;
82   int OnCreate() override;
83   int OnControl(tizen_base::Bundle b) override;
84   int OnTerminate() override;
85   int OnSetI18n() override;
86   int OnSetEvent(IEvent::Type event) override;
87   int OnUnsetEvent(IEvent::Type event) override;
88   int OnTrimMemory() override;
89   void AddEvent(std::shared_ptr<EventBase> event);
90   bool RemoveEvent(std::shared_ptr<EventBase> event);
91   void RaiseEvent(int event, IEvent::Type type);
92   void RaiseEvent(const std::string& event, IEvent::Type type);
93   void FlushMemory();
94   bool IsBgAllowed();
95   bool IsSuspended();
96   void ToggleSuspendedState();
97   int SetI18n(std::string domain_name, std::string dir_name);
98   void AddSuspendTimer();
99   void RemoveSuspendTimer();
100   void SetFeature(int feature);
101   int GetFeature() const;
102   static RotationState GetRotationState();
103   static void SetDisplayState(DisplayState state);
104   static DisplayState GetDisplayState();
105   static int EnableWatchdog();
106   static int DisableWatchdog();
107   static int KickWatchdog();
108
109  protected:
110   void SetCoreDelegator(IAppCore* delegator);
111   void SetLoopDelegator(IMainLoop* delegator);
112   static AppCoreBase* context_;
113
114  private:
115   class Impl;
116   std::unique_ptr<Impl> impl_;
117 };
118
119 }  // namespace tizen_cpp
120
121 #endif  // TIZEN_CPP_APP_CORE_CPP_APP_CORE_BASE_HH_