Lines Matching defs:conn_ref
38 typedef void (*cti_internal_callback_t)(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status);
418 cti_event_handler(object_t event, cti_connection_t conn_ref)
421 INFO("[CX%d] (" PUB_S_SRP "): cleanup", conn_ref->serial, conn_ref->command_name);
422 if (conn_ref->callback.reply != NULL) {
423 conn_ref->internal_callback(conn_ref, event, kCTIStatus_Disconnected);
425 INFO("[CX%d] No callback", conn_ref->serial);
427 if (conn_ref->connection != NULL) {
428 INFO("[CX%d] releasing connection %p", conn_ref->serial, conn_ref->connection);
429 xpc_release(conn_ref->connection);
430 conn_ref->connection = NULL;
435 if (conn_ref->connection == NULL) {
437 conn_ref->serial, conn_ref->command_name, "", "", event, "");
442 cti_log_object("cti_event_handler", conn_ref->serial, conn_ref->command_name, "", "", event, "");
443 if (!conn_ref->checked_in) {
464 conn_ref->internal_callback(conn_ref, event, kCTIStatus_UnknownError);
465 INFO("[CX%d] canceling xpc connection %p", conn_ref->serial, conn_ref->connection);
466 xpc_connection_cancel(conn_ref->connection);
467 } else if (conn_ref->property_name != NULL) {
472 conn_ref->serial, conn_ref->command_name, conn_ref->connection);
473 xpc_connection_cancel(conn_ref->connection);
478 conn_ref->serial, conn_ref->command_name, conn_ref->connection);
479 xpc_connection_cancel(conn_ref->connection);
484 xpc_array_set_string(array, XPC_ARRAY_APPEND, conn_ref->property_name);
485 conn_ref->property_name = NULL;
487 conn_ref->serial, conn_ref->command_name, "", "", dict, "");
488 INFO("[CX%d] sending message on connection %p", conn_ref->serial, conn_ref->connection);
489 xpc_connection_send_message_with_reply(conn_ref->connection, dict, conn_ref->client_queue,
491 cti_event_handler(in_event, conn_ref);
498 object_t *message = conn_ref->first_command;
499 conn_ref->first_command = NULL;
501 conn_ref->serial, conn_ref->command_name, "", "", message, "");
502 conn_ref->checked_in = true;
504 INFO("[CX%d] sending message on connection %p", conn_ref->serial, conn_ref->connection);
505 xpc_connection_send_message_with_reply(conn_ref->connection, message, conn_ref->client_queue,
507 cti_event_handler(in_event, conn_ref);
512 conn_ref->internal_callback(conn_ref, event, kCTIStatus_NoError);
515 cti_log_object("cti_event_handler/other", conn_ref->serial, conn_ref->command_name, "", "", event, "");
517 conn_ref->serial, xpc_dictionary_get_string(event, XPC_ERROR_KEY_DESCRIPTION));
518 conn_ref->internal_callback(conn_ref, NULL, kCTIStatus_DaemonNotRunning);
520 INFO("[CX%d] canceling xpc connection %p", conn_ref->serial, conn_ref->connection);
521 xpc_connection_cancel(conn_ref->connection);
536 cti_connection_t conn_ref = debug_calloc(1, sizeof(struct _cti_connection_t), file, line);
538 cti_connection_t conn_ref = calloc(1, sizeof(struct _cti_connection_t));
540 if (conn_ref == NULL) {
544 conn_ref->serial = client_serial_number;
552 RETAIN(conn_ref, cti_connection);
560 conn_ref->command_name = command_name;
561 conn_ref->property_name = property_name;
562 conn_ref->return_property_name = return_property_name;
563 conn_ref->context = context;
564 conn_ref->client_queue = client_queue;
565 conn_ref->callback = app_callback;
566 conn_ref->internal_callback = internal_callback;
567 conn_ref->connection = xpc_connection_create_mach_service(servname, conn_ref->client_queue,
569 INFO("[CX%d] xpc connection: %p", conn_ref->serial, conn_ref->connection);
570 conn_ref->first_command = dict;
573 cti_log_object("init_connection/command", conn_ref->serial, conn_ref->command_name, "", "", dict, "");
575 if (conn_ref->connection == NULL)
577 ERROR("conn_ref/lib_q is NULL");
578 if (conn_ref != NULL) {
579 RELEASE_HERE(conn_ref, cti_connection);
584 RETAIN_HERE(conn_ref, cti_connection); // For the event handler.
585 xpc_connection_set_event_handler(conn_ref->connection, ^(object_t event) { cti_event_handler(event, conn_ref); });
586 xpc_connection_set_finalizer_f(conn_ref->connection, cti_xpc_connection_finalize);
587 xpc_connection_set_context(conn_ref->connection, conn_ref);
588 xpc_connection_resume(conn_ref->connection);
592 snprintf(client_name, sizeof client_name, "%s-%d", srp_name, conn_ref->serial);
599 cti_log_object("init_connection/checkin", conn_ref->serial, conn_ref->command_name, "", "", checkin_command, "");
600 INFO("[CX%d] sending message on connection %p", conn_ref->serial, conn_ref->connection);
601 xpc_connection_send_message_with_reply(conn_ref->connection, checkin_command, conn_ref->client_queue,
602 ^(object_t event) { cti_event_handler(event, conn_ref); });
606 *ref = conn_ref;
626 // Get conn_ref from init_connection()
644 if (errx) // On error init_connection() leaves *conn_ref set to NULL
654 cti_internal_event_reply_callback(cti_connection_t NONNULL conn_ref, object_t __unused reply, cti_status_t status)
657 INFO("[CX%d] conn_ref = %p", conn_ref != NULL ? conn_ref->serial : 0, conn_ref);
658 callback = conn_ref->callback.reply;
660 callback(conn_ref->context, status);
665 cti_internal_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status)
667 cti_internal_event_reply_callback(conn_ref, reply, status);
668 conn_ref->callback.reply = NULL;
669 if (conn_ref->connection != NULL) {
670 INFO("[CX%d] canceling connection %p", conn_ref->serial, conn_ref->connection);
671 xpc_connection_cancel(conn_ref->connection);
673 cti_connection_release(conn_ref);
847 cti_internal_string_event_reply(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
849 cti_string_property_reply_t callback = conn_ref->callback.string_property_reply;
859 ERROR("[CX%d] nonzero result %llu", conn_ref->serial, command_result);
866 if (property_name == NULL || strcmp(property_name, conn_ref->return_property_name)) {
882 ERROR("[CX%d] no eventData dictionary", conn_ref->serial);
888 ERROR("[CX%d] eventData dictionary contains no 'value' key", conn_ref->serial);
893 ERROR("[CX%d] eventData value array has no elements", conn_ref->serial);
897 ERROR("[CX%d] eventData value array has %zd elements", conn_ref->serial, count);
902 ERROR("[CX%d] eventData value array's first element is not a string", conn_ref->serial);
911 callback(conn_ref->context, string_value, status);
917 cti_internal_string_property_reply(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
919 cti_internal_string_event_reply(conn_ref, reply, status_in);
920 conn_ref->callback.reply = NULL;
921 if (conn_ref->connection != NULL) {
922 INFO("[CX%d] canceling connection %p", conn_ref->serial, conn_ref->connection);
923 xpc_connection_cancel(conn_ref->connection);
925 RELEASE_HERE(conn_ref, cti_connection);
1037 cti_internal_state_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
1039 cti_state_reply_t callback = conn_ref->callback.state_reply;
1077 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
1078 callback(conn_ref->context, state, status);
1106 cti_internal_uint64_property_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
1108 cti_uint64_property_reply_t callback = conn_ref->callback.uint64_property_reply;
1117 ERROR("[CX%d] no property value.", conn_ref->serial);
1142 conn_ref->serial, value_string);
1150 callback(conn_ref->context, uint64_val, status);
1192 cti_internal_network_node_type_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
1194 cti_network_node_type_reply_t callback = conn_ref->callback.network_node_type_reply;
1203 ERROR("[CX%d] No node type returned.", conn_ref->serial);
1206 ERROR("[CX%d] node type type is " PUB_S_SRP " instead of string.", conn_ref->serial, value_string);
1233 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
1234 callback(conn_ref->context, network_node_type, status);
1546 cti_internal_service_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
1548 cti_service_reply_t callback = conn_ref->callback.service_reply;
1557 INFO("[CX%d] services array not present in Thread:Services event.", conn_ref->serial);
1564 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
1565 callback(conn_ref->context, vec, status);
1777 cti_internal_prefix_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
1779 cti_prefix_reply_t callback = conn_ref->callback.prefix_reply;
1795 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
1796 callback(conn_ref->context, vec, status);
1798 INFO("[CX%d] Not calling callback.", conn_ref->serial);
2032 cti_internal_offmesh_route_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
2034 cti_offmesh_route_reply_t callback = conn_ref->callback.offmesh_route_reply;
2050 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
2051 callback(conn_ref->context, vec, status);
2053 INFO("[CX%d] Not calling callback for %p", conn_ref->serial, conn_ref);
2194 cti_internal_onmesh_prefix_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
2196 cti_onmesh_prefix_reply_t callback = conn_ref->callback.onmesh_prefix_reply;
2212 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
2213 callback(conn_ref->context, vec, status);
2215 INFO("[CX%d] not calling callback for %p", conn_ref->serial, conn_ref);
2247 cti_internal_rloc16_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
2249 cti_rloc16_reply_t callback = conn_ref->callback.rloc16_reply;
2266 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
2267 callback(conn_ref->context, rloc16, status);
2269 INFO("[CX%d] not calling callback for %p", conn_ref->serial, conn_ref);
2297 cti_internal_wed_reply_callback(cti_connection_t NONNULL conn_ref, object_t reply, cti_status_t status_in)
2299 cti_wed_reply_t callback = conn_ref->callback.wed_reply;
2313 INFO("[CX%d] wed status array not present in wed status event.", conn_ref->serial);
2359 INFO("[CX%d] calling callback for %p", conn_ref->serial, conn_ref);
2360 callback(conn_ref->context, extended_mac, ml_eid, added, status);