• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 OPP_GAP_CLIENT_H
17 #define OPP_GAP_CLIENT_H
18 #include <cstdint>
19 #include <memory>
20 #include "gap_if.h"
21 #include "log.h"
22 #include "raw_address.h"
23 
24 namespace OHOS {
25 namespace bluetooth {
26 /**
27  * @brief opp gap client
28  * opp gap client
29  */
30 class OppGapClient {
31 public:
32     /**
33      * @brief constructor
34      * @details constructor
35      * @param address remote device
36      * @param channel rfcomm channel or l2cap psm
37      * @param rfcommOrPsm true:l2cap false:rfcomm
38      * @return
39      */
40     OppGapClient(const std::string &address, GapSecChannel channel, bool rfcommOrPsm);
41 
42     /**
43      * @brief deconstructor
44      * @details deconstructor
45      * @return
46      */
47     virtual ~OppGapClient();
48 
49     /**
50      * @brief register gap
51      * @details register gap service
52      * @return int @c 0 success
53      *             @c not 0 failure
54      */
55     int Register();
56 
57     /**
58      * @brief deregister gap
59      * @details deregister gap service
60      * @return int @c 0 success
61      *             @c not 0 failure
62      */
63     int Deregister();
64 
65     /**
66      * @brief RequestSecurity
67      * @details RequestSecurity
68      * @return int @c 0 success
69      *             @c not 0 failure
70      */
71     int RequestSecurity();
72 
73 private:
74     void RequestSecurityCallback(uint16_t result) const;
75     static void RequestSecurityCallback(uint16_t result, GapServiceSecurityInfo security, void *context);
76 
77 private:
78     bool registered_ = false;          // registered or not
79     std::string address_;              // remote device address
80     GapSecChannel gapSecChannel_ {};   // rfcomm channel or l2cap psm
81     bool l2capOrRfcomm_ = false;       // true:l2cap false:rfcomm
82 };
83 }  // namespace bluetooth
84 }  // namespace OHOS
85 #endif  // OPP_GAP_CLIENT_H
86