• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <stdio.h>
11 #include "hdf_io_service_if.h"
12 #include "hdf_uhdf_test.h"
13 
14 static struct HdfIoService *g_testService = NULL;
15 static struct HdfSBuf *g_msg = NULL;
16 static struct HdfSBuf *g_reply = NULL;
17 
HdfTestOpenService(void)18 void HdfTestOpenService(void)
19 {
20     g_testService = HdfIoServiceBind(HDF_TEST_SERVICE_NAME);
21     if (g_testService == NULL) {
22         printf("%s HdfIoServiceBind %s failed\n\r", __func__, HDF_TEST_SERVICE_NAME);
23         return;
24     }
25     g_msg = HdfSbufObtainDefaultSize();
26     if (g_msg == NULL) {
27         printf("fail to obtain sbuf data\n\r");
28         return;
29     }
30     g_reply = HdfSbufObtainDefaultSize();
31     if (g_reply == NULL) {
32         printf("fail to obtain sbuf reply\n\r");
33         HdfSbufRecycle(g_msg);
34         return;
35     }
36 }
37 
HdfTestCloseService(void)38 void HdfTestCloseService(void)
39 {
40     if (g_msg != NULL) {
41         HdfSbufRecycle(g_msg);
42         g_msg = NULL;
43     };
44     if (g_reply != NULL) {
45         HdfSbufRecycle(g_reply);
46         g_reply = NULL;
47     };
48     if (g_testService != NULL) {
49         HdfIoServiceRecycle(g_testService);
50         g_testService = NULL;
51     };
52 }
53 
HdfTestSendMsgToService(struct HdfTestMsg * msg)54 int HdfTestSendMsgToService(struct HdfTestMsg *msg)
55 {
56     int ret;
57     struct HdfTestMsg *testReply = NULL;
58     unsigned int len;
59     CHECK_TEST_NULL_PTR_RETURN(g_testService);
60     CHECK_TEST_NULL_PTR_RETURN(g_msg);
61     CHECK_TEST_NULL_PTR_RETURN(g_reply);
62     CHECK_TEST_NULL_PTR_RETURN(msg);
63 
64     if (!HdfSbufWriteBuffer(g_msg, msg, sizeof(*msg))) {
65         printf("HdfTestSendMsgToService g_msg write failed\n\r");
66     }
67 
68     ret = g_testService->dispatcher->Dispatch(&g_testService->object, 0, g_msg, g_reply);
69     if (ret != HDF_SUCCESS) {
70         printf("HdfTestSendMsgToService fail to send service call\n\r");
71         return ret;
72     }
73 
74     if (!HdfSbufReadBuffer(g_reply, (const void **)&testReply, &len)) {
75         printf("HdfTestSendMsgToService g_reply read failed\n\r");
76     }
77 
78     if (testReply == NULL) {
79         printf("HdfTestSendMsgToService testReply is null\n\r");
80         ret = -1;
81     } else {
82         ret = testReply->result;
83     }
84     HdfSbufFlush(g_msg);
85     HdfSbufFlush(g_reply);
86 
87     return ret;
88 }
89 
90