• 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 #include "devhost_service_clnt.h"
17 #include "devmgr_service.h"
18 #include "hdf_base.h"
19 #include "hdf_cstring.h"
20 #include "hdf_log.h"
21 #include "hdf_sbuf.h"
22 
23 #define HDF_LOG_TAG devmgr_query_device
24 
DevFillQueryDeviceInfo(struct IDevmgrService * inst,struct HdfSBuf * data,struct HdfSBuf * reply)25 int DevFillQueryDeviceInfo(struct IDevmgrService *inst, struct HdfSBuf *data, struct HdfSBuf *reply)
26 {
27     struct DevmgrService *devMgrSvc = (struct DevmgrService *)inst;
28     struct HdfSListIterator itDeviceInfo;
29     struct HdfDeviceInfo *deviceInfo = NULL;
30     struct DevHostServiceClnt *hostClnt = NULL;
31     bool flag = false;
32     uint16_t status = 0;
33 
34     if (devMgrSvc == NULL || data == NULL || reply == NULL) {
35         HDF_LOGE("%{public}s failed, parameter is null", __func__);
36         return HDF_FAILURE;
37     }
38 
39     HdfSbufReadUint16(data, &status);
40     if (status != HDF_SERVICE_UNUSABLE && status != HDF_SERVICE_USABLE) {
41         HDF_LOGE("%{public}s failed, status is invalid %{public}d", __func__, status);
42         return HDF_FAILURE;
43     }
44 
45     DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) {
46     HdfSListIteratorInit(&itDeviceInfo, &hostClnt->unloadDevInfos);
47         HDF_LOGD("%{public}s, host:%{public}s %{public}d", __func__, hostClnt->hostName, hostClnt->hostId);
48         while (HdfSListIteratorHasNext(&itDeviceInfo)) {
49             deviceInfo = (struct HdfDeviceInfo *)HdfSListIteratorNext(&itDeviceInfo);
50             HDF_LOGD("%{public}s %{public}s policy:%{public}d status:%{public}d type:%{public}d",
51                 __func__, deviceInfo->svcName, deviceInfo->policy, deviceInfo->status, deviceInfo->deviceType);
52             if ((deviceInfo->policy == SERVICE_POLICY_CAPACITY || deviceInfo->policy == SERVICE_POLICY_PUBLIC) &&
53                 deviceInfo->status == status) {
54                 flag = HdfSbufWriteString(reply, deviceInfo->svcName);
55                 if (flag == false) {
56                     HDF_LOGE("%{public}s writing string failed %{public}s", __func__, deviceInfo->svcName);
57                     return HDF_FAILURE;
58                 }
59                 flag = HdfSbufWriteInt32(reply, deviceInfo->deviceType);
60                 if (flag == false) {
61                     HDF_LOGE("%{public}s writing int32 failed %{public}d", __func__, deviceInfo->deviceType);
62                     return HDF_FAILURE;
63                 }
64             }
65         }
66     }
67     return HDF_SUCCESS;
68 }
69 
70