1 /** 2 * Copyright (C) 2022 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 BASE_MANAGER_H 18 #define BASE_MANAGER_H 19 20 #include <binder/Parcel.h> 21 #include <functional> 22 23 typedef int (*CBManager)(int sessionId, const android::Parcel& parcel); 24 25 class BaseManager 26 { 27 public: 28 BaseManager(); 29 virtual ~BaseManager(); 30 31 /** 32 * @brief Send message to session to operate 33 * 34 * @param sessionId identification of session 35 * @param parcel parcel of message and parameters 36 */ 37 virtual void sendMessage(const int sessionId, const android::Parcel& parcel) = 0; 38 39 /** 40 * @brief Set the Callback object 41 * 42 * @param pfnCallback 43 */ 44 virtual void setCallback(CBManager pfnCallback); 45 46 /** 47 * @brief Send response message to assigend callback method 48 * 49 * @param sessionId The unique identification of the session 50 * @param parcel The parcel object contains event message and parameter 51 * @return int Returns -1 when it is fail invoke callback function. Returns 1 when it is 52 * success. 53 */ 54 virtual int sendResponse(int sessionId, const android::Parcel& parcel); 55 56 protected: 57 virtual int getState(int sessionId) = 0; 58 std::function<int(int, const android::Parcel&)> mCallback; 59 }; 60 61 #endif