1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DRIVER_EXTENSION_CONTROLLER_H 17 #define DRIVER_EXTENSION_CONTROLLER_H 18 #include <string> 19 #include <memory> 20 #include <map> 21 #include "single_instance.h" 22 #include "iremote_object.h" 23 24 namespace OHOS { 25 namespace ExternalDeviceManager { 26 class IDriverExtensionConnectCallback; 27 class DriverExtensionController { 28 DECLARE_SINGLE_INSTANCE_BASE(DriverExtensionController); 29 public: 30 ~DriverExtensionController() = default; 31 int32_t StartDriverExtension(std::string baudleName, std::string abilityName); 32 int32_t StopDriverExtension(std::string bundleName, std::string abilityName, int32_t userId = -1); 33 int32_t ConnectDriverExtension( 34 std::string bundleName, 35 std::string abilityName, 36 std::shared_ptr<IDriverExtensionConnectCallback> callback, 37 uint32_t deviceId = 0 38 ); 39 int32_t DisconnectDriverExtension( 40 std::string bundleName, 41 std::string abilityName, 42 std::shared_ptr<IDriverExtensionConnectCallback> callback, 43 uint32_t deviceId = 0 44 ); 45 class DriverExtensionAbilityConnection; 46 47 private: 48 DriverExtensionController() = default; 49 }; 50 51 struct DrvExtConnectionInfo { 52 std::string bundleName_; 53 std::string abilityName_; 54 uint32_t deviceId_; 55 sptr<DriverExtensionController::DriverExtensionAbilityConnection> connectInner_; 56 }; 57 58 class IDriverExtensionConnectCallback { 59 public: 60 virtual ~IDriverExtensionConnectCallback() = default; 61 virtual int32_t OnConnectDone(const sptr<IRemoteObject> &remote, int resultCode) = 0; 62 virtual int32_t OnDisconnectDone(int resultCode) = 0; 63 bool IsConnectDone(); 64 sptr<IRemoteObject> GetRemoteObj(); 65 protected: 66 friend class DriverExtensionController; 67 std::shared_ptr<DrvExtConnectionInfo> info_ = nullptr; 68 }; 69 } 70 } 71 #endif