• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "idl_test_service_proxy.h"
17 
18 namespace OHOS {
TestIntTransaction(int _data,int & result)19 ErrCode IdlTestServiceProxy::TestIntTransaction(int _data, int& result)
20 {
21     MessageParcel data;
22     MessageParcel reply;
23     MessageOption option(MessageOption::TF_SYNC);
24 
25     if (!data.WriteInterfaceToken(GetDescriptor())) {
26         return ERR_INVALID_VALUE;
27     }
28 
29     data.WriteInt32(_data);
30 
31     if (Remote() == nullptr) {
32         return ERR_INVALID_VALUE;
33     }
34     int32_t st = Remote()->SendRequest(COMMAND_TEST_INT_TRANSACTION, data, reply, option);
35     if (st != ERR_NONE) {
36         return st;
37     }
38 
39     ErrCode ec = reply.ReadInt32();
40     if (FAILED(ec)) {
41         return ec;
42     }
43 
44     result = reply.ReadInt32();
45     return ERR_OK;
46 }
47 
TestStringTransaction(const std::string & _data)48 ErrCode IdlTestServiceProxy::TestStringTransaction(const std::string& _data)
49 {
50     MessageParcel data;
51     MessageParcel reply;
52     MessageOption option(MessageOption::TF_SYNC);
53 
54     if (!data.WriteInterfaceToken(GetDescriptor())) {
55         return ERR_INVALID_VALUE;
56     }
57 
58     data.WriteString16(Str8ToStr16(_data));
59 
60     if (Remote() == nullptr) {
61         return ERR_INVALID_VALUE;
62     }
63     int32_t st = Remote()->SendRequest(COMMAND_TEST_STRING_TRANSACTION, data, reply, option);
64     if (st != ERR_NONE) {
65         return st;
66     }
67 
68     ErrCode ec = reply.ReadInt32();
69     if (FAILED(ec)) {
70         return ec;
71     }
72 
73     return ERR_OK;
74 }
75 } // namespace OHOS
76