1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 /*============================================================================= 19 @file sns_client.h 20 21 Client library for SEE communication via QSockets or QMI. 22 23 ===========================================================================*/ 24 25 /*============================================================================= 26 Include Files 27 ===========================================================================*/ 28 #include "sns_client.pb.h" 29 30 /*============================================================================= 31 Type Definitions 32 ===========================================================================*/ 33 34 struct sns_client; 35 36 /** 37 * Indication callback function. 38 * 39 * @param[i] msg Encoded message of type sns_client_event_msg 40 */ 41 typedef void (*sns_client_ind)(struct sns_client *client, void *msg, 42 uint32_t msg_len, void *cb_data); 43 44 /** 45 * Response callback function. 46 * 47 * @param[i] error Error code as received from service 48 */ 49 typedef void (*sns_client_resp)(struct sns_client *client, sns_std_error error, 50 void *cb_data); 51 52 /** 53 * Error callback function. 54 * 55 * @param[i] msg Encoded message of type sns_client_event_msg 56 */ 57 typedef void (*sns_client_error)(struct sns_client *client, sns_std_error error, 58 void *cb_data); 59 60 /*============================================================================= 61 Public Function Definitions 62 ===========================================================================*/ 63 64 /** 65 * Initialize a new client connection to the service. 66 * 67 * @return 68 * 0 - Success 69 * -1 - Unable to find service 70 * -2 - Maximum client count reached 71 */ 72 int sns_client_init(struct sns_client **client, uint32_t timeout, 73 sns_client_ind ind_cb, void *ind_cb_data, 74 sns_client_error error_cb, void *error_cb_data); 75 76 /** 77 * Deinitialize an existing client connection. Blocking function. 78 * No response or indication callbacks will be received after function returns. 79 * 80 * @return 0 upon success; <0 upon error 81 */ 82 int sns_client_deinit(struct sns_client *client); 83 84 /** 85 * Send a request on the client connection. 86 * 87 * @return 88 * 0 - Success 89 * -1 - Encoding failure 90 * -2 - Transport layer failure 91 */ 92 int sns_client_send(struct sns_client *client, sns_client_request_msg *msg, 93 sns_client_resp resp_cb, void *resp_cb_data);