James Kuszmaul | 6439136 | 2021-01-17 11:32:00 -0800 | [diff] [blame^] | 1 | #include "parameters.h" |
| 2 | #include <rawrtcdc/data_channel.h> |
| 3 | #include <rawrtcdc/data_channel_parameters.h> |
| 4 | #include <rawrtcc/code.h> |
| 5 | #include <re.h> |
| 6 | |
| 7 | /* |
| 8 | * Get the label from the data channel parameters. |
| 9 | * `*labelp` will be set to a copy of the parameter's label and must be |
| 10 | * unreferenced. |
| 11 | * |
| 12 | * Return `RAWRTC_CODE_NO_VALUE` in case no label has been set. |
| 13 | * Otherwise, `RAWRTC_CODE_SUCCESS` will be returned and `*parameters* |
| 14 | * must be unreferenced. |
| 15 | */ |
| 16 | enum rawrtc_code rawrtc_data_channel_parameters_get_label( |
| 17 | char** const labelp, // de-referenced |
| 18 | struct rawrtc_data_channel_parameters* const parameters) { |
| 19 | // Check arguments |
| 20 | if (!labelp || !parameters) { |
| 21 | return RAWRTC_CODE_INVALID_ARGUMENT; |
| 22 | } |
| 23 | |
| 24 | // Set value |
| 25 | if (parameters->label) { |
| 26 | *labelp = mem_ref(parameters->label); |
| 27 | return RAWRTC_CODE_SUCCESS; |
| 28 | } else { |
| 29 | return RAWRTC_CODE_NO_VALUE; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Get the channel type from the data channel parameters. |
| 35 | */ |
| 36 | enum rawrtc_code rawrtc_data_channel_parameters_get_channel_type( |
| 37 | enum rawrtc_data_channel_type* const channel_typep, // de-referenced |
| 38 | struct rawrtc_data_channel_parameters* const parameters) { |
| 39 | // Check arguments |
| 40 | if (!channel_typep || !parameters) { |
| 41 | return RAWRTC_CODE_INVALID_ARGUMENT; |
| 42 | } |
| 43 | |
| 44 | // Set value |
| 45 | *channel_typep = parameters->channel_type; |
| 46 | return RAWRTC_CODE_SUCCESS; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Get the reliability parameter from the data channel parameters. |
| 51 | * |
| 52 | * Return `RAWRTC_CODE_NO_VALUE` in case the channel type is |
| 53 | * `RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_*`. Otherwise, |
| 54 | * `RAWRTC_CODE_SUCCESS` will be returned. |
| 55 | */ |
| 56 | enum rawrtc_code rawrtc_data_channel_parameters_get_reliability_parameter( |
| 57 | uint32_t* const reliability_parameterp, // de-referenced |
| 58 | struct rawrtc_data_channel_parameters* const parameters) { |
| 59 | // Check arguments |
| 60 | if (!reliability_parameterp || !parameters) { |
| 61 | return RAWRTC_CODE_INVALID_ARGUMENT; |
| 62 | } |
| 63 | |
| 64 | // Set value |
| 65 | switch (parameters->channel_type) { |
| 66 | case RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_ORDERED: |
| 67 | case RAWRTC_DATA_CHANNEL_TYPE_RELIABLE_UNORDERED: |
| 68 | return RAWRTC_CODE_NO_VALUE; |
| 69 | default: |
| 70 | *reliability_parameterp = parameters->reliability_parameter; |
| 71 | return RAWRTC_CODE_SUCCESS; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * Get the protocol from the data channel parameters. |
| 77 | * `*protocolp` will be set to a copy of the parameter's protocol and |
| 78 | * must be unreferenced. |
| 79 | * |
| 80 | * Return `RAWRTC_CODE_NO_VALUE` in case no protocol has been set. |
| 81 | * Otherwise, `RAWRTC_CODE_SUCCESS` will be returned and `*protocolp* |
| 82 | * must be unreferenced. |
| 83 | */ |
| 84 | enum rawrtc_code rawrtc_data_channel_parameters_get_protocol( |
| 85 | char** const protocolp, // de-referenced |
| 86 | struct rawrtc_data_channel_parameters* const parameters) { |
| 87 | // Check arguments |
| 88 | if (!protocolp || !parameters) { |
| 89 | return RAWRTC_CODE_INVALID_ARGUMENT; |
| 90 | } |
| 91 | |
| 92 | // Set value |
| 93 | if (parameters->protocol) { |
| 94 | *protocolp = mem_ref(parameters->protocol); |
| 95 | return RAWRTC_CODE_SUCCESS; |
| 96 | } else { |
| 97 | return RAWRTC_CODE_NO_VALUE; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Get the 'negotiated' flag from the data channel parameters. |
| 103 | */ |
| 104 | enum rawrtc_code rawrtc_data_channel_parameters_get_negotiated( |
| 105 | bool* const negotiatedp, // de-referenced |
| 106 | struct rawrtc_data_channel_parameters* const parameters) { |
| 107 | // Check arguments |
| 108 | if (!negotiatedp || !parameters) { |
| 109 | return RAWRTC_CODE_INVALID_ARGUMENT; |
| 110 | } |
| 111 | |
| 112 | // Set value |
| 113 | *negotiatedp = parameters->negotiated; |
| 114 | return RAWRTC_CODE_SUCCESS; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Get the negotiated id from the data channel parameters. |
| 119 | * |
| 120 | * Return `RAWRTC_CODE_NO_VALUE` in case the 'negotiated' flag is set |
| 121 | * `false`. Otherwise, `RAWRTC_CODE_SUCCESS` will be returned. |
| 122 | */ |
| 123 | enum rawrtc_code rawrtc_data_channel_parameters_get_id( |
| 124 | uint16_t* const idp, // de-referenced |
| 125 | struct rawrtc_data_channel_parameters* const parameters) { |
| 126 | // Check arguments |
| 127 | if (!idp || !parameters) { |
| 128 | return RAWRTC_CODE_INVALID_ARGUMENT; |
| 129 | } |
| 130 | |
| 131 | // Set value |
| 132 | if (parameters->negotiated) { |
| 133 | *idp = parameters->id; |
| 134 | return RAWRTC_CODE_SUCCESS; |
| 135 | } else { |
| 136 | return RAWRTC_CODE_NO_VALUE; |
| 137 | } |
| 138 | } |