Exemplo n.º 1
0
/*  Make sure client closed down the device. */
int device_cleanup(mud_session *ps)
{
   int i, dd=1;

   if(!ps->device[dd].index)
      return 0;          /* nothing to do */

   BUG("device_cleanup: device uri=%s\n", ps->device[dd].uri);

   for (i=0; i<HPMUD_CHANNEL_MAX; i++)
   {
      if (ps->device[dd].channel[i].client_cnt)
      {
         BUG("device_cleanup: close channel %d...\n", i);
         hpmud_close_channel(dd, ps->device[dd].channel[i].index);
         BUG("device_cleanup: done closing channel %d\n", i);
      }
   }

   BUG("device_cleanup: close device dd=%d...\n", dd);
   hpmud_close_device(dd);
   BUG("device_cleanup: done closing device dd=%d\n", dd);

   return 0;
}
Exemplo n.º 2
0
SANE_Status __attribute__ ((visibility ("hidden"))) ledm_open(SANE_String_Const device, SANE_Handle *handle)
{
  struct hpmud_model_attributes ma;
  int stat = SANE_STATUS_IO_ERROR;

  if(session)
  {
    return SANE_STATUS_DEVICE_BUSY;
  }
  if((session = create_session()) == NULL)
    return SANE_STATUS_NO_MEM;

  /* Set session to specified device. */
  snprintf(session->uri, sizeof(session->uri)-1, "hp:%s", device);   /* prepend "hp:" */

  /* Get actual model attributes from models.dat. */
  hpmud_query_model(session->uri, &ma);
  session->scan_type = ma.scantype;

  if (hpmud_open_device(session->uri, ma.mfp_mode, &session->dd) != HPMUD_R_OK)
  {
    stat = SANE_STATUS_IO_ERROR;
    goto bugout;
  }

  init_options(session);

  if (bb_open(session))
  {
    stat = SANE_STATUS_IO_ERROR;
    goto bugout;
  }

  /* Set supported Scan Modes as determined by bb_open. */
   ledm_control_option(session, LEDM_OPTION_SCAN_MODE, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  /* Set scan input sources as determined by bb_open. */
   ledm_control_option(session, LEDM_OPTION_INPUT_SOURCE, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  /* Set supported resolutions. */
  ledm_control_option(session, LEDM_OPTION_SCAN_RESOLUTION, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  /* Set supported contrast. */
  ledm_control_option(session, LEDM_OPTION_CONTRAST, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  /* Set supported compression. (Note, cm1017 may say it supports MMR, but it doesn't) */
  ledm_control_option(session, LEDM_OPTION_COMPRESSION, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  /* Determine supported jpeg quality factor as determined by bb_open. */
  ledm_control_option(session, LEDM_OPTION_JPEG_QUALITY, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  /* Set x,y extents. See bb_open */
  ledm_control_option(session, LEDM_OPTION_TL_X, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */
  ledm_control_option(session, LEDM_OPTION_TL_Y, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */
  ledm_control_option(session, LEDM_OPTION_BR_X, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */
  ledm_control_option(session, LEDM_OPTION_BR_Y, SANE_ACTION_SET_AUTO, NULL, NULL); /* set default option */

  *handle = (SANE_Handle *)session;

  stat = SANE_STATUS_GOOD;

bugout:

   if (stat != SANE_STATUS_GOOD)
   {
      if (session)
      {
         bb_close(session);
         if (session->cd > 0)
            hpmud_close_channel(session->dd, session->cd);
         if (session->dd > 0)
            hpmud_close_device(session->dd);
         free(session);
         session = NULL;
      }
   }

   return stat;
}