Esempio n. 1
0
G_MODULE_EXPORT void
gnome_scan_module_init (GnomeScanModule *module)
{
	SANE_Status status;
	SANE_Int version;
	/* TODO: version checking */
	status = sane_init(&version, NULL);
	bind_textdomain_codeset("sane-backends","UTF-8");

	g_message (G_STRLOC ": SANE version is %i.%i.%i for GSANE %s",
		   SANE_VERSION_MAJOR(version),
		   SANE_VERSION_MINOR(version),
		   SANE_VERSION_BUILD(version),
		   PACKAGE_VERSION);
	
	if (SANE_VERSION_MAJOR(version) != SANE_CURRENT_MAJOR) {
		g_warning (G_STRLOC ": SANE major version must be %i.",
			   SANE_CURRENT_MAJOR);
		return;
	}
	
	gsane_backend_register (G_TYPE_MODULE (module));
	gsane_scanner_register (G_TYPE_MODULE (module));

	/* GSane option handling */
	gsane_option_manager = gsane_option_manager_new();
	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_BOOL, GSANE_TYPE_OPTION_HANDLER_GENERIC);
	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_INT, GSANE_TYPE_OPTION_HANDLER_GENERIC);
	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_FIXED, GSANE_TYPE_OPTION_HANDLER_GENERIC);
	gsane_option_manager_add_rule_by_type(gsane_option_manager, SANE_TYPE_STRING, GSANE_TYPE_OPTION_HANDLER_GENERIC);
	gsane_option_manager_add_rules_by_name(gsane_option_manager, GSANE_TYPE_OPTION_SOURCE, "source", "doc-source", NULL);
	gsane_option_manager_add_rules_by_name(gsane_option_manager, GSANE_TYPE_OPTION_PRIMARY, "resolution", "mode", NULL);
	gsane_option_manager_add_rules_by_name(gsane_option_manager, GSANE_TYPE_OPTION_AREA, "tl-x", "tl-y", "br-x", "br-y", NULL);
}
Esempio n. 2
0
static void
build_menu(Widget widget, XtPointer clientdata, XtPointer call_data)
{
    WidgetList children,wlist;
    Cardinal nchildren;
    const SANE_Device **list;
    Widget push;
    XmString str;
    char action[256];
    int rc,i;

    /* del old */
    XtVaGetValues(widget,
                  XtNchildren,&children,
                  XtNnumChildren,&nchildren,
                  NULL);
    wlist = malloc(sizeof(Widget*)*nchildren);
    memcpy(wlist,children,sizeof(Widget*)*nchildren);
    for (i = 0; i < nchildren; i++)
        XtDestroyWidget(wlist[i]);
    free(wlist);

    /* create new */
    if (SANE_STATUS_GOOD != (rc = sane_init(NULL,NULL))) {
        fprintf(stderr,"sane_init: %s\n",sane_strstatus(rc));
        goto done;
    }
    sane_get_devices(&list,0);
    if (NULL == list[0])
        goto done;

    for (i = 0; list[i] != NULL; i++) {
        if (debug)
            fprintf(stderr,"sane dev: %s | %s | %s | %s\n",
                    list[i]->name, list[i]->vendor,
                    list[i]->model, list[i]->type);
        str = XmStringGenerate((char*)list[i]->model,
                               NULL, XmMULTIBYTE_TEXT, NULL);
        push = XtVaCreateManagedWidget(list[i]->name,
                                       xmPushButtonWidgetClass,widget,
                                       XmNlabelString,str,
                                       NULL);
        XmStringFree(str);
        sprintf(action,"Scan(%s)",list[i]->name);
        XtAddCallback(push,XmNactivateCallback,action_cb,strdup(action));
    }

done:
    sane_exit();
}
Esempio n. 3
0
void
sane_menu(Widget menu)
{
    Widget submenu;
    int rc;

    if (SANE_STATUS_GOOD != (rc = sane_init(NULL,NULL))) {
        fprintf(stderr,"sane_init: %s\n",sane_strstatus(rc));
        goto done;
    }
    submenu = XmCreatePulldownMenu(menu,"scanM",NULL,0);
    XtVaCreateManagedWidget("scan",xmCascadeButtonWidgetClass,menu,
                            XmNsubMenuId,submenu,NULL);
    XtAddCallback(submenu, XmNmapCallback, build_menu, NULL);

done:
    sane_exit();
}
Esempio n. 4
0
static PyObject *init (PyObject * self, PyObject * args)
{
    SANE_Status st;
    SANE_Int version;

    if (!PyArg_ParseTuple (args, ""))
        raiseError("Invalid arguments.");

    /* XXX Authorization is not yet supported */
    st = sane_init (&version, auth_callback);

    if (st != SANE_STATUS_GOOD)
        return raiseSaneError (st);

    return Py_BuildValue ("iiii", version, SANE_VERSION_MAJOR (version),
                          SANE_VERSION_MINOR (version),
                          SANE_VERSION_BUILD (version));

}
Esempio n. 5
0
/**
 * cd_sane_client_refresh:
 **/
static void
cd_sane_client_refresh (CdMainPrivate *priv)
{
	CdMainDev *tmp;
	const SANE_Device **device_list = NULL;
	gint idx;
	guint i;
	SANE_Status status;

	status = sane_init (NULL, NULL);
	if (status != SANE_STATUS_GOOD) {
		g_warning ("failed to init SANE: %s",
			   sane_strstatus (status));
		goto out;
	}

	/* get scanners on the local server */
	status = sane_get_devices (&device_list, TRUE);
	if (status != SANE_STATUS_GOOD) {
		g_warning ("failed to get devices from SANE: %s",
			   sane_strstatus (status));
		goto out;
	}

	/* nothing */
	if (device_list == NULL || device_list[0] == NULL)
		goto out;

	/* add them */
	for (idx = 0; device_list[idx] != NULL; idx++)
		cd_sane_client_add (priv, device_list[idx]);

	/* remove any that are invalid */
	for (i = 0; i < priv->array->len; i++) {
		tmp = g_ptr_array_index (priv->array, i);
		if (tmp->valid)
			continue;
		cd_sane_client_remove (priv, tmp->device);
	}
out:
	g_main_loop_quit (priv->loop);
}
Esempio n. 6
0
void sane_worker( char *command, char *param ) {

  char *response;

  if( SANE_STATUS_GOOD != sane_init(NULL, NULL) ) {
    o_log( ERROR, "Could not start sane");
  }

  // Get a list of scanners
  if ( command && 0 == strcmp(command, "internalGetScannerList") ) {
    response = internalGetScannerList( param );
  }

  // Get scanner details (attributes)
  else if ( command && 0 == strcmp(command, "internalGetScannerDetails") ) {
    char *deviceid = strtok(o_strdup(param), ","); // device
    char *lang = strtok( NULL, ","); // lang
    response = internalGetScannerDetails( deviceid, lang );
    free( deviceid );
  }

  // Scan a page
  else if ( command && 0 == strcmp(command, "internalDoScanningOperation") ) {
    char *uuid = strtok(o_strdup(param), ","); // uuid
    char *lang = strtok( NULL, ","); // lang
    response = internalDoScanningOperation( uuid, lang );
    free( uuid );
  }

  else {
    o_log( ERROR, "Unknown Command");
    response = o_strdup("ERROR");
  }

  sane_exit();

  // POST RESPONSE ON STDOUT
  printf("%s", response);
  free(response);
}
Esempio n. 7
0
static void*
sane_idainit(FILE *fp, char *filename, unsigned int page, struct ida_image_info *info,
             int thumbnail)
{
    const SANE_Option_Descriptor *opt;
    SANE_Int flags, count;
    struct sane_state *h;
    int rc,i,value,dpi = 0;

    h = malloc(sizeof(*h));
    memset(h,0,sizeof(*h));

    if (SANE_STATUS_GOOD != (rc = sane_init(NULL,NULL))) {
        fprintf(stderr,"sane_init: %s\n",sane_strstatus(rc));
        goto oops;
    }
    if (SANE_STATUS_GOOD != (rc = sane_open(filename,&h->sane))) {
        fprintf(stderr,"sane_open: %s\n",sane_strstatus(rc));
        goto oops;
    }

    /* set options */
    opt = sane_get_option_descriptor(h->sane,0);
    rc = sane_control_option(h->sane, 0, SANE_ACTION_GET_VALUE,
                             &count, &flags);
    for (i = 1; i < count; i++) {
        opt = sane_get_option_descriptor(h->sane,i);
        if (opt->name && 0 == strcmp(opt->name,SANE_NAME_SCAN_TL_X)) {
            value = opt->constraint.range->min;
            sane_control_option(h->sane, i, SANE_ACTION_SET_VALUE,
                                &value, &flags);
        } else if (opt->name && 0 == strcmp(opt->name,SANE_NAME_SCAN_TL_Y)) {
            value = opt->constraint.range->min;
            sane_control_option(h->sane, i, SANE_ACTION_SET_VALUE,
                                &value, &flags);
        } else if (opt->name && 0 == strcmp(opt->name,SANE_NAME_SCAN_BR_X)) {
            value = opt->constraint.range->max;
            sane_control_option(h->sane, i, SANE_ACTION_SET_VALUE,
                                &value, &flags);
        } else if (opt->name && 0 == strcmp(opt->name,SANE_NAME_SCAN_BR_Y)) {
            value = opt->constraint.range->max;
            sane_control_option(h->sane, i, SANE_ACTION_SET_VALUE,
                                &value, &flags);
        } else if (opt->name && 0 == strcmp(opt->name,SANE_NAME_PREVIEW)) {
            value = SANE_FALSE;
            sane_control_option(h->sane, i, SANE_ACTION_SET_VALUE,
                                &value, &flags);
        } else if (opt->cap & SANE_CAP_AUTOMATIC)
            sane_control_option(h->sane, i, SANE_ACTION_SET_AUTO,
                                NULL, &flags);
        if (opt->name && 0 == strcmp(opt->name,SANE_NAME_SCAN_RESOLUTION)) {
            if (sane_res) {
                dpi = sane_res;
                sane_control_option(h->sane, i, SANE_ACTION_SET_VALUE,
                                    &dpi, &flags);
            }
            sane_control_option(h->sane, i, SANE_ACTION_GET_VALUE,
                                &dpi, &flags);
        }
        if (debug)
            dump_desc(h->sane,i,opt);
    }

    if (SANE_STATUS_GOOD != (rc = sane_start(h->sane))) {
        fprintf(stderr,"sane_start: %s\n",sane_strstatus(rc));
        goto oops;
    }
    h->started = 1;

    if (SANE_STATUS_GOOD != (rc = sane_get_parameters(h->sane,&h->parm))) {
        fprintf(stderr,"sane_get_parameters: %s\n",sane_strstatus(rc));
        goto oops;
    }

    if (h->parm.format != SANE_FRAME_GRAY &&
            h->parm.format != SANE_FRAME_RGB) {
        fprintf(stderr,"sane: unsupported frame format (%d)\n",h->parm.format);
        goto oops;
    }
    if (h->parm.depth != 8) {
        fprintf(stderr,"sane: unsupported color depth (%d)\n",h->parm.depth);
        goto oops;
    }
    if (-1 == h->parm.lines) {
        fprintf(stderr,"sane: can't handle unknown image size\n");
        goto oops;
    }

    info->width  = h->parm.pixels_per_line;
    info->height = h->parm.lines;
    if (dpi)
        info->dpi  = dpi;
    h->buf = malloc(h->parm.bytes_per_line * BUF_LINES);
    if (debug)
        fprintf(stderr,"sane: scanning %dx%d %s\n",info->width,info->height,
                (h->parm.format == SANE_FRAME_GRAY) ? "gray" : "color");

    return h;

oops:
    if (h->buf)
        free(h->buf);
    if (h->started)
        sane_cancel(h->sane);
    if (h->sane)
        sane_close(h->sane);
    sane_exit();
    free(h);
    return NULL;
}
Esempio n. 8
0
void
testsane (const char *dev_name)
{
  int hlp, x;
  SANE_Status bla;
  SANE_Int blubb;
  SANE_Handle hand;
  SANE_Parameters pars;
  const SANE_Option_Descriptor *sod;
  const SANE_Device **device_list;
  char buffer[2048];

  bla = sane_init (&blubb, auth_callback);
  fprintf (stderr, "Init : stat=%d ver=%x\nPress Enter to continue...",
	   bla, blubb);
  getchar ();
  if (bla != SANE_STATUS_GOOD)
    return;

  bla = sane_get_devices (&device_list, SANE_FALSE);
  fprintf (stderr, "GetDev : stat=%s\n", sane_strstatus (bla));
  if (bla != SANE_STATUS_GOOD)
    return;

  bla = sane_open (dev_name, &hand);
  fprintf (stderr, "Open : stat=%s hand=%p\n", sane_strstatus (bla), hand);
  if (bla != SANE_STATUS_GOOD)
    return;

  bla = sane_set_io_mode (hand, 0);
  fprintf (stderr, "SetIoMode : stat=%s\n", sane_strstatus (bla));

  for (hlp = 0; hlp < 9999; hlp++)
    {
      sod = sane_get_option_descriptor (hand, hlp);
      if (sod == NULL)
	break;
      fprintf (stderr, "Gopt(%d) : stat=%p\n", hlp, sod);
      fprintf (stderr, "name : %s\n", sod->name);
      fprintf (stderr, "title: %s\n", sod->title);
      fprintf (stderr, "desc : %s\n", sod->desc);

      fprintf (stderr, "type : %d\n", sod->type);
      fprintf (stderr, "unit : %d\n", sod->unit);
      fprintf (stderr, "size : %d\n", sod->size);
      fprintf (stderr, "cap  : %d\n", sod->cap);
      fprintf (stderr, "ctyp : %d\n", sod->constraint_type);
      switch (sod->constraint_type)
	{
	case SANE_CONSTRAINT_NONE:
	  break;
	case SANE_CONSTRAINT_STRING_LIST:
	  fprintf (stderr, "stringlist:\n");
	  break;
	case SANE_CONSTRAINT_WORD_LIST:
	  fprintf (stderr, "wordlist (%d) : ", sod->constraint.word_list[0]);
	  for (x = 1; x <= sod->constraint.word_list[0]; x++)
	    fprintf (stderr, " %d ", sod->constraint.word_list[x]);
	  fprintf (stderr, "\n");
	  break;
	case SANE_CONSTRAINT_RANGE:
	  fprintf (stderr, "range: %d-%d %d \n", sod->constraint.range->min,
		   sod->constraint.range->max, sod->constraint.range->quant);
	  break;
	}
    }

  bla = sane_get_parameters (hand, &pars);
  fprintf (stderr,
	   "Parm : stat=%s form=%d,lf=%d,bpl=%d,pixpl=%d,lin=%d,dep=%d\n",
	   sane_strstatus (bla),
	   pars.format, pars.last_frame,
	   pars.bytes_per_line, pars.pixels_per_line,
	   pars.lines, pars.depth);
  if (bla != SANE_STATUS_GOOD)
    return;

  bla = sane_start (hand);
  fprintf (stderr, "Start : stat=%s\n", sane_strstatus (bla));
  if (bla != SANE_STATUS_GOOD)
    return;

  do
    {
      bla = sane_read (hand, buffer, sizeof (buffer), &blubb);
      /*printf("Read : stat=%s len=%d\n",sane_strstatus (bla),blubb); */
      if (bla != SANE_STATUS_GOOD)
	{
	  if (bla == SANE_STATUS_EOF)
	    break;
	  return;
	}
      fwrite (buffer, 1, blubb, stdout);
    }
  while (1);

  sane_cancel (hand);
  fprintf (stderr, "Cancel.\n");

  sane_close (hand);
  fprintf (stderr, "Close\n");

  for (hlp = 0; hlp < 20; hlp++)
    fprintf (stderr, "STRS %d=%s\n", hlp, sane_strstatus (hlp));

  fprintf (stderr, "Exit.\n");
}