1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_
#define ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_
#include <unordered_map>
#include <android-base/macros.h>
#include <android/hardware/contexthub/1.0/IContexthub.h>
#include <hardware/context_hub.h>
namespace android {
namespace hardware {
namespace contexthub {
namespace V1_0 {
namespace implementation {
struct Contexthub : public ::android::hardware::contexthub::V1_0::IContexthub {
Contexthub();
Return<void> getHubs(getHubs_cb _hidl_cb) override;
Return<Result> registerCallback(uint32_t hubId,
const sp<IContexthubCallback> &cb) override;
Return<Result> sendMessageToHub(uint32_t hubId,
const ContextHubMsg &msg) override;
Return<Result> loadNanoApp(uint32_t hubId,
const NanoAppBinary& appBinary,
uint32_t transactionId) override;
Return<Result> unloadNanoApp(uint32_t hubId,
uint64_t appId,
uint32_t transactionId) override;
Return<Result> enableNanoApp(uint32_t hubId,
uint64_t appId,
uint32_t transactionId) override;
Return<Result> disableNanoApp(uint32_t hubId,
uint64_t appId,
uint32_t transactionId) override;
Return<Result> queryApps(uint32_t hubId) override;
Return<Result> reboot(uint32_t hubId);
bool isInitialized();
private:
struct CachedHubInformation{
struct hub_app_name_t osAppName;
sp<IContexthubCallback> callback;
};
class DeathRecipient : public hidl_death_recipient {
public:
DeathRecipient(const sp<Contexthub> contexthub);
void serviceDied(
uint64_t cookie,
const wp<::android::hidl::base::V1_0::IBase>& who) override;
private:
sp<Contexthub> mContexthub;
};
status_t mInitCheck;
const struct context_hub_module_t *mContextHubModule;
std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
sp<DeathRecipient> mDeathRecipient;
bool mIsTransactionPending;
uint32_t mTransactionId;
bool isValidHubId(uint32_t hubId);
sp<IContexthubCallback> getCallBackForHubId(uint32_t hubId);
int handleOsMessage(sp<IContexthubCallback> cb,
uint32_t msgType,
const uint8_t *msg,
int msgLen);
// Handle the case where the callback registered for the given hub ID dies
void handleServiceDeath(uint32_t hubId);
static int contextHubCb(uint32_t hubId,
const struct hub_message_t *rxMsg,
void *cookie);
bool setOsAppAsDestination(hub_message_t *msg, int hubId);
DISALLOW_COPY_AND_ASSIGN(Contexthub);
};
extern "C" IContexthub *HIDL_FETCH_IContexthub(const char *name);
} // namespace implementation
} // namespace V1_0
} // namespace contexthub
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_
|