AddOn manager
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor-internal / addons / test-sample-addon.cpp
1 /*
2  * Copyright (c) 2020 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
18 #include <cstring>
19 #include <dali/devel-api/addons/addon-base.h>
20 #include <dali-test-suite-utils.h>
21
22 namespace
23 {
24 bool gIsPaused = false;
25 }
26
27 int StringLen( const char* str )
28 {
29   return strlen( str );
30 }
31
32 int DoSum( int a, int b )
33 {
34   return a+b;
35 }
36
37 bool GetLifecycleStatus()
38 {
39   return gIsPaused;
40 }
41
42 struct AddOnDataInstance
43 {
44   int GetValue()
45   {
46     return 42;
47   }
48
49   static int GetValueWithInstance( AddOnDataInstance* instance )
50   {
51     return instance->GetValue();
52   }
53 };
54
55 AddOnDataInstance* CreateInstance()
56 {
57   return new AddOnDataInstance();
58 }
59
60 class TestDummyAddOn : public Dali::AddOns::AddOnBase
61 {
62 public:
63
64   void GetAddOnInfo( Dali::AddOnInfo& info ) override
65   {
66     info.type = Dali::AddOnType::GENERIC;
67     info.name = "SampleAddOn";
68     info.version = Dali::DALI_ADDON_VERSION( 1, 0, 0 );
69     info.next = nullptr;
70     tet_printf( "SampleAddOn: GetAddOnInfo() : name = %s\n", info.name.c_str());
71   }
72
73   /**
74    * Dispatch table for global functions
75    * @return
76    */
77   Dali::AddOns::DispatchTable* GetGlobalDispatchTable() override
78   {
79     static Dali::AddOns::DispatchTable dispatchTable{};
80     if( dispatchTable.Empty() )
81     {
82       dispatchTable["DoSum"]                     = DoSum;
83       dispatchTable["StringLen"]                 = StringLen;
84       dispatchTable["GetLifecycleStatus"]        = GetLifecycleStatus;
85       dispatchTable["CreateInstance"]            = CreateInstance;
86
87     }
88     return &dispatchTable;
89   }
90
91   /**
92    * Lifecycle
93    */
94   void OnStart() override
95   {
96     gIsPaused = false;
97   }
98
99   void OnStop() override
100   {
101     gIsPaused = true;
102   }
103
104   void OnPause() override
105   {
106     gIsPaused = true;
107   }
108
109   void OnResume() override
110   {
111     gIsPaused = false;
112   }
113
114   /**
115    * Dispatch table for instance functions
116    * @return
117    */
118   Dali::AddOns::DispatchTable* GetInstanceDispatchTable() override
119   {
120     static Dali::AddOns::DispatchTable dispatchTable{};
121     if( dispatchTable.Empty() )
122     {
123       dispatchTable["InstanceCall"] = AddOnDataInstance::GetValueWithInstance;
124     }
125     return &dispatchTable;
126   }
127 };
128
129 REGISTER_ADDON_CLASS( TestDummyAddOn );