• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVICE_BASE_H
17 #define GATT_SERVICE_BASE_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 #include <stddef.h>
23 #include "buffer.h"
24 #include "gatt_defines.h"
25 
26 namespace bluetooth {
27 class GattServiceBase {
28 public:
29     static const uint8_t MAXIMUM_NUMBER_APPLICATION;
30 
GattServiceBase()31     GattServiceBase() : runningState_(false), mutexRunningState_()
32     {}
~GattServiceBase()33     virtual ~GattServiceBase()
34     {}
InRunningState()35     bool InRunningState()
36     {
37         std::lock_guard<std::mutex> lck(mutexRunningState_);
38         return runningState_;
39     }
Start()40     void Start()
41     {
42         std::lock_guard<std::mutex> lck(mutexRunningState_);
43         runningState_ = true;
44     }
Stop()45     void Stop()
46     {
47         std::lock_guard<std::mutex> lck(mutexRunningState_);
48         runningState_ = false;
49     }
50 
51     static int ConvertConnectionState(const std::string &state);
52 
53     static Buffer *BuildBuffer(const uint8_t *value, size_t length);
54     static Buffer *BuildBuffer(const uint8_t *value, size_t offset, size_t length);
55 
56     static GattValue MoveToGattValue(std::unique_ptr<uint8_t[]> &value);
57     static GattValue BuildGattValue(const uint8_t *value, size_t length);
58     static int GetApplicationId();
59 
60 private:
61     bool runningState_;
62     std::mutex mutexRunningState_;
63 };
64 }  // namespace bluetooth
65 
66 #endif  // !GATT_SERVICE_BASE_H
67