2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #import <Cocoa/Cocoa.h>
20 #include "extern-definitions.h"
23 #include <dali/internal/adaptor/common/framework.h>
26 #include <dali/integration-api/debug.h>
29 #include <dali/internal/system/common/callback-manager.h>
43 /// Application Status Enum
54 } // Unnamed namespace
57 * Impl to hide WindowsSystem data members
59 struct Framework::Impl
64 : mAbortCallBack( nullptr ),
65 mLanguage( "NOT_SUPPORTED" ),
66 mRegion( "NOT_SUPPORTED" )
72 delete mAbortCallBack;
75 std::string GetLanguage() const
80 std::string GetRegion() const
85 void SetAbortCallback( CallbackBase *base )
87 mAbortCallBack = base;
90 bool ExecuteCallback()
92 if( nullptr != mAbortCallBack )
94 CallbackBase::Execute( *mAbortCallBack );
103 Impl( const Impl& impl ) = delete;
106 Impl& operator=( const Impl& impl ) = delete;
110 CallbackBase* mAbortCallBack;
111 std::string mLanguage;
115 Framework::Framework(Framework::Observer& observer, Framework::TaskObserver& taskObserver, int* argc, char*** argv, Type type, bool useUiThread)
116 : mObserver(observer),
117 mTaskObserver(taskObserver),
125 mAbortHandler( MakeCallback( this, &Framework::AbortCallback ) ),
129 mImpl = new Impl(this);
131 // ensures the NSApp global object is initialized
132 [NSApplication sharedApplication];
134 // this is needed for applications without a bundle
135 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
137 // make sure we can become the key window
138 [NSApp activateIgnoringOtherApps:YES];
141 Framework::~Framework()
151 void Framework::Run()
154 AppStatusHandler(APP_CREATE, nullptr);
159 void Framework::Quit()
161 AppStatusHandler(APP_TERMINATE, nullptr);
164 bool Framework::IsMainLoopRunning()
169 void Framework::AddAbortCallback( CallbackBase* callback )
171 mImpl->SetAbortCallback( callback );
174 std::string Framework::GetBundleName() const
179 void Framework::SetBundleName(const std::string& name)
184 std::string Framework::GetBundleId() const
189 std::string Framework::GetResourcePath()
191 // "DALI_APPLICATION_PACKAGE" is used by macOS specifically to get the already configured Application package path.
192 const char* macEnvironmentVariable = "DALI_APPLICATION_PACKAGE";
193 char* value = getenv( macEnvironmentVariable );
195 std::string resourcePath;
198 resourcePath = value;
201 if( resourcePath.back() != '/' )
209 std::string Framework::GetDataPath()
211 return app_get_data_path();
214 void Framework::SetBundleId(const std::string& id)
219 void Framework::AbortCallback( )
221 // if an abort call back has been installed run it.
222 if( false == mImpl->ExecuteCallback() )
228 bool Framework::AppStatusHandler(int type, void *)
244 mObserver.OnResume();
248 mObserver.OnTerminate();
255 case APP_LANGUAGE_CHANGE:
256 mObserver.OnLanguageChanged();
266 void Framework::InitThreads()
270 std::string Framework::GetLanguage() const
272 return mImpl->GetLanguage();
275 std::string Framework::GetRegion() const
277 return mImpl->GetRegion();
280 } // namespace Adaptor
282 } // namespace Internal