Tizen Native API  7.0

The cion server API provides functions for cion server.

Required Header

#include <cion.h>

Overview

The cion server can accept connection request and send or receive data. It provides functions to create cion server and communication APIs.

Functions

int cion_server_create (cion_server_h *server, const char *service_name, const char *display_name, cion_security_h security)
 Creates the Cion server handle.
int cion_server_destroy (cion_server_h server)
 Destroys the Cion server handle.
int cion_server_listen (cion_server_h server, cion_server_connection_request_cb cb, void *user_data)
 Starts listening to connection requests from clients.
int cion_server_stop (cion_server_h server)
 Stops listening to connection requests from clients.
int cion_server_disconnect (cion_server_h server, cion_peer_info_h peer_info)
 Disconnects from a client.
int cion_server_send_payload_async (cion_server_h server, cion_peer_info_h peer_info, cion_payload_h payload, cion_server_payload_async_result_cb cb, void *user_data)
 Sends payload asynchronously.
int cion_server_foreach_connected_peer_info (cion_server_h server, cion_server_connected_peer_info_cb callback, void *user_data)
 Gets connected peers information.
int cion_server_add_connection_result_cb (cion_server_h server, cion_server_connection_result_cb cb, void *user_data)
 Adds callback function for connection result.
int cion_server_remove_connection_result_cb (cion_server_h server, cion_server_connection_result_cb cb)
 Removes callback function for connection result.
int cion_server_add_payload_received_cb (cion_server_h server, cion_server_payload_received_cb cb, void *user_data)
 Adds callback function to receive payload.
int cion_server_remove_payload_received_cb (cion_server_h server, cion_server_payload_received_cb cb)
 Removes callback function to receive payload.
int cion_server_set_data_received_cb (cion_server_h server, cion_server_data_received_cb cb, void *user_data)
 Sets callback function to receive data.
int cion_server_unset_data_received_cb (cion_server_h server)
 Unsets callback function to receive data.
int cion_server_add_disconnected_cb (cion_server_h server, cion_server_disconnected_cb cb, void *user_data)
 Adds callback function for disconnection event.
int cion_server_remove_disconnected_cb (cion_server_h server, cion_server_disconnected_cb cb)
 Removes callback function for disconnection event.
int cion_server_accept (cion_server_h server, const cion_peer_info_h peer_info)
 Accepts the connection request from a peer.
int cion_server_reject (cion_server_h server, const cion_peer_info_h peer_info, const char *reason)
 Rejects the connection request from a peer.
int cion_server_set_display_name (cion_server_h server, const char *display_name)
 Sets the server display name.
int cion_server_set_on_demand_launch_enabled (cion_server_h server, bool enabled)
 Sets on-demand launch state.

Typedefs

typedef void * cion_server_h
 The Cion server handle.
typedef bool(* cion_server_connected_peer_info_cb )(const cion_peer_info_h peer_info, void *user_data)
 Called to get the connected peer information.
typedef void(* cion_server_connection_result_cb )(const char *service_name, const cion_peer_info_h peer_info, const cion_connection_result_h result, void *user_data)
 Called when the connection is accepted or rejected.
typedef void(* cion_server_payload_async_result_cb )(const cion_payload_async_result_h result, void *user_data)
 Called after sending payload asynchronously.
typedef void(* cion_server_data_received_cb )(const char *service_name, const cion_peer_info_h peer_info, const unsigned char *data, unsigned int data_size, unsigned char **return_data, unsigned int *return_data_size, void *user_data)
 Called when data is received.
typedef void(* cion_server_payload_received_cb )(const char *service_name, const cion_peer_info_h peer_info, const cion_payload_h payload, cion_payload_transfer_status_e status, void *user_data)
 Called when payload is received.
typedef void(* cion_server_connection_request_cb )(const char *service_name, const cion_peer_info_h peer_info, void *user_data)
 Called when a connection is requested.
typedef void(* cion_server_disconnected_cb )(const char *service_name, const cion_peer_info_h peer_info, void *user_data)
 Called when a peer disconnects.

Typedef Documentation

typedef bool(* cion_server_connected_peer_info_cb)(const cion_peer_info_h peer_info, void *user_data)

Called to get the connected peer information.

Since :
6.5
Parameters:
[in]peer_infoThe Cion peer information handle
The peer_info can be used only in the callback. To use outside, make a copy.
[in]user_dataThe user data
Returns:
true to continue with the next iteration of the loop, otherwise false to break out of the loop.
See also:
cion_server_foreach_connected_peer_info()
cion_peer_info_h
typedef void(* cion_server_connection_request_cb)(const char *service_name, const cion_peer_info_h peer_info, void *user_data)

Called when a connection is requested.

Since :
6.5
Parameters:
[in]service_nameThe name of service
The service_name can be used only in the callback. To use outside, make a copy.
[in]peer_infoThe Cion peer information handle
The peer_info can be used only in the callback. To use outside, make a copy.
[in]user_dataThe user data
See also:
cion_server_listen()
cion_peer_info_h
typedef void(* cion_server_connection_result_cb)(const char *service_name, const cion_peer_info_h peer_info, const cion_connection_result_h result, void *user_data)

Called when the connection is accepted or rejected.

Since :
6.5
Parameters:
[in]service_nameThe name of service
The service_name can be used only in the callback. To use outside, make a copy.
[in]peer_infoThe Cion peer information handle
The peer_info can be used only in the callback. To use outside, make a copy.
[in]resultThe handle for connection result
The result can be used only in the callback. To use outside, make a copy.
[in]user_dataThe user data
See also:
cion_server_add_connection_result_cb()
cion_peer_info_h
cion_connection_result_h
typedef void(* cion_server_data_received_cb)(const char *service_name, const cion_peer_info_h peer_info, const unsigned char *data, unsigned int data_size, unsigned char **return_data, unsigned int *return_data_size, void *user_data)

Called when data is received.

Since :
6.5
Remarks:
The server should return reply by setting return_data and return_data_size.
Parameters:
[in]service_nameThe name of service
The service_name can be used only in the callback. To use outside, make a copy.
[in]peer_infoThe Cion peer information handle
The peer_info can be used only in the callback. To use outside, make a copy.
[in]dataThe data
The peer_info can be used only in the callback. To use outside, make a copy.
[in]data_sizeThe size of data
[out]return_dataThe data to return
[out]return_data_sizeThe size of return data
[in]user_dataThe user data
See also:
cion_server_set_data_received_cb()
cion_peer_info_h
typedef void(* cion_server_disconnected_cb)(const char *service_name, const cion_peer_info_h peer_info, void *user_data)

Called when a peer disconnects.

Since :
6.5
Parameters:
[in]service_nameThe name of service
The service_name can be used only in the callback. To use outside, make a copy.
[in]peer_infoThe Cion peer information handle
The peer_info can be used only in the callback. To use outside, make a copy.
[in]user_dataThe user data
See also:
cion_server_add_disconnected_cb()
cion_peer_info_h
typedef void* cion_server_h

The Cion server handle.

Since :
6.5
typedef void(* cion_server_payload_async_result_cb)(const cion_payload_async_result_h result, void *user_data)

Called after sending payload asynchronously.

Since :
6.5
Parameters:
[in]resultThe result of sending payload
The result can be used only in the callback. To use outside, make a copy.
[in]user_dataThe user data
See also:
cion_server_send_payload_async()
cion_payload_async_result_h
typedef void(* cion_server_payload_received_cb)(const char *service_name, const cion_peer_info_h peer_info, const cion_payload_h payload, cion_payload_transfer_status_e status, void *user_data)

Called when payload is received.

Since :
6.5
Parameters:
[in]service_nameThe name of service
The service_name can be used only in the callback. To use outside, make a copy.
[in]peer_infoThe Cion peer information handle
The peer_info can be used only in the callback. To use outside, make a copy.
[in]payloadThe received payload
The payload can be used only in the callback.
The payload should not be released.
[in]statusThe status of transfer
[in]user_dataThe user data
See also:
cion_server_add_payload_received_cb()
cion_peer_info_h
cion_payload_h
cion_payload_transfer_status_e

Function Documentation

int cion_server_accept ( cion_server_h  server,
const cion_peer_info_h  peer_info 
)

Accepts the connection request from a peer.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]peer_infoThe Cion peer information handle
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_accept(server, peer_info);
}

Adds callback function for connection result.

Since :
6.5
Parameters:
[in]serverThe Cion server handle.
[in]cbThe callback function
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_connection_result_cb()
cion_server_remove_connection_result_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_add_connection_result_cb(server,
            _cion_server_connection_result_cb, NULL);
}
int cion_server_add_disconnected_cb ( cion_server_h  server,
cion_server_disconnected_cb  cb,
void *  user_data 
)

Adds callback function for disconnection event.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]cbThe callback function
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_disconnected_cb()
cion_server_remove_disconnected_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_add_disconnected_cb(server,
            _cion_server_disconnected_cb, NULL);
}

Adds callback function to receive payload.

Since :
6.5
Parameters:
[in]serverThe Cion server
[in]cbThe callback function
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_payload_received_cb()
cion_server_remove_payload_received_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_add_payload_received_cb(server,
            _cion_server_payload_received_cb, NULL);
}
int cion_server_create ( cion_server_h server,
const char *  service_name,
const char *  display_name,
cion_security_h  security 
)

Creates the Cion server handle.

The Cion server listens client requests.

Since :
6.5
Remarks:
server must be released using cion_server_destroy().
Max length of service_name including the null terminator is 512.
Parameters:
[out]serverThe Cion server handle
[in]service_nameThe name of service
[in]display_nameThe display name of service
[in]securityThe Cion security handle
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_NOT_SUPPORTEDNot supported
CION_ERROR_INVALID_PARAMETERInvalid parameter
CION_ERROR_OUT_OF_MEMORYOut of memory
CION_ERROR_IO_ERRORIO error
CION_ERROR_INVALID_OPERATIONInvalid operation
CION_ERROR_OPERATION_FAILEDOperation failed
See also:
cion_server_destroy()
cion_security_create()
Sample code:
#include <cion.h>

{
    int ret;

    cion_server_h server = NULL;

    ret = cion_server_create(&server, "myservice", "mydisplayname", NULL);
}

Destroys the Cion server handle.

Since :
6.5
Parameters:
[in]serverThe Cion server handle.
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_create()
Sample code:
#include <cion.h>
{
    int ret;

    ret = cion_server_destroy(server);
}
int cion_server_disconnect ( cion_server_h  server,
cion_peer_info_h  peer_info 
)

Disconnects from a client.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]peer_infoThe Cion peer information handle
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_disconnect(server, peer_info);
}

Gets connected peers information.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]callbackThe callback function
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_connected_peer_info_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_foreach_connected_peer_info(server,
        _cion_server_connected_peer_info_cb, NULL);
}
int cion_server_listen ( cion_server_h  server,
cion_server_connection_request_cb  cb,
void *  user_data 
)

Starts listening to connection requests from clients.

Since :
6.5
Privilege Level:
public
Privilege:
http://tizen.org/privilege/d2d.datasharing
http://tizen.org/privilege/internet
Parameters:
[in]serverThe Cion server handle
[in]cbThe callback function
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_PERMISSION_DENIEDPermission denied
CION_ERROR_INVALID_PARAMETERInvalid parameter
CION_ERROR_ALREADY_IN_PROGRESSAlready in progress
See also:
cion_server_connection_request_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_listen(server, _cion_server_connection_request_cb, NULL);
}
int cion_server_reject ( cion_server_h  server,
const cion_peer_info_h  peer_info,
const char *  reason 
)

Rejects the connection request from a peer.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]peer_infoThe Cion peer information handle
[in]reasonThe reason of reject
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_reject(server, peer_info, "NOT_ALLOWED");
}

Removes callback function for connection result.

Since :
6.5
Parameters:
[in]serverThe Cion server handle.
[in]cbThe callback function
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_connection_result_cb()
cion_server_add_connection_result_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_remove_connection_result_cb(server,
            _cion_server_connection_result_cb);
}

Removes callback function for disconnection event.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]cbThe callback function
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_disconnected_cb()
cion_server_add_disconnected_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_remove_disconnected_cb(server,
            _cion_server_disconnected_cb);
}

Removes callback function to receive payload.

Since :
6.5
Parameters:
[in]serverThe Cion server
[in]cbThe callback function
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_payload_received_cb()
cion_server_add_payload_received_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_remove_payload_received_cb(server,
            _cion_server_payload_received_cb);
}
int cion_server_send_payload_async ( cion_server_h  server,
cion_peer_info_h  peer_info,
cion_payload_h  payload,
cion_server_payload_async_result_cb  cb,
void *  user_data 
)

Sends payload asynchronously.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]peer_infoThe Cion peer information handle
[in]payloadThe payload to send
[in]cbThe callback function for result
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
CION_ERROR_INVALID_OPERATIONInvalid operation
See also:
cion_payload_create()
cion_server_payload_async_result_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_send_payload_async(server, peer_info, payload,
            _cion_server_payload_async_result_cb, NULL);
}
int cion_server_set_data_received_cb ( cion_server_h  server,
cion_server_data_received_cb  cb,
void *  user_data 
)

Sets callback function to receive data.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]cbThe callback function
[in]user_dataThe user data
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_data_received_cb()
cion_server_unset_data_received_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_set_data_received_cb(server,
            _cion_server_data_received_cb, NULL);
}
int cion_server_set_display_name ( cion_server_h  server,
const char *  display_name 
)

Sets the server display name.

The display name is a customized name for server.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
[in]display_nameThe display name
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
CION_ERROR_OUT_OF_MEMORYOut of memory
CION_ERROR_IO_ERRORIO error
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_set_display_name(server, "MyDPName");
}
int cion_server_set_on_demand_launch_enabled ( cion_server_h  server,
bool  enabled 
)

Sets on-demand launch state.

If the on-demand launch state is enabled, the server is launched on demand when the request comes.

Since :
6.5
Privilege Level:
public
Privilege:
http://tizen.org/privilege/d2d.remotelaunch
Parameters:
[in]serverThe Cion server handle
[in]enabledThe enable state
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_PERMISSION_DENIEDPermission denied
CION_ERROR_INVALID_PARAMETERInvalid parameter
CION_ERROR_OUT_OF_MEMORYOut of memory
CION_ERROR_IO_ERRORIO error
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_set_on_demand_launch_enabled(server, true);
}

Stops listening to connection requests from clients.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
CION_ERROR_INVALID_OPERATIONInvalid operation
See also:
cion_server_listen()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_stop(server);
}

Unsets callback function to receive data.

Since :
6.5
Parameters:
[in]serverThe Cion server handle
Returns:
0 on success, otherwise a negative error value
Return values:
CION_ERROR_NONESuccessful
CION_ERROR_INVALID_PARAMETERInvalid parameter
See also:
cion_server_data_received_cb()
cion_server_set_data_received_cb()
Sample code:
#include <cion.h>

{
    int ret;

    ret = cion_server_unset_data_received_cb(server);
}