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 "rpc_trans_callback.h"
17
18 #include "dbinder_invoker.h"
19 #include "rpc_errno.h"
20 #include "rpc_log.h"
21
OnConnected(int32_t sessionId,int32_t result)22 static int32_t OnConnected(int32_t sessionId, int32_t result)
23 {
24 if (sessionId < 0 || result != 0) {
25 RPC_LOG_ERROR("fail to open session because of wrong channel ID");
26 return ERR_FAILED;
27 }
28 RPC_LOG_INFO("rpc OnConnected callback, receive sessionId: %d", sessionId);
29 return OnReceiveNewConnection(sessionId);
30 }
31
OnDisconnected(int32_t sessionId)32 static int32_t OnDisconnected(int32_t sessionId)
33 {
34 RPC_LOG_INFO("rpc OnDisconnected callback, receive sessionId: %d", sessionId);
35 OnDatabusSessionClosed(sessionId);
36 return ERR_NONE;
37 }
38
OnRecieved(int32_t sessionId,const void * data,uint32_t len)39 static int32_t OnRecieved(int32_t sessionId, const void *data, uint32_t len)
40 {
41 RPC_LOG_INFO("rpc OnRecieved callback, receive sessionId: %d", sessionId);
42 OnMessageAvailable(sessionId, data, len);
43 return ERR_NONE;
44 }
45
46 static TransCallback g_sessionListener = {
47 .OnConnected = OnConnected,
48 .OnDisconnected = OnDisconnected,
49 .OnRecieved = OnRecieved
50 };
51
GetRpcTransCallback(void)52 TransCallback *GetRpcTransCallback(void)
53 {
54 RPC_LOG_INFO("GetTransCallback rpc");
55 return &g_sessionListener;
56 }