179a732c7Sopenharmony_ci/*
279a732c7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License.
579a732c7Sopenharmony_ci * You may obtain a copy of the License at
679a732c7Sopenharmony_ci *
779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
879a732c7Sopenharmony_ci *
979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and
1379a732c7Sopenharmony_ci * limitations under the License.
1479a732c7Sopenharmony_ci */
1579a732c7Sopenharmony_ci
1679a732c7Sopenharmony_ci/**
1779a732c7Sopenharmony_ci * @addtogroup Softbus
1879a732c7Sopenharmony_ci * @{
1979a732c7Sopenharmony_ci *
2079a732c7Sopenharmony_ci * @brief Provides high-speed, secure communication between devices.
2179a732c7Sopenharmony_ci *
2279a732c7Sopenharmony_ci * This module implements unified distributed communication capability management between
2379a732c7Sopenharmony_ci * nearby devices, and provides link-independent device discovery and transmission interfaces
2479a732c7Sopenharmony_ci * to support service publishing and data transmission.
2579a732c7Sopenharmony_ci *
2679a732c7Sopenharmony_ci * @since 1.0
2779a732c7Sopenharmony_ci * @version 1.0
2879a732c7Sopenharmony_ci */
2979a732c7Sopenharmony_ci
3079a732c7Sopenharmony_ci/**
3179a732c7Sopenharmony_ci * @file session.h
3279a732c7Sopenharmony_ci *
3379a732c7Sopenharmony_ci * @brief Declares unified data transmission interfaces.
3479a732c7Sopenharmony_ci *
3579a732c7Sopenharmony_ci * This file provides data transmission capabilities, including creating and removing a session server,
3679a732c7Sopenharmony_ci * opening and closing sessions, receiving data, and querying basic session information. \n
3779a732c7Sopenharmony_ci * After multiple nearby devices are discovered and networked, these interfaces can be used to
3879a732c7Sopenharmony_ci * transmit data across devices. \n
3979a732c7Sopenharmony_ci *
4079a732c7Sopenharmony_ci * @since 1.0
4179a732c7Sopenharmony_ci * @version 1.0
4279a732c7Sopenharmony_ci */
4379a732c7Sopenharmony_ci#ifndef SESSION_H
4479a732c7Sopenharmony_ci#define SESSION_H
4579a732c7Sopenharmony_ci
4679a732c7Sopenharmony_ci#include <stdint.h>
4779a732c7Sopenharmony_ci
4879a732c7Sopenharmony_ci#ifdef __cplusplus
4979a732c7Sopenharmony_ciextern "C" {
5079a732c7Sopenharmony_ci#endif
5179a732c7Sopenharmony_ci/**
5279a732c7Sopenharmony_ci * @brief business type of session
5379a732c7Sopenharmony_ci *
5479a732c7Sopenharmony_ci * @since 1.0
5579a732c7Sopenharmony_ci * @version 1.0
5679a732c7Sopenharmony_ci */
5779a732c7Sopenharmony_citypedef enum {
5879a732c7Sopenharmony_ci    TYPE_MESSAGE = 1,
5979a732c7Sopenharmony_ci    TYPE_BYTES,
6079a732c7Sopenharmony_ci    TYPE_FILE,
6179a732c7Sopenharmony_ci    TYPE_STREAM,
6279a732c7Sopenharmony_ci    TYPE_BUTT,
6379a732c7Sopenharmony_ci} SessionType;
6479a732c7Sopenharmony_ci
6579a732c7Sopenharmony_citypedef enum {
6679a732c7Sopenharmony_ci    INVALID = -1,
6779a732c7Sopenharmony_ci    /*
6879a732c7Sopenharmony_ci     * Send any segment of a frame each time.
6979a732c7Sopenharmony_ci     */
7079a732c7Sopenharmony_ci    RAW_STREAM,
7179a732c7Sopenharmony_ci    /*
7279a732c7Sopenharmony_ci     * Send a whole video frame each time.
7379a732c7Sopenharmony_ci     */
7479a732c7Sopenharmony_ci    COMMON_VIDEO_STREAM,
7579a732c7Sopenharmony_ci    /*
7679a732c7Sopenharmony_ci     * Send a whole audio frame each time.
7779a732c7Sopenharmony_ci     */
7879a732c7Sopenharmony_ci    COMMON_AUDIO_STREAM,
7979a732c7Sopenharmony_ci    /*
8079a732c7Sopenharmony_ci     * Slice frame mode.
8179a732c7Sopenharmony_ci     */
8279a732c7Sopenharmony_ci    VIDEO_SLICE_STREAM,
8379a732c7Sopenharmony_ci} StreamType;
8479a732c7Sopenharmony_ci
8579a732c7Sopenharmony_citypedef enum {
8679a732c7Sopenharmony_ci    LINK_TYPE_WIFI_WLAN_5G = 1,
8779a732c7Sopenharmony_ci    LINK_TYPE_WIFI_WLAN_2G = 2,
8879a732c7Sopenharmony_ci    LINK_TYPE_WIFI_P2P = 3,
8979a732c7Sopenharmony_ci    LINK_TYPE_BR = 4,
9079a732c7Sopenharmony_ci    LINK_TYPE_MAX = 4,
9179a732c7Sopenharmony_ci} LinkType;
9279a732c7Sopenharmony_ci
9379a732c7Sopenharmony_citypedef struct {
9479a732c7Sopenharmony_ci    /** @brief dataType{@link SessionType} */
9579a732c7Sopenharmony_ci    int dataType;
9679a732c7Sopenharmony_ci    int linkTypeNum;
9779a732c7Sopenharmony_ci    LinkType linkType[LINK_TYPE_MAX];
9879a732c7Sopenharmony_ci    union {
9979a732c7Sopenharmony_ci        struct StreamAttr {
10079a732c7Sopenharmony_ci            int streamType;
10179a732c7Sopenharmony_ci        } streamAttr;
10279a732c7Sopenharmony_ci    } attr;
10379a732c7Sopenharmony_ci} SessionAttribute;
10479a732c7Sopenharmony_ci
10579a732c7Sopenharmony_citypedef struct {
10679a732c7Sopenharmony_ci    char *buf;
10779a732c7Sopenharmony_ci    int bufLen;
10879a732c7Sopenharmony_ci} StreamData;
10979a732c7Sopenharmony_ci
11079a732c7Sopenharmony_citypedef struct {
11179a732c7Sopenharmony_ci    int type;
11279a732c7Sopenharmony_ci    int64_t value;
11379a732c7Sopenharmony_ci} TV;
11479a732c7Sopenharmony_ci
11579a732c7Sopenharmony_citypedef struct {
11679a732c7Sopenharmony_ci    int frameType;
11779a732c7Sopenharmony_ci    int64_t timeStamp;
11879a732c7Sopenharmony_ci    int seqNum;
11979a732c7Sopenharmony_ci    int seqSubNum;
12079a732c7Sopenharmony_ci    int level;
12179a732c7Sopenharmony_ci    int bitMap;
12279a732c7Sopenharmony_ci    int tvCount;
12379a732c7Sopenharmony_ci    TV *tvList;
12479a732c7Sopenharmony_ci} FrameInfo;
12579a732c7Sopenharmony_ci
12679a732c7Sopenharmony_citypedef struct {
12779a732c7Sopenharmony_ci    int (*OnSessionOpened)(int sessionId, int result);
12879a732c7Sopenharmony_ci    void (*OnSessionClosed)(int sessionId);
12979a732c7Sopenharmony_ci    void (*OnBytesReceived)(int sessionId, const void *data, unsigned int dataLen);
13079a732c7Sopenharmony_ci    void (*OnMessageReceived)(int sessionId, const void *data, unsigned int dataLen);
13179a732c7Sopenharmony_ci    void (*OnStreamReceived)(int sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param);
13279a732c7Sopenharmony_ci} ISessionListener;
13379a732c7Sopenharmony_ci
13479a732c7Sopenharmony_citypedef struct {
13579a732c7Sopenharmony_ci    int (*OnReceiveFileStarted)(int sessionId, const char *files, int fileCnt);
13679a732c7Sopenharmony_ci    int (*OnReceiveFileProcess)(int sessionId, const char *firstFile, uint64_t bytesUpload, uint64_t bytesTotal);
13779a732c7Sopenharmony_ci    void (*OnReceiveFileFinished)(int sessionId, const char *files, int fileCnt);
13879a732c7Sopenharmony_ci    void (*OnFileTransError)(int sessionId);
13979a732c7Sopenharmony_ci} IFileReceiveListener;
14079a732c7Sopenharmony_ci
14179a732c7Sopenharmony_citypedef struct {
14279a732c7Sopenharmony_ci    int (*OnSendFileProcess)(int sessionId, uint64_t bytesUpload, uint64_t bytesTotal);
14379a732c7Sopenharmony_ci    int (*OnSendFileFinished)(int sessionId, const char *firstFile);
14479a732c7Sopenharmony_ci    void (*OnFileTransError)(int sessionId);
14579a732c7Sopenharmony_ci} IFileSendListener;
14679a732c7Sopenharmony_ci
14779a732c7Sopenharmony_ciint CreateSessionServer(const char *pkgName, const char *sessionName, const ISessionListener *listener);
14879a732c7Sopenharmony_ci
14979a732c7Sopenharmony_ciint RemoveSessionServer(const char *pkgName, const char *sessionName);
15079a732c7Sopenharmony_ci
15179a732c7Sopenharmony_ciint OpenSession(const char *mySessionName, const char *peerSessionName, const char *peerDeviceId, const char *groupId,
15279a732c7Sopenharmony_ci                const SessionAttribute *attr);
15379a732c7Sopenharmony_ci
15479a732c7Sopenharmony_civoid CloseSession(int sessionId);
15579a732c7Sopenharmony_ci
15679a732c7Sopenharmony_ciint SendBytes(int sessionId, const void *data, unsigned int len);
15779a732c7Sopenharmony_ci
15879a732c7Sopenharmony_ciint SendMessage(int sessionId, const void *data, unsigned int len);
15979a732c7Sopenharmony_ci
16079a732c7Sopenharmony_ciint SendStream(int sessionId, const StreamData *data, const StreamData *ext, const FrameInfo *param);
16179a732c7Sopenharmony_ci
16279a732c7Sopenharmony_ciint GetMySessionName(int sessionId, char *sessionName, unsigned int len);
16379a732c7Sopenharmony_ci
16479a732c7Sopenharmony_ciint GetPeerSessionName(int sessionId, char *sessionName, unsigned int len);
16579a732c7Sopenharmony_ci
16679a732c7Sopenharmony_ciint GetPeerDeviceId(int sessionId, char *devId, unsigned int len);
16779a732c7Sopenharmony_ci
16879a732c7Sopenharmony_ciint GetSessionSide(int sessionId);
16979a732c7Sopenharmony_ci
17079a732c7Sopenharmony_ciint SetFileReceiveListener(const char *pkgName, const char *sessionName, const IFileReceiveListener *recvListener,
17179a732c7Sopenharmony_ci                           const char *rootDir);
17279a732c7Sopenharmony_ci
17379a732c7Sopenharmony_ciint SetFileSendListener(const char *pkgName, const char *sessionName, const IFileSendListener *sendListener);
17479a732c7Sopenharmony_ci
17579a732c7Sopenharmony_ciint SendFile(int sessionId, const char *sFileList[], const char *dFileList[], uint32_t fileCnt);
17679a732c7Sopenharmony_ci#ifdef __cplusplus
17779a732c7Sopenharmony_ci}
17879a732c7Sopenharmony_ci#endif
17979a732c7Sopenharmony_ci#endif // SESSION_H
180