olp-cpp-sdk  1.22.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Context.h
1 /*
2  * Copyright (C) 2019-2023 HERE Europe B.V.
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  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <functional>
23 #include <memory>
24 #include <mutex>
25 #include <string>
26 
27 #include <olp/core/CoreApi.h>
28 
29 #if defined(ANDROID) || defined(ANDROID_HOST)
30 #include <jni.h>
31 #endif
32 
33 namespace olp {
34 namespace context {
41 struct ContextData;
42 
51 class CORE_API Context {
52  public:
60  using InitializedCallback = std::function<void()>;
61 
69  using DeinitializedCallback = std::function<void()>;
70 
78  static void addInitializeCallbacks(InitializedCallback initCallback,
79  DeinitializedCallback deinitCalback);
80 
89  class CORE_API Scope {
90  public:
99  Scope();
100 
101 #if defined(ANDROID) || defined(ANDROID_HOST)
113  Scope(JavaVM* vm, jobject context);
114 #endif
115 
119  Scope(const Scope&) = delete;
123  Scope& operator=(const Scope&) = delete;
124 
131 
132  private:
133  std::shared_ptr<ContextData> m_cd;
134  };
135 
139  Context() = delete;
140 
141  friend class Context::Scope;
142 
143  private:
145  static void init();
146 
148  static void deinit();
149 
150 #if defined(ANDROID) || defined(ANDROID_HOST)
152  static void init(JavaVM* vm, jobject application);
153 #endif
154 
155  public:
156 #if defined(ANDROID) || defined(ANDROID_HOST)
164  static JavaVM* getJavaVM();
172  static jobject getAndroidContext();
173 #elif defined(__APPLE__)
179  static void EnterBackground();
180 
186  static void ExitBackground();
187 
201  static void StoreBackgroundSessionCompletionHandler(
202  const std::string& session_name,
203  std::function<void(void)> completion_handler);
204 
205 #endif // __APPLE__
206 };
207 
208 } // namespace context
209 } // namespace olp
Initializes the Context class in its constructor (if it is not already initialized) and deinitializes...
Definition: Context.h:89
Scope & operator=(const Scope &)=delete
The deleted assignment operator.
~Scope()
Invokes deinitialized callbacks of the Context class.
Scope(const Scope &)=delete
The deleted copy constructor.
Scope()
Creates the Scope instance.
Used only for the Android environment to correctly initialize the NetworkAndroid class.
Definition: Context.h:51
static void addInitializeCallbacks(InitializedCallback initCallback, DeinitializedCallback deinitCalback)
Registers functions that are called when the context is initialized and destroyed.
std::function< void()> InitializedCallback
Called when the Context object is initialized.
Definition: Context.h:60
std::function< void()> DeinitializedCallback
Called when the Context object is deinitialized.
Definition: Context.h:69
Context()=delete
The deleted default constructor.
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24