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)25 int32_t NetManagerCallBack::RequestNetwork(const std::string &ident, const std::set<NetCap> &netCaps)
26 {
27 if (netCaps.empty()) {
28 TELEPHONY_LOGI("netCaps is empty[%{public}s]", ident.c_str());
29 return CELLULAR_DATA_INVALID_PARAM;
30 }
31 NetRequest request;
32 request.capability = *netCaps.begin();
33 request.ident = ident;
34 int32_t result = DelayedRefSingleton<CellularDataService>::GetInstance().RequestNet(request);
35 return result;
36 }
37
ReleaseNetwork(const std::string & ident,const std::set<NetCap> & netCaps)38 int32_t NetManagerCallBack::ReleaseNetwork(const std::string &ident, const std::set<NetCap> &netCaps)
39 {
40 if (netCaps.empty()) {
41 TELEPHONY_LOGI("netCaps is empty[%{public}s]", ident.c_str());
42 return CELLULAR_DATA_INVALID_PARAM;
43 }
44 NetRequest request;
45 request.capability = *netCaps.begin();
46 request.ident = ident;
47 int32_t result = DelayedRefSingleton<CellularDataService>::GetInstance().ReleaseNet(request);
48 return result;
49 }
50 } // namespace Telephony
51 } // namespace OHOS