MCPcopy Create free account
hub / github.com/OpenPrinting/cups / sidechannel_thread

Function sidechannel_thread

backend/usb-libusb.c:1880–2017  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1878 */
1879
1880static void*
1881sidechannel_thread(void *reference)
1882{
1883 cups_sc_command_t command; /* Request command */
1884 cups_sc_status_t status; /* Request/response status */
1885 char data[2048]; /* Request/response data */
1886 int datalen; /* Request/response data size */
1887
1888
1889 (void)reference;
1890
1891 do
1892 {
1893 datalen = sizeof(data);
1894
1895 if (cupsSideChannelRead(&command, &status, data, &datalen, 1.0))
1896 {
1897 if (status == CUPS_SC_STATUS_TIMEOUT)
1898 continue;
1899 else
1900 break;
1901 }
1902
1903 switch (command)
1904 {
1905 case CUPS_SC_CMD_SOFT_RESET: /* Do a soft reset */
1906 fputs("DEBUG: CUPS_SC_CMD_SOFT_RESET received from driver...\n",
1907 stderr);
1908
1909 soft_reset();
1910 cupsSideChannelWrite(command, CUPS_SC_STATUS_OK, NULL, 0, 1.0);
1911 fputs("DEBUG: Returning status CUPS_STATUS_OK with no bytes...\n",
1912 stderr);
1913 break;
1914
1915 case CUPS_SC_CMD_DRAIN_OUTPUT: /* Drain all pending output */
1916 fputs("DEBUG: CUPS_SC_CMD_DRAIN_OUTPUT received from driver...\n",
1917 stderr);
1918
1919 g.drain_output = 1;
1920 pthread_mutex_lock(&g.readwrite_lock_mutex);
1921 if (!g.readwrite_lock)
1922 {
1923 /*
1924 * If main thread is inside select(), assume it has infinite
1925 * timeout and needs to be woken up.
1926 */
1927 if (write(g.wakeup_pipe[1], &data, 1) < 0)
1928 fputs("DEBUG: Error writing to wakeup pipe\n", stderr);
1929 }
1930 pthread_mutex_unlock(&g.readwrite_lock_mutex);
1931 break;
1932
1933 case CUPS_SC_CMD_GET_BIDI: /* Is the connection bidirectional? */
1934 fputs("DEBUG: CUPS_SC_CMD_GET_BIDI received from driver...\n",
1935 stderr);
1936
1937 data[0] = (g.printer->protocol >= 2 ? 1 : 0);

Callers

nothing calls this directly

Calls 4

cupsSideChannelReadFunction · 0.85
cupsSideChannelWriteFunction · 0.85
soft_resetFunction · 0.70
get_device_idFunction · 0.70

Tested by

no test coverage detected