1bae4d13cSopenharmony_ci/* 2bae4d13cSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3bae4d13cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bae4d13cSopenharmony_ci * you may not use this file except in compliance with the License. 5bae4d13cSopenharmony_ci * You may obtain a copy of the License at 6bae4d13cSopenharmony_ci * 7bae4d13cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bae4d13cSopenharmony_ci * 9bae4d13cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bae4d13cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bae4d13cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bae4d13cSopenharmony_ci * See the License for the specific language governing permissions and 13bae4d13cSopenharmony_ci * limitations under the License. 14bae4d13cSopenharmony_ci */ 15bae4d13cSopenharmony_ci 16bae4d13cSopenharmony_ci#ifndef RUST_BINDING_H 17bae4d13cSopenharmony_ci#define RUST_BINDING_H 18bae4d13cSopenharmony_ci#include <stdint.h> 19bae4d13cSopenharmony_ci#include <string.h> 20bae4d13cSopenharmony_ci#include "proto.h" 21bae4d13cSopenharmony_ci 22bae4d13cSopenharmony_ciextern "C" { 23bae4d13cSopenharmony_ci struct RustStreamSocket; 24bae4d13cSopenharmony_ci struct RustStreamSession; 25bae4d13cSopenharmony_ci struct RustStreamBuffer; 26bae4d13cSopenharmony_ci struct RustNetPacket { 27bae4d13cSopenharmony_ci OHOS::Sensors::MessageId msgId { OHOS::Sensors::MessageId::INVALID }; 28bae4d13cSopenharmony_ci struct RustStreamBuffer *streamBuffer; 29bae4d13cSopenharmony_ci }; 30bae4d13cSopenharmony_ci RustStreamSocket *StreamSocketCreate(void); 31bae4d13cSopenharmony_ci void StreamSocketDelete(RustStreamSocket *raw); 32bae4d13cSopenharmony_ci int32_t StreamSocketGetFd(const RustStreamSocket *rustStreamSocket); 33bae4d13cSopenharmony_ci int32_t StreamSocketClose(RustStreamSocket *rustStreamSocket); 34bae4d13cSopenharmony_ci int32_t StreamSocketSetFd(RustStreamSocket *rustStreamSocket, int32_t fd); 35bae4d13cSopenharmony_ci RustStreamSession *StreamSessionCreate(void); 36bae4d13cSopenharmony_ci void StreamSessionDelete(RustStreamSession *raw); 37bae4d13cSopenharmony_ci void StreamSessionSetUid(RustStreamSession *rustStreamSession, int32_t uid); 38bae4d13cSopenharmony_ci void StreamSessionSetPid(RustStreamSession *rustStreamSession, int32_t pid); 39bae4d13cSopenharmony_ci void StreamSessionSetFd(RustStreamSession *rustStreamSession, int32_t fd); 40bae4d13cSopenharmony_ci void StreamSessionClose(RustStreamSession *rustStreamSession); 41bae4d13cSopenharmony_ci bool StreamSessionSendMsg(const RustStreamSession *rustStreamSession, const char *buf, size_t size); 42bae4d13cSopenharmony_ci int32_t StreamSessionGetUid(const RustStreamSession *rustStreamSession); 43bae4d13cSopenharmony_ci int32_t StreamSessionGetPid(const RustStreamSession *rustStreamSession); 44bae4d13cSopenharmony_ci int32_t StreamSessionGetFd(const RustStreamSession *rustStreamSession); 45bae4d13cSopenharmony_ci void StreamSessionSetTokenType(RustStreamSession *rustStreamSession, int32_t type); 46bae4d13cSopenharmony_ci int32_t StreamSessionGetTokenType(const RustStreamSession *rustStreamSession); 47bae4d13cSopenharmony_ci int32_t StreamSessionGetModuleType(const RustStreamSession *rustStreamSession); 48bae4d13cSopenharmony_ci RustStreamBuffer *StreamBufferCreate(void); 49bae4d13cSopenharmony_ci void StreamBufferDelete(RustStreamBuffer *raw); 50bae4d13cSopenharmony_ci int32_t StreamBufferGetWcount(const RustStreamBuffer *rustStreamBuffer); 51bae4d13cSopenharmony_ci int32_t StreamBufferGetRcount(const RustStreamBuffer *rustStreamBuffer); 52bae4d13cSopenharmony_ci int32_t StreamBufferGetWpos(const RustStreamBuffer *rustStreamBuffer); 53bae4d13cSopenharmony_ci int32_t StreamBufferGetRpos(const RustStreamBuffer *rustStreamBuffer); 54bae4d13cSopenharmony_ci const char *StreamBufferGetSzBuff(const RustStreamBuffer *rustStreamBuffer); 55bae4d13cSopenharmony_ci int32_t StreamBufferSetRwErrStatus(RustStreamBuffer *rustStreamBuffer, int32_t rwErrStatus); 56bae4d13cSopenharmony_ci int32_t StreamBufferSetRpos(RustStreamBuffer *rustStreamBuffer, int32_t rPos); 57bae4d13cSopenharmony_ci void StreamBufferReset(RustStreamBuffer *rustStreamBuffer); 58bae4d13cSopenharmony_ci void StreamBufferClean(RustStreamBuffer *rustStreamBuffer); 59bae4d13cSopenharmony_ci bool StreamBufferRead(RustStreamBuffer *rustStreamBuffer1, RustStreamBuffer *rustStreamBuffer2); 60bae4d13cSopenharmony_ci bool StreamBufferWrite(RustStreamBuffer *rustStreamBuffer1, const RustStreamBuffer *rustStreamBuffer2); 61bae4d13cSopenharmony_ci const char *StreamBufferReadBuf(const RustStreamBuffer *rustStreamBuffer); 62bae4d13cSopenharmony_ci bool StreamBufferReadChar(RustStreamBuffer *rustStreamBuffer, char *buf, size_t size); 63bae4d13cSopenharmony_ci bool StreamBufferWriteChar(RustStreamBuffer *rustStreamBuffer, const char *buf, size_t size); 64bae4d13cSopenharmony_ci const char *StreamBufferData(const RustStreamBuffer *rustStreamBuffer); 65bae4d13cSopenharmony_ci size_t StreamBufferSize(const RustStreamBuffer *rustStreamBuffer); 66bae4d13cSopenharmony_ci const char *StreamBufferGetErrorStatusRemark(const RustStreamBuffer *rustStreamBuffer); 67bae4d13cSopenharmony_ci bool StreamBufferChkRWError(const RustStreamBuffer *rustStreamBuffer); 68bae4d13cSopenharmony_ci bool StreamBufferCheckWrite(RustStreamBuffer *rustStreamBuffer, size_t size); 69bae4d13cSopenharmony_ci bool CircleStreamBufferWrite(RustStreamBuffer *rustStreamBuffer, const char *buf, size_t size); 70bae4d13cSopenharmony_ci void CircleStreamBufferCopyDataToBegin(RustStreamBuffer *rustStreamBuffer); 71bae4d13cSopenharmony_ci} 72bae4d13cSopenharmony_ci#endif // RUST_BINDING_H