Home | History | Annotate | Download | only in wifi_offload
      1 /*
      2  * Copyright (C) 2017 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 #ifndef WIFI_OFFLOAD_CHRE_INTERFACE_H_
     17 #define WIFI_OFFLOAD_CHRE_INTERFACE_H_
     18 
     19 #include "chre_constants.h"
     20 #include "chre_host/host_protocol_host.h"
     21 #include "chre_host/socket_client.h"
     22 #include "chre_interface_callbacks.h"
     23 
     24 namespace android {
     25 namespace hardware {
     26 namespace wifi {
     27 namespace offload {
     28 namespace V1_0 {
     29 namespace implementation {
     30 
     31 class ChreInterface;
     32 
     33 class SocketCallbacks
     34     : public ::android::chre::SocketClient::ICallbacks,
     35       public ::android::chre::IChreMessageHandlers {
     36   public:
     37     SocketCallbacks(ChreInterface* parent);
     38     void onMessageReceived(const void* data, size_t length) override;
     39     void onConnected() override;
     40     void onConnectionAborted() override;
     41     void onDisconnected() override;
     42     void handleNanoappMessage(const ::chre::fbs::NanoappMessageT& message) override;
     43     void handleHubInfoResponse(const ::chre::fbs::HubInfoResponseT& response) override;
     44     void handleNanoappListResponse(const ::chre::fbs::NanoappListResponseT& response) override;
     45     void handleLoadNanoappResponse(const ::chre::fbs::LoadNanoappResponseT& response) override;
     46     void handleUnloadNanoappResponse(const ::chre::fbs::UnloadNanoappResponseT& response) override;
     47 
     48   private:
     49     /* Requests Hub Information, returns true if Hub Info request was sent */
     50     bool getHubInfo();
     51     /* Request list of Nano apps, returns true if Nano app List request was sent */
     52     bool getNanoAppList();
     53     ChreInterface* mParent;
     54 };
     55 
     56 class ChreInterface {
     57   public:
     58     ChreInterface(ChreInterfaceCallbacks* callback);
     59     ~ChreInterface();
     60     /* Return the status of socket connection */
     61     bool isConnected();
     62     /* Send a message to the Nano app, returns true if send successful */
     63     bool sendCommandToApp(uint32_t messageType, const std::vector<uint8_t>& message);
     64     /* Connected or connection restart handling method */
     65     void reportConnectionEvent(ChreInterfaceCallbacks::ConnectionEvent /* event */);
     66     /* Requests Hub Information, returns true if Hub Info request was sent */
     67     bool getHubInfo();
     68     /* Request list of Nano apps, returns true if Nano app List request was sent */
     69     bool getNanoAppList();
     70     /* Invoked by the socket callbacks when a message is recieved from Nano app */
     71     void handleMessage(uint32_t messageType, const void* messageData, size_t messageDataLen);
     72 
     73   private:
     74     ::android::chre::SocketClient mClient;
     75     sp<SocketCallbacks> mSocketCallbacks;
     76     ChreInterfaceCallbacks* mServerCallbacks;
     77     std::mutex mChreInterfaceLock;
     78     bool mSocketConnected;
     79 };
     80 
     81 }  // namespace implementation
     82 }  // namespace V1_0
     83 }  // namespace offload
     84 }  // namespace wifi
     85 }  // namespace hardware
     86 }  // namespace android
     87 #endif  // WIFI_OFFLOAD_CHRE_INTERFACE_H_
     88