1 /* 2 * Side-channel API definitions for CUPS. 3 * 4 * Copyright © 2020-2024 by OpenPrinting. 5 * Copyright © 2007-2019 by Apple Inc. 6 * Copyright © 2006 by Easy Software Products. 7 * 8 * Licensed under Apache License v2.0. See the file "LICENSE" for more information. 9 */ 10 11 #ifndef _CUPS_SIDECHANNEL_H_ 12 # define _CUPS_SIDECHANNEL_H_ 13 14 /* 15 * Include necessary headers... 16 */ 17 18 # include "versioning.h" 19 # include <sys/types.h> 20 # if defined(_WIN32) && !defined(__CUPS_SSIZE_T_DEFINED) 21 # define __CUPS_SSIZE_T_DEFINED 22 # include <stddef.h> 23 /* Windows does not support the ssize_t type, so map it to __int64... */ 24 typedef __int64 ssize_t; /* @private@ */ 25 # endif /* _WIN32 && !__CUPS_SSIZE_T_DEFINED */ 26 27 28 /* 29 * C++ magic... 30 */ 31 32 # ifdef __cplusplus 33 extern "C" { 34 # endif /* __cplusplus */ 35 36 37 /* 38 * Constants... 39 */ 40 41 #define CUPS_SC_FD 4 /* File descriptor for select/poll */ 42 43 44 /* 45 * Enumerations... 46 */ 47 48 enum cups_sc_bidi_e /**** Bidirectional capability values ****/ 49 { 50 CUPS_SC_BIDI_NOT_SUPPORTED = 0, /* Bidirectional I/O is not supported */ 51 CUPS_SC_BIDI_SUPPORTED = 1 /* Bidirectional I/O is supported */ 52 }; 53 typedef enum cups_sc_bidi_e cups_sc_bidi_t; 54 /**** Bidirectional capabilities ****/ 55 56 enum cups_sc_command_e /**** Request command codes ****/ 57 { 58 CUPS_SC_CMD_NONE = 0, /* No command @private@ */ 59 CUPS_SC_CMD_SOFT_RESET = 1, /* Do a soft reset */ 60 CUPS_SC_CMD_DRAIN_OUTPUT = 2, /* Drain all pending output */ 61 CUPS_SC_CMD_GET_BIDI = 3, /* Return bidirectional capabilities */ 62 CUPS_SC_CMD_GET_DEVICE_ID = 4, /* Return the IEEE-1284 device ID */ 63 CUPS_SC_CMD_GET_STATE = 5, /* Return the device state */ 64 CUPS_SC_CMD_SNMP_GET = 6, /* Query an SNMP OID @since CUPS 1.4/macOS 10.6@ */ 65 CUPS_SC_CMD_SNMP_GET_NEXT = 7, /* Query the next SNMP OID @since CUPS 1.4/macOS 10.6@ */ 66 CUPS_SC_CMD_GET_CONNECTED = 8, /* Return whether the backend is "connected" to the printer @since CUPS 1.5/macOS 10.7@ */ 67 CUPS_SC_CMD_MAX /* End of valid values @private@ */ 68 }; 69 typedef enum cups_sc_command_e cups_sc_command_t; 70 /**** Request command codes ****/ 71 72 enum cups_sc_connected_e /**** Connectivity values ****/ 73 { 74 CUPS_SC_NOT_CONNECTED = 0, /* Backend is not "connected" to printer */ 75 CUPS_SC_CONNECTED = 1 /* Backend is "connected" to printer */ 76 }; 77 typedef enum cups_sc_connected_e cups_sc_connected_t; 78 /**** Connectivity values ****/ 79 80 81 enum cups_sc_state_e /**** Printer state bits ****/ 82 { 83 CUPS_SC_STATE_OFFLINE = 0, /* Device is offline */ 84 CUPS_SC_STATE_ONLINE = 1, /* Device is online */ 85 CUPS_SC_STATE_BUSY = 2, /* Device is busy */ 86 CUPS_SC_STATE_ERROR = 4, /* Other error condition */ 87 CUPS_SC_STATE_MEDIA_LOW = 16, /* Paper low condition */ 88 CUPS_SC_STATE_MEDIA_EMPTY = 32, /* Paper out condition */ 89 CUPS_SC_STATE_MARKER_LOW = 64, /* Toner/ink low condition */ 90 CUPS_SC_STATE_MARKER_EMPTY = 128 /* Toner/ink out condition */ 91 }; 92 typedef enum cups_sc_state_e cups_sc_state_t; 93 /**** Printer state bits ****/ 94 95 enum cups_sc_status_e /**** Response status codes ****/ 96 { 97 CUPS_SC_STATUS_NONE, /* No status */ 98 CUPS_SC_STATUS_OK, /* Operation succeeded */ 99 CUPS_SC_STATUS_IO_ERROR, /* An I/O error occurred */ 100 CUPS_SC_STATUS_TIMEOUT, /* The backend did not respond */ 101 CUPS_SC_STATUS_NO_RESPONSE, /* The device did not respond */ 102 CUPS_SC_STATUS_BAD_MESSAGE, /* The command/response message was invalid */ 103 CUPS_SC_STATUS_TOO_BIG, /* Response too big */ 104 CUPS_SC_STATUS_NOT_IMPLEMENTED /* Command not implemented */ 105 }; 106 typedef enum cups_sc_status_e cups_sc_status_t; 107 /**** Response status codes ****/ 108 109 typedef void (*cups_sc_walk_func_t)(const char *oid, const char *data, 110 int datalen, void *context); 111 /**** SNMP walk callback ****/ 112 113 114 /* 115 * Prototypes... 116 */ 117 118 /**** New in CUPS 1.2/macOS 10.5 ****/ 119 extern ssize_t cupsBackChannelRead(char *buffer, size_t bytes, 120 double timeout) _CUPS_API_1_2; 121 extern ssize_t cupsBackChannelWrite(const char *buffer, size_t bytes, 122 double timeout) _CUPS_API_1_2; 123 124 /**** New in CUPS 1.3/macOS 10.5 ****/ 125 extern cups_sc_status_t cupsSideChannelDoRequest(cups_sc_command_t command, 126 char *data, int *datalen, 127 double timeout) _CUPS_API_1_3; 128 extern int cupsSideChannelRead(cups_sc_command_t *command, 129 cups_sc_status_t *status, 130 char *data, int *datalen, 131 double timeout) _CUPS_API_1_3; 132 extern int cupsSideChannelWrite(cups_sc_command_t command, 133 cups_sc_status_t status, 134 const char *data, int datalen, 135 double timeout) _CUPS_API_1_3; 136 137 /**** New in CUPS 1.4/macOS 10.6 ****/ 138 extern cups_sc_status_t cupsSideChannelSNMPGet(const char *oid, char *data, 139 int *datalen, double timeout) 140 _CUPS_API_1_4; 141 extern cups_sc_status_t cupsSideChannelSNMPWalk(const char *oid, double timeout, 142 cups_sc_walk_func_t cb, 143 void *context) _CUPS_API_1_4; 144 145 146 # ifdef __cplusplus 147 } 148 # endif /* __cplusplus */ 149 150 #endif /* !_CUPS_SIDECHANNEL_H_ */ 151