blob: 0883ce8215c0496c7d6d7e82d7cc1c166ae4d354 [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,
43 const ::android::hardware::hidl_vec<uint8_t>& appBinary,
44 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;
68 sp<IContexthubCallback> callBack;
69 };
70
71 status_t mInitCheck;
72 const struct context_hub_module_t *mContextHubModule;
73 std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
74
75 sp<IContexthubCallback> mCb;
76 bool mIsTransactionPending;
77 uint32_t mTransactionId;
78
79 bool isValidHubId(uint32_t hubId);
80
81 sp<IContexthubCallback> getCallBackForHubId(uint32_t hubId);
82
83 int handleOsMessage(sp<IContexthubCallback> cb,
84 uint32_t msgType,
85 const uint8_t *msg,
86 int msgLen);
87
88 static int contextHubCb(uint32_t hubId,
89 const struct hub_message_t *rxMsg,
90 void *cookie);
91
92 bool setOsAppAsDestination(hub_message_t *msg, int hubId);
93
94 DISALLOW_COPY_AND_ASSIGN(Contexthub);
95};
96
97extern "C" IContexthub *HIDL_FETCH_IContexthub(const char *name);
98
99} // namespace implementation
100} // namespace V1_0
101} // namespace contexthub
102} // namespace hardware
103} // namespace android
104
105#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_0_CONTEXTHUB_H_