blob: db23ec2e63c3b6b76100d42a98205be84d865c3b [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
22#include <android/hardware/contexthub/1.0/IContexthub.h>
23#include <hardware/context_hub.h>
24
25namespace android {
26namespace hardware {
27namespace contexthub {
28namespace V1_0 {
29namespace implementation {
30
31struct Contexthub : public ::android::hardware::contexthub::V1_0::IContexthub {
32 Contexthub();
33
34 Return<void> getHubs(getHubs_cb _hidl_cb) override;
35
36 Return<Result> registerCallback(uint32_t hubId,
37 const sp<IContexthubCallback> &cb) override;
38
39 Return<Result> sendMessageToHub(uint32_t hubId,
40 const ContextHubMsg &msg) override;
41
42 Return<Result> loadNanoApp(uint32_t hubId,
Brian Duddiec6d2fd42017-01-12 14:47:58 -080043 const NanoAppBinary& appBinary,
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080044 uint32_t transactionId) override;
45
46 Return<Result> unloadNanoApp(uint32_t hubId,
47 uint64_t appId,
48 uint32_t transactionId) override;
49
50 Return<Result> enableNanoApp(uint32_t hubId,
51 uint64_t appId,
52 uint32_t transactionId) override;
53
54 Return<Result> disableNanoApp(uint32_t hubId,
55 uint64_t appId,
56 uint32_t transactionId) override;
57
58 Return<Result> queryApps(uint32_t hubId) override;
59
60 Return<Result> reboot(uint32_t hubId);
61
62 bool isInitialized();
63
64private:
65
66 struct CachedHubInformation{
67 struct hub_app_name_t osAppName;
Brian Duddie154b0882017-06-01 18:51:22 -070068 sp<IContexthubCallback> callback;
69 };
70
71 class DeathRecipient : public hidl_death_recipient {
72 public:
73 DeathRecipient(const sp<Contexthub> contexthub);
74
75 void serviceDied(
76 uint64_t cookie,
77 const wp<::android::hidl::base::V1_0::IBase>& who) override;
78
79 private:
80 sp<Contexthub> mContexthub;
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080081 };
82
83 status_t mInitCheck;
84 const struct context_hub_module_t *mContextHubModule;
85 std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
86
Brian Duddie154b0882017-06-01 18:51:22 -070087 sp<DeathRecipient> mDeathRecipient;
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -080088 bool mIsTransactionPending;
89 uint32_t mTransactionId;
90
91 bool isValidHubId(uint32_t hubId);
92
93 sp<IContexthubCallback> getCallBackForHubId(uint32_t hubId);
94
95 int handleOsMessage(sp<IContexthubCallback> cb,
96 uint32_t msgType,
97 const uint8_t *msg,
98 int msgLen);
99
Brian Duddie154b0882017-06-01 18:51:22 -0700100 // Handle the case where the callback registered for the given hub ID dies
101 void handleServiceDeath(uint32_t hubId);
102
Ashutosh Joshi1bec86a2016-11-15 13:48:58 -0800103 static int contextHubCb(uint32_t hubId,
104 const struct hub_message_t *rxMsg,
105 void *cookie);
106
107 bool setOsAppAsDestination(hub_message_t *msg, int hubId);
108
109 DISALLOW_COPY_AND_ASSIGN(Contexthub);
110};
111
112extern "C" IContexthub *HIDL_FETCH_IContexthub(const char *name);
113
114} // namespace implementation
115} // namespace V1_0
116} // namespace contexthub
117} // namespace hardware
118} // namespace android
119
120#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_