1 /* 2 * Copyright (C) 2021 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_SERVER_SERVICE_H 17 #define GATT_SERVER_SERVICE_H 18 19 #include <list> 20 #include <string> 21 #include "base_def.h" 22 #include "context.h" 23 #include "gatt_data.h" 24 #include "interface_profile_gatt_server.h" 25 #include "raw_address.h" 26 27 namespace bluetooth { 28 class GattServerService : public IProfileGattServer, public utility::Context { 29 public: 30 int RegisterApplication(std::shared_ptr<IGattServerCallback> callback) override; 31 int DeregisterApplication(int appId) override; 32 int AddService(int appId, Service &service) override; 33 int RemoveService(int appId, const Service &service) override; 34 int ClearServices(int appId) override; 35 int NotifyClient(const GattDevice &device, Characteristic &characteristic, bool needConfirm = false) override; 36 int RespondCharacteristicRead(const GattDevice &device, Characteristic &characteristic, int ret) override; 37 int RespondCharacteristicReadByUuid(const GattDevice &device, Characteristic &characteristic, int ret) override; 38 int RespondCharacteristicWrite(const GattDevice &device, const Characteristic &characteristic, int ret) override; 39 int RespondDescriptorRead(const GattDevice &device, Descriptor &descriptor, int ret) override; 40 int RespondDescriptorWrite(const GattDevice &device, const Descriptor &descriptor, int ret) override; 41 int CancelConnection(const GattDevice &device) override; 42 int SetCharacteristicValue(const Characteristic &characteristic); 43 int SetCharacteristicPermission(const Characteristic &characteristic, uint8_t properties, uint8_t permission); 44 45 int RegisterApplicationSync(std::shared_ptr<IGattServerCallback> callback) const; 46 int DeregisterApplicationSync(int appId) const; 47 int AddServiceSync(int appId, Service &service) const; 48 const std::string GetDatabaseHash() const; 49 50 GattServerService(); 51 ~GattServerService(); 52 53 /// Inherited from the parent class 54 void Enable() override; 55 void Disable() override; 56 utility::Context *GetContext() override; 57 58 std::list<RawAddress> GetConnectDevices() override; 59 int GetConnectState() override; 60 int GetMaxConnectNum() override; 61 62 DISALLOW_COPY_AND_ASSIGN(GattServerService); 63 64 private: 65 int Connect(const RawAddress &device) override; 66 int Disconnect(const RawAddress &device) override; 67 68 DECLARE_IMPL(); 69 }; 70 } // namespace bluetooth 71 72 #endif // !GATT_SERVER_SERVICE_H 73