1 /*
2  * Copyright (c) 2023 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 RUST_BINDING_H
17 #define RUST_BINDING_H
18 #include <stdint.h>
19 #include <string.h>
20 #include "proto.h"
21 
22 extern "C" {
23     struct RustStreamSocket;
24     struct RustStreamSession;
25     struct RustStreamBuffer;
26     struct RustNetPacket {
27         OHOS::Sensors::MessageId msgId { OHOS::Sensors::MessageId::INVALID };
28         struct RustStreamBuffer *streamBuffer;
29     };
30     RustStreamSocket *StreamSocketCreate(void);
31     void StreamSocketDelete(RustStreamSocket *raw);
32     int32_t StreamSocketGetFd(const RustStreamSocket *rustStreamSocket);
33     int32_t StreamSocketClose(RustStreamSocket *rustStreamSocket);
34     int32_t StreamSocketSetFd(RustStreamSocket *rustStreamSocket, int32_t fd);
35     RustStreamSession *StreamSessionCreate(void);
36     void StreamSessionDelete(RustStreamSession *raw);
37     void StreamSessionSetUid(RustStreamSession *rustStreamSession, int32_t uid);
38     void StreamSessionSetPid(RustStreamSession *rustStreamSession, int32_t pid);
39     void StreamSessionSetFd(RustStreamSession *rustStreamSession, int32_t fd);
40     void StreamSessionClose(RustStreamSession *rustStreamSession);
41     bool StreamSessionSendMsg(const RustStreamSession *rustStreamSession, const char *buf, size_t size);
42     int32_t StreamSessionGetUid(const RustStreamSession *rustStreamSession);
43     int32_t StreamSessionGetPid(const RustStreamSession *rustStreamSession);
44     int32_t StreamSessionGetFd(const RustStreamSession *rustStreamSession);
45     void StreamSessionSetTokenType(RustStreamSession *rustStreamSession, int32_t type);
46     int32_t StreamSessionGetTokenType(const RustStreamSession *rustStreamSession);
47     int32_t StreamSessionGetModuleType(const RustStreamSession *rustStreamSession);
48     RustStreamBuffer *StreamBufferCreate(void);
49     void StreamBufferDelete(RustStreamBuffer *raw);
50     int32_t StreamBufferGetWcount(const RustStreamBuffer *rustStreamBuffer);
51     int32_t StreamBufferGetRcount(const RustStreamBuffer *rustStreamBuffer);
52     int32_t StreamBufferGetWpos(const RustStreamBuffer *rustStreamBuffer);
53     int32_t StreamBufferGetRpos(const RustStreamBuffer *rustStreamBuffer);
54     const char *StreamBufferGetSzBuff(const RustStreamBuffer *rustStreamBuffer);
55     int32_t StreamBufferSetRwErrStatus(RustStreamBuffer *rustStreamBuffer, int32_t rwErrStatus);
56     int32_t StreamBufferSetRpos(RustStreamBuffer *rustStreamBuffer, int32_t rPos);
57     void StreamBufferReset(RustStreamBuffer *rustStreamBuffer);
58     void StreamBufferClean(RustStreamBuffer *rustStreamBuffer);
59     bool StreamBufferRead(RustStreamBuffer *rustStreamBuffer1, RustStreamBuffer *rustStreamBuffer2);
60     bool StreamBufferWrite(RustStreamBuffer *rustStreamBuffer1, const RustStreamBuffer *rustStreamBuffer2);
61     const char *StreamBufferReadBuf(const RustStreamBuffer *rustStreamBuffer);
62     bool StreamBufferReadChar(RustStreamBuffer *rustStreamBuffer, char *buf, size_t size);
63     bool StreamBufferWriteChar(RustStreamBuffer *rustStreamBuffer, const char *buf, size_t size);
64     const char *StreamBufferData(const RustStreamBuffer *rustStreamBuffer);
65     size_t StreamBufferSize(const RustStreamBuffer *rustStreamBuffer);
66     const char *StreamBufferGetErrorStatusRemark(const RustStreamBuffer *rustStreamBuffer);
67     bool StreamBufferChkRWError(const RustStreamBuffer *rustStreamBuffer);
68     bool StreamBufferCheckWrite(RustStreamBuffer *rustStreamBuffer, size_t size);
69     bool CircleStreamBufferWrite(RustStreamBuffer *rustStreamBuffer, const char *buf, size_t size);
70     void CircleStreamBufferCopyDataToBegin(RustStreamBuffer *rustStreamBuffer);
71 }
72 #endif // RUST_BINDING_H