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 #include "net_manager_call_back.h"
17 
18 #include "cellular_data_constant.h"
19 #include "cellular_data_error.h"
20 #include "cellular_data_service.h"
21 #include "cellular_data_types.h"
22 
23 namespace OHOS {
24 namespace Telephony {
RequestNetwork(const std::string & ident,const std::set<NetCap> & netCaps,const NetManagerStandard::NetRequest & netrequest)25 int32_t NetManagerCallBack::RequestNetwork(const std::string &ident,
26                                            const std::set<NetCap> &netCaps,
27                                            const NetManagerStandard::NetRequest &netrequest)
28 {
29     if (netCaps.empty()) {
30         TELEPHONY_LOGI("netCaps is empty[%{public}s]", ident.c_str());
31         return CELLULAR_DATA_INVALID_PARAM;
32     }
33     NetRequest request;
34     for (const auto &netCap : netCaps) {
35         request.capability |= 1L << netCap;
36     }
37     request.ident = ident;
38     request.registerType = netrequest.registerType;
39     for (const auto &netBearType : netrequest.bearTypes) {
40         request.bearTypes |= 1L << netBearType;
41     }
42     int32_t result = DelayedRefSingleton<CellularDataService>::GetInstance().RequestNet(request);
43     return result;
44 }
45 
ReleaseNetwork(const std::string & ident,const std::set<NetCap> & netCaps)46 int32_t NetManagerCallBack::ReleaseNetwork(const std::string &ident, const std::set<NetCap> &netCaps)
47 {
48     if (netCaps.empty()) {
49         TELEPHONY_LOGI("netCaps is empty[%{public}s]", ident.c_str());
50         return CELLULAR_DATA_INVALID_PARAM;
51     }
52     NetRequest request;
53     for (const auto &netCap : netCaps) {
54         request.capability |= 1L << netCap;
55     }
56     request.ident = ident;
57     int32_t result = DelayedRefSingleton<CellularDataService>::GetInstance().ReleaseNet(request);
58     return result;
59 }
60 } // namespace Telephony
61 } // namespace OHOS