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 #ifndef HDI_SAMPLE_CLIENT_CPP_INF_H
17 #define HDI_SAMPLE_CLIENT_CPP_INF_H
18
19 #include <list>
20 #include <map>
21 #include <vector>
22 #include <hdf_log.h>
23 #include <iservmgr_hdi.h>
24
25 namespace OHOS {
26 namespace HDI {
27 namespace Sample {
28 namespace V1_0 {
29 struct StructSample {
30 int8_t first;
31 int16_t second;
32 };
33
34 enum EnumSample {
35 MEM_FIRST,
36 MEM_SECOND,
37 MEM_THIRD,
38 };
39
40
41 enum {
42 CMD_BOOLEAN_TYPE_TEST,
43 CMD_BYTE_TYPE_TEST,
44 CMD_SHORT_TYPE_TEST,
45 CMD_INT_TYPE_TEST,
46 CMD_LONG_TYPE_TEST,
47 CMD_FLOAT_TYPE_TEST,
48 CMD_DOUBLE_TYPE_TEST,
49 CMD_STRING_TYPE_TEST,
50 CMD_UCHAR_TYPE_TEST,
51 CMD_USHORT_TYPE_TEST,
52 CMD_UINT_TYPE_TEST,
53 CMD_ULONG_TYPE_TEST,
54 CMD_LIST_TYPE_TEST,
55 CMD_MAP_TYPE_TEST,
56 CMD_ARRAY_TYPE_TEST,
57 CMD_STRUCT_TYPE_TEST,
58 CMD_ENUM_TYPE_TEST,
59 };
60
61 class ISample : public IRemoteBroker {
62 public:
63 DECLARE_INTERFACE_DESCRIPTOR(u"HDI.Sample.V1_0");
64
~ISample()65 virtual ~ISample(){}
66
67 static sptr<ISample> Get(const std::string& serviceName);
68
69 virtual int32_t BooleanTypeTest(const bool input, bool& output) = 0;
70
71 virtual int32_t ByteTypeTest(const int8_t input, int8_t& output) = 0;
72
73 virtual int32_t ShortTypeTest(const int16_t input, int16_t& output) = 0;
74
75 virtual int32_t IntTypeTest(const int32_t input, int32_t& output) = 0;
76
77 virtual int32_t LongTypeTest(const int64_t input, int64_t& output) = 0;
78
79 virtual int32_t FloatTypeTest(const float input, float& output) = 0;
80
81 virtual int32_t DoubleTypeTest(const double input, double& output) = 0;
82
83 virtual int32_t StringTypeTest(const std::string& input, std::string& output) = 0;
84
85 virtual int32_t UcharTypeTest(const uint8_t input, uint8_t& output) = 0;
86
87 virtual int32_t UshortTypeTest(const uint16_t input, uint16_t& output) = 0;
88
89 virtual int32_t UintTypeTest(const uint32_t input, uint32_t& output) = 0;
90
91 virtual int32_t UlongTypeTest(const uint64_t input, uint64_t& output) = 0;
92
93 virtual int32_t ListTypeTest(const std::list<int8_t>& input, std::list<int8_t>& output) = 0;
94
95 virtual int32_t MapTypeTest(const std::map<int8_t, int8_t>& input, std::map<int8_t, int8_t>& output) = 0;
96
97 virtual int32_t ArrayTypeTest(const std::vector<int8_t>& input, std::vector<int8_t>& output) = 0;
98
99 virtual int32_t StructTypeTest(const StructSample& input, StructSample& output) = 0;
100
101 virtual int32_t EnumTypeTest(const EnumSample& input, EnumSample& output) = 0;
102 };
103
Get(const std::string & serviceName)104 sptr<ISample> ISample::Get(const std::string& serviceName)
105 {
106 do {
107 using namespace OHOS::HDI::ServiceManager::V1_0;
108 auto servMgr = IServiceManager::Get();
109 if (servMgr == nullptr) {
110 break;
111 }
112
113 sptr<IRemoteObject> remote = servMgr->GetService(serviceName.c_str());
114 if (remote != nullptr) {
115 return iface_cast<ISample>(remote);
116 }
117 } while(false);
118
119 HDF_LOGE("%{public}s: get %{public}s failed!", __func__, serviceName.c_str());
120 return nullptr;
121 }
122 } // namespace V1_0
123 } // namespace Sample
124 } // namespace HDI
125 } // namespace OHOS
126
127 #endif // HDI_SAMPLE_CLIENT_CPP_INF_H