Home | History | Annotate | Download | only in contexthubhal
      1 /*
      2  * Copyright (C) 2018 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 #include "nanohub_perdevice.h"
     18 #include "nanohubhal.h"
     19 
     20 using namespace android::nanohub;
     21 
     22 static context_hub_callback *mSavedCbk = nullptr;
     23 
     24 static int legacy_cbk(uint32_t hub_id, const HubMessage &rxMsg, void *cookie)
     25 {
     26     return mSavedCbk(hub_id, &rxMsg, cookie);
     27 }
     28 
     29 static int legacy_subscribe_messages(uint32_t hub_id, context_hub_callback *cbk, void *cookie)
     30 {
     31     mSavedCbk = cbk;
     32     if (cbk)
     33         return NanoHub::subscribeMessages(hub_id, legacy_cbk, cookie);
     34     else
     35         return NanoHub::subscribeMessages(hub_id, nullptr, nullptr);
     36 }
     37 
     38 static int legacy_send_message(uint32_t hub_id, const hub_message_t *msg)
     39 {
     40     return NanoHub::sendToNanohub(hub_id, msg, 0, ENDPOINT_UNSPECIFIED);
     41 }
     42 
     43 static int legacy_get_hubs(context_hub_module_t*, const context_hub_t ** list)
     44 {
     45     *list = get_hub_info();
     46 
     47     return 1; /* we have one hub */
     48 }
     49 
     50 context_hub_module_t HAL_MODULE_INFO_SYM = {
     51     .common = {
     52         .tag = HARDWARE_MODULE_TAG,
     53         .module_api_version = CONTEXT_HUB_DEVICE_API_VERSION_1_0,
     54         .hal_api_version = HARDWARE_HAL_API_VERSION,
     55         .id = CONTEXT_HUB_MODULE_ID,
     56         .name = "Nanohub HAL",
     57         .author = "Google",
     58     },
     59 
     60     .get_hubs = legacy_get_hubs,
     61     .subscribe_messages = legacy_subscribe_messages,
     62     .send_message = legacy_send_message,
     63 };
     64