olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
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
33namespace olp {
34namespace context {
41struct ContextData;
42
51class CORE_API Context {
52 public:
60 using InitializedCallback = std::function<void()>;
61
69 using DeinitializedCallback = std::function<void()>;
70
79 DeinitializedCallback deinitCalback);
80
89 class CORE_API Scope {
90 public:
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()
Invokes deinitialized callbacks of the Context class.
Scope(const Scope &)=delete
The deleted copy constructor.
Scope & operator=(const Scope &)=delete
The deleted assignment operator.
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