1 /* 2 * Copyright (C) 2021-2022 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 GATT_CLIENT_SERVICE_H 17 #define GATT_CLIENT_SERVICE_H 18 19 #include <cstdint> 20 #include <list> 21 #include <memory> 22 #include <vector> 23 #include "base_def.h" 24 #include "context.h" 25 #include "bt_uuid.h" 26 #include "gatt_data.h" 27 #include "interface_profile_gatt_client.h" 28 #include "raw_address.h" 29 30 namespace OHOS { 31 namespace bluetooth { 32 class GattClientService : public IProfileGattClient, public utility::Context { 33 public: 34 int RegisterApplication(IGattClientCallback &callback, const RawAddress &addr, uint8_t transport) override; 35 int RegisterSharedApplication(IGattClientCallback &callback, const RawAddress &addr, uint8_t transport) override; 36 int DeregisterApplication(int appId) override; 37 int Connect(int appId, bool autoConnect = false) override; 38 int Disconnect(int appId) override; 39 int DiscoveryServices(int appId) override; 40 int ReadCharacteristic(int appId, const Characteristic &characteristic) override; 41 int ReadCharacteristicByUuid(int appId, const Uuid &uuid) override; 42 int WriteCharacteristic(int appId, Characteristic &characteristic, bool withoutRespond = false) override; 43 int SignedWriteCharacteristic(int appId, Characteristic &characteristic) override; 44 int ReadDescriptor(int appId, const Descriptor &descriptor) override; 45 int WriteDescriptor(int appId, Descriptor &descriptor) override; 46 int RequestExchangeMtu(int appId, int mtu) override; 47 std::vector<GattDevice> GetAllDevice() override; 48 int RequestConnectionPriority(int appId, int connPriority) override; 49 std::vector<Service> GetServices(int appId) override; 50 51 GattClientService(); 52 ~GattClientService(); 53 54 /// Inherited from the parent class 55 void Enable() override; 56 void Disable() override; 57 utility::Context *GetContext() override; 58 59 int GetConnectState() override; 60 int GetMaxConnectNum() override; 61 std::list<RawAddress> GetConnectDevices() override; 62 63 BT_DISALLOW_COPY_AND_ASSIGN(GattClientService); 64 65 private: 66 int Connect(const RawAddress &device) override; 67 int Disconnect(const RawAddress &device) override; 68 DECLARE_IMPL(); 69 }; 70 } // namespace bluetooth 71 } // namespace OHOS 72 73 #endif // !GATT_CLIENT_SERVICE_H 74