blob: cf2bc457842f594f0fe1f94d54206b7acd532d01 [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;
Brian Duddie154b0882017-06-01 18:51:22 -070069 sp<IContexthubCallback> callback;
70 };
71
72 class DeathRecipient : public hidl_death_recipient {
73 public:
74 DeathRecipient(const sp<Contexthub> contexthub);
75
76 void serviceDied(
77 uint64_t cookie,
78 const wp<::android::hidl::base::V1_0::IBase>& who) override;
79
80 private:
81 sp<Contexthub> mContexthub;
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080082 };
83
84 status_t mInitCheck;
85 const struct context_hub_module_t *mContextHubModule;
86 std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
87
Brian Duddie154b0882017-06-01 18:51:22 -070088 sp<DeathRecipient> mDeathRecipient;
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080089 bool mIsTransactionPending;
90 uint32_t mTransactionId;
91
92 bool isValidHubId(uint32_t hubId);
93
94 sp<IContexthubCallback> getCallBackForHubId(uint32_t hubId);
95
96 int handleOsMessage(sp<IContexthubCallback> cb,
97 uint32_t msgType,
98 const uint8_t *msg,
99 int msgLen);
100
Brian Duddie154b0882017-06-01 18:51:22 -0700101 // Handle the case where the callback registered for the given hub ID dies
102 void handleServiceDeath(uint32_t hubId);
103
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -0800104 static int contextHubCb(uint32_t hubId,
105 const struct hub_message_t *rxMsg,
106 void *cookie);
107
108 bool setOsAppAsDestination(hub_message_t *msg, int hubId);
109
110 DISALLOW_COPY_AND_ASSIGN(Contexthub);
111};
112
113extern "C" IContexthub *HIDL_FETCH_IContexthub(const char *name);
114
115} // namespace implementation
116} // namespace V1_0
117} // namespace contexthub
118} // namespace hardware
119} // namespace android
120
121#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_