目录

Development for the Sending Device

Scenario Design

For details, please refer to Scenario Design for the Sending Device.

Development Process

Add the following code to the device-side user process to integrate the capabilities into the sending device:
int main(int argc, char* argv[])
{
    signal(SIGINT, Exit);
    int num = 0;
    printf("Debug tx for role %d.\n", TRANSMITTER);
    char** uriList = ScanFileName(SEND_PATH, &num);
    if (InitShareKit(NULL) != 0) {
        goto done;
    }
    ShareTransHandle transHandle;
    memset(&transHandle, 0, sizeof(ShareTransHandle));
    transHandle.statusCb = SharekitStatusChangeCbFunc;
    if (StartShareService(TRANSMITTER, &transHandle) != 0) {
        goto done;
    }
    ShareDeviceInfo* dev = NULL;
    dev = SelectDev();
    ShareFileInfo files;
    memset(&files, 0, sizeof(ShareFileInfo));
    files.uriList = uriList;
    files.fileNum = num;
    if (dev != NULL) {
        (void)TransFile(dev, &files);
    }
    FreeFileList(uriList, num);
    StopShareService();
    UninitShareKit();
    sleep(1);
    printf("main exit. \n");
    return 0;
}

[h2]Initializing Share Engine

Starts the request for initializing device resources for Share Engine.

Function Declaration

int InitShare Kit(void* handle)

Parameter

void*

handle

  • void * type
  • Extended parameter, which is not used currently.

Return Value

int

0: success; other values: failure

[h2]Registering a Callback

Notify the user of the file sending progress.

Function Declaration

typedef void(*ShareProgressCallback)(int process)

Parameter

int

process

Sending progress

Return Value

void

NA

Notify the user of any status change, for example, when the sending is complete or has been canceled.

Function Declaration

typedef void(*ShareStatusCallback)(ShareStatus* status)

Parameter

ShareStatus*

status

Current state

Return Value

void

NA

[h2]Searching for Devices

The sending device discovers available devices in close proximity using BLE advertising.

Function Declaration

int GetAvailableDevice(ShareDeviceInfo** devInfo, int* devNum)

Parameter

ShareDeviceInfo**

devInfo

  • Output parameters.
  • Save the detected devices.

int*

devNum

  • Output parameters.
  • Save the number of detected devices.

Return Value

int

0: success; other values: failure

[h2]Selecting a Device and Initiate Sharing

Select a connected device to share specific files with it.

Function Declaration

int TransFile(const ShareDeviceInfo* device, const ShareFileInfo* files)

Parameter

const ShareDeviceInfo*

device

Information about the receiving device, such as its MAC address

const ShareFileInfo*

files

Information about the files to share

Return Value

int

0: success; other values: failure

[h2]Obtaining the Active Device and Cancel Sharing

Cancel sending.

Function Declaration

void CancelTransFile(void)

Return Value

void

-

[h2]Stopping Searching

End the searching service.

Function Declaration

int StopShareService(void)

Return Value

int

0: success; other values: failure

[h2]Unregistering Share Engine

Release the system resources occupied by Share Engine.

Function Declaration

int UninitShare Kit(void)

Return Value

int

0: success; other values: failure

For details about the APIs, please refer to the API Reference.

For details about the code example, please refer to the Sample Code.