blob: e58793007f35fdd94e4ccc6e717a534c20cf6674 [file] [log] [blame]
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
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 ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_
18#define ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_
19
20#include <unordered_map>
21
Steven Moreland9c7f45c2017-05-01 13:07:56 -070022#include <android-base/macros.h>
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080023#include <android/hardware/contexthub/1.0/IContexthub.h>
24#include <hardware/context_hub.h>
25
26namespace android {
27namespace hardware {
28namespace contexthub {
29namespace V1_0 {
30namespace implementation {
31
32struct Contexthub : public ::android::hardware::contexthub::V1_0::IContexthub {
33 Contexthub();
34
35 Return<void> getHubs(getHubs_cb _hidl_cb) override;
36
37 Return<Result> registerCallback(uint32_t hubId,
38 const sp<IContexthubCallback> &cb) override;
39
40 Return<Result> sendMessageToHub(uint32_t hubId,
41 const ContextHubMsg &msg) override;
42
43 Return<Result> loadNanoApp(uint32_t hubId,
Brian Duddiec6d2fd42017-01-12 14:47:58 -080044 const NanoAppBinary& appBinary,
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080045 uint32_t transactionId) override;
46
47 Return<Result> unloadNanoApp(uint32_t hubId,
48 uint64_t appId,
49 uint32_t transactionId) override;
50
51 Return<Result> enableNanoApp(uint32_t hubId,
52 uint64_t appId,
53 uint32_t transactionId) override;
54
55 Return<Result> disableNanoApp(uint32_t hubId,
56 uint64_t appId,
57 uint32_t transactionId) override;
58
59 Return<Result> queryApps(uint32_t hubId) override;
60
61 Return<Result> reboot(uint32_t hubId);
62
63 bool isInitialized();
64
65private:
66
67 struct CachedHubInformation{
68 struct hub_app_name_t osAppName;
69 sp<IContexthubCallback> callBack;
70 };
71
72 status_t mInitCheck;
73 const struct context_hub_module_t *mContextHubModule;
74 std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
75
76 sp<IContexthubCallback> mCb;
77 bool mIsTransactionPending;
78 uint32_t mTransactionId;
79
80 bool isValidHubId(uint32_t hubId);
81
82 sp<IContexthubCallback> getCallBackForHubId(uint32_t hubId);
83
84 int handleOsMessage(sp<IContexthubCallback> cb,
85 uint32_t msgType,
86 const uint8_t *msg,
87 int msgLen);
88
89 static int contextHubCb(uint32_t hubId,
90 const struct hub_message_t *rxMsg,
91 void *cookie);
92
93 bool setOsAppAsDestination(hub_message_t *msg, int hubId);
94
95 DISALLOW_COPY_AND_ASSIGN(Contexthub);
96};
97
98extern "C" IContexthub *HIDL_FETCH_IContexthub(const char *name);
99
100} // namespace implementation
101} // namespace V1_0
102} // namespace contexthub
103} // namespace hardware
104} // namespace android
105
106#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_