photoController::~photoController() 
{
	dumpPhotoMemory();
	if(camera_detected == true)
		gp_camera_exit(camera, context);
	gp_camera_unref(camera);
}
Exemple #2
0
Camera::~Camera() {
    std::lock_guard<std::mutex> g(mutex);
	gp_context_unref(ctx->context);
	
	if (camera)
		gp_camera_unref(camera); // XXX: freeing also exits it, i guess
}
CAMLprim
value caml_gp_camera_unref(value cam_val) {
  CAMLparam1(cam_val);
  Camera *cam = Camera_val(cam_val);
  gp_camera_unref(cam);
  CAMLreturn(Val_unit);
}
Exemple #4
0
static void
gtkam_camera_finalize (GObject *object)
{
	GtkamCamera *c = GTKAM_CAMERA (object);

	if (c->camera) {
		gp_camera_unref (c->camera);
		c->camera = NULL;
	}

	G_OBJECT_CLASS (parent_class)->finalize (object);
}
void Image_GPhoto::releaseCamera(GPhotoCamera& camera)
{
    lock_guard<recursive_mutex> lock(_gpMutex);

    gp_camera_exit(camera.cam, _gpContext);
    if (camera.cam != nullptr)
        gp_camera_unref(camera.cam);
    if (camera.configuration != nullptr)
        gp_widget_unref(camera.configuration);

    camera.cam = nullptr;
    camera.configuration = nullptr;
}
Exemple #6
0
void cleanup(void *arg)
{
	int value = 0;

	// TODO check to see if we have already cleaned up?

	IPRINT("PTP2 capture - Cleaning up\n");
	camera_set("capture", &value);
	gp_camera_exit(camera, context);
	gp_camera_unref(camera);
	gp_context_unref(context);
	free(global->in[plugin_id].buf);
}
int releaseCamera(Camera **c, GPContext *ctx)
{
	int result = GP_OK;
	if (!(*c))
		return GP_ERROR;
	if ((result = gp_camera_exit ((*c), ctx)) != GP_OK)
		return result;
	if ((result = gp_camera_unref ((*c))) != GP_OK)
		return result;
	// if ((result = gp_camera_free ((*c)) != GP_OK)
	// 	return result;
	*c = NULL;
	return GP_OK;
}
Exemple #8
0
static void
gnocam_camera_finalize (GObject *object)
{
	GnoCamCamera *gc = GNOCAM_CAMERA (object);

	if (gc->priv) {
		if (gc->camera) {
			gp_camera_unref (gc->camera);
			gc->camera = NULL;
		}
		g_free (gc->priv);
		gc->priv = NULL;
	}

	G_OBJECT_CLASS (parent_class)->finalize (object);
}
Exemple #9
0
GPCamera::~GPCamera()
{
#ifdef HAVE_GPHOTO2
    if (d->status)
    {
        gp_context_unref(d->status->context);
        d->status = 0;
    }

    if (d->camera)
    {
        gp_camera_unref(d->camera);
        d->camera = 0;
    }

#endif /* HAVE_GPHOTO2 */

    delete d;
}
bool photoController::initCamera()
{
	gp_camera_new (&camera);
	DEBUG_PRINTF(V_MESSAGE, "Camera initialization (gp_camera_init).\n");
	int retval = gp_camera_init(camera, context);
	if (retval != GP_OK) 
	{
		DEBUG_PRINTF(V_WARNING, "Could not detect any camera!\n");
		camera_detected = false;        
		gp_camera_unref(camera);
		camera = NULL;
		// TODO - Retry camera initialization, if fails, signalize with led (and TCP message?).
	}
	else
	{
		DEBUG_PRINTF(V_MESSAGE, "Camera detected!\n");
		camera_detected = true;
		setPhotoQuality();
	}
	return camera_detected;
}
Exemple #11
0
void
gp_params_exit (GPParams *p)
{
	if (!p)
		return;

	if (p->_abilities_list)
		gp_abilities_list_free (p->_abilities_list);
	if (p->camera)
		gp_camera_unref (p->camera);
	if (p->folder)
		free (p->folder);
	if (p->filename)
		free (p->filename);
	if (p->context)
		gp_context_unref (p->context);
	if (p->hook_script)
		free (p->hook_script);
	if (p->portinfo_list)
		gp_port_info_list_free (p->portinfo_list);
	memset (p, 0, sizeof (GPParams));
}
Exemple #12
0
/**
 * Close connection to the camera. Remove all unread frames/files.
 */
void DigitalCameraCapture::close()
{
    try
    {
        if (!frame.empty())
        {
            frame.release();
        }
        if (camera)
        {
            CR(gp_camera_exit(camera, context));
            CR(gp_camera_unref(camera));
            camera = NULL;
        }
        opened = false;
        if (int frames = grabbedFrames.size() > 0)
        {
            while (frames--)
            {
                CameraFile * file = grabbedFrames.front();
                grabbedFrames.pop_front();
                CR(gp_file_unref(file));
            }
        }
        if (rootWidget)
        {
            widgetInfo.clear();
            CR(gp_widget_unref(rootWidget));
            rootWidget = NULL;
        }
    }
    catch (GPhoto2Exception & e)
    {
        message(ERROR, "cannot close device properly", e);
    }
}
Exemple #13
0
static GnoCamCamera *
gnocam_main_get_camera (GnoCamMain *gm, const gchar *model, const gchar *port,
		        CORBA_Environment *ev)
{
	Camera *camera;
	GnoCamCamera *gc = NULL;

	g_message ("Trying to get a camera for model '%s' (port '%s')...",
		   model, port);

	g_return_val_if_fail (GNOCAM_IS_MAIN (gm), NULL);

	gc = gnocam_cache_lookup (gm->priv->cache, model, port);
	if (gc) {
		bonobo_object_ref (gc);
		return gc;
	}

	CR (gp_camera_new (&camera), ev);
	if (BONOBO_EX (ev))
		return (CORBA_OBJECT_NIL);

	if (model && strlen (model)) {
		CameraAbilities a;
		CameraAbilitiesList *al = NULL;
		int m;

	        memset (&a, 0, sizeof (CameraAbilities));
	        gp_abilities_list_new (&al);
	        gp_abilities_list_load (al, NULL);
	        m = gp_abilities_list_lookup_model (al, model);
	        gp_abilities_list_get_abilities (al, m, &a);
	        gp_abilities_list_free (al);
		CR (gp_camera_set_abilities (camera, a), ev);
		if (BONOBO_EX (ev)) {
			gp_camera_unref (camera);
			return NULL;
		}
	}

	if (port && strlen (port)) {
		GPPortInfo info;
		GPPortInfoList *il = NULL;
		int p;

		memset (&info, 0, sizeof (GPPortInfo));
		gp_port_info_list_new (&il);
		gp_port_info_list_load (il);
		p = gp_port_info_list_lookup_name (il, port);
		if (p < 0)
			p = gp_port_info_list_lookup_path (il, port);
		gp_port_info_list_get_info (il, p, &info);
		gp_port_info_list_free (il);
		CR (gp_camera_set_port_info (camera, info), ev); 
		if (BONOBO_EX (ev)) { 
			gp_camera_unref (camera);
			return (CORBA_OBJECT_NIL);
		}
	}

        CR (gp_camera_init (camera, NULL), ev);
        if (BONOBO_EX (ev)) {
                gp_camera_unref (camera); 
                return NULL;
        }

        gc = gnocam_camera_new (camera, ev);
        gp_camera_unref (camera);
        if (BONOBO_EX (ev))
                return NULL;

	gnocam_cache_add (gm->priv->cache, gc);

        g_message ("Successfully created a camera.");

	return gc;
}
Exemple #14
0
int
main (int argc, char **argv)
{
    fd_set rs;
    struct timeval tv;
    int n, cmd_len;
    char cmd[PATH_MAX + 32];
    const char *arg;
    GFParams params;

    memset (&params, 0, sizeof (GFParams));
    if (gp_camera_new (&(params.camera)) < 0)
        goto ExitError;
    if (gp_abilities_list_new (&(params.al)) < 0)
        goto ExitError;
    if (gp_abilities_list_load (params.al, NULL) < 0)
        goto ExitError;
    if (gp_port_info_list_new (&params.il) < 0)
        goto ExitError;
    if (gp_port_info_list_load (params.il) < 0)
        goto ExitError;
    params.folder = malloc (strlen ("/") + 1);
    if (!params.folder)
        goto ExitError;
    strcpy (params.folder, "/");
    params.idletime = 1800;

    n = sizeof (struct sockaddr_in);
    if (getsockname (0, (struct sockaddr *) &params.sai_sock, &n)) {
        fprintf (stdout, "421 Can not get name of sock.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = sizeof (struct sockaddr_in);
    if (getpeername (0, (struct sockaddr *) &params.sai_peer, &n)) {
        fprintf (stdout, "421 Can not get name of peer.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = IPTOS_LOWDELAY;
    setsockopt (0, IPPROTO_IP, IP_TOS, (char *) &n, sizeof (int));

    fprintf (stdout, "220-Hello and welcome to the wonderful world\r\n");
    fprintf (stdout, "220-of gphoto!\r\n");
    fprintf (stdout, "220-\r\n");
    fprintf (stdout, "220-Use this server like a standard FTP-Server.\r\n");
    fprintf (stdout, "220-List files in virtual directory\r\n");
    fflush (stdout);
    fprintf (stdout, "220-'/capture-image' in order to capture\r\n");
    fflush (stdout);
    fprintf (stdout, "220-an image, in '/capture-preview' in order\r\n");
    fflush (stdout);
    fprintf (stdout, "220-to capture a preview.\r\n");
    fflush (stdout);
    fprintf (stdout, "220 FTP server ready.\r\n");
    fflush (stdout);

    while (1) {

        /* Read something. */
        syslog (LOG_INFO, "Reading...");
        FD_ZERO (&rs);
        tv.tv_sec = 1800;
        tv.tv_usec = 0;
        memset (cmd, 0, sizeof (cmd));
        cmd_len = n = 0;
        while (1) {
            if (!n) {
                FD_SET (0, &rs);
                select (1, &rs, NULL, NULL, &tv);
                if (ioctl (0, FIONREAD, &n) < 0)
                    n = 0;
            }
            if (FD_ISSET (0, &rs)) {
                if (read (0, cmd + cmd_len, 1) <= 0)
                    goto ExitError;
                if (n)
                    n--;
                if (cmd[cmd_len] == '\n') {
                    cmd[cmd_len + 1] = '\0';
                    break;
                }
                if (cmd_len < sizeof (cmd) - 2)
                    cmd_len++;
            } else
                goto ExitError;
        }

        syslog (LOG_INFO, "Got '%s'...", cmd);
        for (n = 0; isalpha (cmd[n]) && n < sizeof (cmd); n++)
            cmd[n] = tolower (cmd[n]);
        if (!n) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            goto ExitOk;
        }
        while (isspace (cmd[n]) && n < sizeof (cmd))
            cmd[n++] = '\0';
        arg = cmd + n;
        while (cmd[n] && n < sizeof (cmd))
            n++;
        n--;
        while (isspace (cmd[n]))
            cmd[n--] = '\0';
        syslog (LOG_INFO, "Processing '%s' - '%s'...", cmd, arg);
        if (!strcasecmp (cmd, "cwd")) {
            gf_cwd (&params, arg);
        } else if (!strcasecmp (cmd, "list")) {
            if (gf_list (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "noop")) {
            fprintf (stdout, "200 NOOP command successful.\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "pass")) {
            if (gf_pass (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pasv")) {
            gf_pasv (&params);
        } else if (!strcasecmp (cmd, "port")) {
            if (gf_port (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pwd") ||
                   !strcasecmp (cmd, "xpwd")) {
            fprintf (stdout, "257 \"%s\"\r\n", params.folder);
            fflush (stdout);
        } else if (!strcasecmp (cmd, "quit")) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            syslog (LOG_INFO, "Quit.");
            return (0);
        } else if (!strcasecmp (cmd, "retr")) {
            if (gf_retr (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "syst")) {
            printf ("215 UNIX Type: L8\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "type")) {
            if (!arg)
                goto ExitError;
            gf_type (&params, *arg);
        } else if (!strcasecmp (cmd, "user")) {
            if (gf_user (&params, arg) < 0)
                goto ExitError;
        } else {
            syslog (LOG_INFO, "Command '%s'...", cmd);
            printf ("%3d %s\r\n", 550, "Unknown command.");
            fflush (stdout);
        }
    }

ExitError:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    syslog (LOG_INFO, "Error: 1");
    return (1);

ExitOk:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    return (0);
}
Exemple #15
0
static GtkamCamera *
gtkam_chooser_get_camera (GtkamChooser *chooser)
{
	GtkWidget *dialog, *status;
	GPPortInfo info;
	Camera *camera;
	CameraAbilities abilities;
	const gchar *model, *port, *speed;
	gchar *port_path, *right, *tmp;
	int m, p, r;
	gboolean multi;
	GtkamCamera *c;

	model = gtk_entry_get_text (chooser->priv->entry_model);
	port  = gtk_entry_get_text (chooser->priv->entry_port);
	speed = gtk_entry_get_text (chooser->priv->entry_speed);
	multi = GTK_TOGGLE_BUTTON (chooser->priv->check_multi)->active;

	if (!port || !*port)
		port_path = g_strdup (_("None"));
	else {
		port_path = g_strdup (port);
		right = strrchr (port_path, ')');
		*right = '\0';
		tmp = g_strdup (strrchr (port_path, '(') + 1);
		g_free (port_path);
		port_path = tmp;
	}

	gp_camera_new (&camera);
#ifdef HAVE_GP_CAMERA_SET_TIMEOUT_FUNCS
	gp_camera_set_timeout_funcs (camera, start_timeout_func,
				     stop_timeout_func, NULL);
#endif

	/* Model? */
	m = gp_abilities_list_lookup_model (chooser->priv->al, model);
	gp_abilities_list_get_abilities (chooser->priv->al, m, &abilities);
	gp_camera_set_abilities (camera, abilities);

	/* Port? */
	if (strcmp (port_path, _("None"))) {
		p = gp_port_info_list_lookup_path (chooser->priv->il,
						   port_path);
		gp_port_info_list_get_info (chooser->priv->il, p, &info);
		gp_camera_set_port_info (camera, info);
	}

	/* Speed? */
	if (strcmp (speed, _("Best")))
		gp_camera_set_port_speed (camera, atoi (speed));

	/*
	 * Initialize the camera to check if it is really there. Exit
	 * afterwards because other applications could need the camera, too.
	 */
	status = gtkam_status_new (_("Initializing camera..."));
	gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status);
	r = gp_camera_init (camera, GTKAM_STATUS (status)->context->context);
	if (multi)
		gp_camera_exit (camera, NULL);
	switch (r) {
	case GP_OK:
		break;
	case GP_ERROR_CANCEL:
		g_free (port_path);
		break;
	default:
		g_free (port_path);
		dialog = gtkam_error_new (r, GTKAM_STATUS (status)->context,
			NULL, _("Could not initialize camera."));
		gtk_window_set_transient_for (GTK_WINDOW (dialog),
					      GTK_WINDOW (chooser));
		gtk_widget_show (dialog);
		gp_camera_unref (camera);
		camera = NULL;
	}
	gtk_object_destroy (GTK_OBJECT (status));

	c = gtkam_camera_new (camera, multi);
	gp_camera_unref (camera);

	return (c);
}
Exemple #16
0
photo_camera::~photo_camera( void )
{
  gp_camera_unref( camera_ ); //delete camera_;
  gp_context_unref( context_ ); //delete context_;
}
Exemple #17
0
int main (int argc, char** argv)
{
      std::cout<<"GP_OK = "<<GP_OK<<std::endl;

      GPContext *currentContext = NULL;
      gp_context_new();

      Camera *camera=NULL;
      gp_camera_new (&camera);
      gp_camera_init (camera, currentContext);

      CameraAbilitiesList * abilitiesList;
      CameraAbilities  abilities;
      CameraAbilities * ptr_abilities;
      ptr_abilities = &abilities;
      int haveListAbilities = gp_abilities_list_get_abilities (abilitiesList, 0, ptr_abilities);
      std::cout<<"haveListAbilities : "<< haveListAbilities<<std::endl;

     /* int haveAbilities = gp_camera_set_abilities(camera, abilities);
      std::cout<<"haveAbilities : "<< haveAbilities<<std::endl;*/

/*      //in case camera driver can't figure out the current camera's speed
      //gp_camera_set_port_path or name => pas TROUVE
      int speed; //AURA BESOIN D4UNE VALEUR (???)
      int hasSpeed = gp_camera_set_port_speed (camera, speed);
*/



      //to know port's camera
      GPPortInfo info;
      GPPortInfo * ptr_info;
      ptr_info = &info;
     /* int infoSetted = gp_camera_set_port_info (camera, info);
      std::cout<<"infoSetted : "<< infoSetted<<std::endl;*/


      ///
      int infoGetted = gp_camera_get_port_info(camera, ptr_info);
      std::cout<<"infoGetted : "<< infoGetted<<std::endl;


      //To have a window with camera's config
      CameraWidget ** widget;
      CameraWidgetType type;
      const char *label;
      int widgetCreated = gp_widget_new (type, label, widget);
      std::cout<<"widgetCreated : "<< widgetCreated<<std::endl;

      //get config
      int configGetted = gp_camera_get_config (camera, widget, currentContext);
      std::cout<<"configGetted : "<< configGetted<<std::endl;

      //set the configuration's camera
//      int cameraSetted = gp_camera_set_config (camera, *widget, currentContext);
//      std::cout<<"cameraSetted : "<< cameraSetted<<std::endl;


      //HAVE TO FIND FUNCTION WHICH GET/SET THE PÄTH
      CameraFilePath * path;
      //IDEM
      CameraCaptureType typeCapture;
      CameraFileType typeFile; //mm type à priori
      //capture
      int captured = gp_camera_capture (camera, typeCapture, path, currentContext);
      std::cout<<"captured : "<< captured<<std::endl;

      //To get capture from camera to computer
      //folder on computer
      //TO COMPLETE
      const char *folder = "../pictures";
      //TO COMPLETE
      //(devra être renseigné en fonction du numéro de la photoprécédente par ex)
      const char *file = "picture001";

      //??
      CameraFile * camera_file;
      int captureGetted = gp_camera_file_get(camera, folder, file, typeFile,camera_file, currentContext);
      std::cout<<"captureGetted : "<< captureGetted<<std::endl;


      int indiceCountCamera = gp_camera_unref (camera);



        //Before the end of using camera => better!
        int cameraExited = gp_camera_exit (camera, currentContext);

        return EXIT_SUCCESS;
}
Exemple #18
0
bool GPCamera::doConnect()
{
#ifdef HAVE_GPHOTO2
    int errorCode;

    // -- first step - setup the camera --------------------

    if (d->camera)
    {
        gp_camera_unref(d->camera);
        d->camera = 0;
    }

    CameraAbilitiesList* abilList = 0;
    GPPortInfoList*      infoList = 0;
    GPPortInfo           info;

    gp_camera_new(&d->camera);

    delete d->status;
    d->status = 0;
    d->status = new GPStatus();

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, d->status->context);
    gp_port_info_list_new(&infoList);
    gp_port_info_list_load(infoList);

    int modelNum     = gp_abilities_list_lookup_model(abilList, m_model.toLatin1().constData());
    int portNum      = gp_port_info_list_lookup_path(infoList, m_port.toLatin1().constData());

    gp_abilities_list_get_abilities(abilList, modelNum, &d->cameraAbilities);

    errorCode    = gp_camera_set_abilities(d->camera, d->cameraAbilities);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera Abilities!";
        printGphotoErrorDescription(errorCode);
        gp_camera_unref(d->camera);
        d->camera = 0;
        gp_abilities_list_free(abilList);
        gp_port_info_list_free(infoList);
        return false;
    }

    if (m_model != QLatin1String("Directory Browse"))
    {
        gp_port_info_list_get_info(infoList, portNum, &info);
        errorCode = gp_camera_set_port_info(d->camera, info);

        if (errorCode != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera port!";
            printGphotoErrorDescription(errorCode);
            gp_camera_unref(d->camera);
            d->camera = 0;
            gp_abilities_list_free(abilList);
            gp_port_info_list_free(infoList);
            return false;
        }
    }

    gp_abilities_list_free(abilList);
    gp_port_info_list_free(infoList);

    if (d->cameraAbilities.file_operations &
        GP_FILE_OPERATION_PREVIEW)
    {
        m_thumbnailSupport = true;
    }

    if (d->cameraAbilities.file_operations &
        GP_FILE_OPERATION_DELETE)
    {
        m_deleteSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_PUT_FILE)
    {
        m_uploadSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_MAKE_DIR)
    {
        m_mkDirSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_REMOVE_DIR)
    {
        m_delDirSupport = true;
    }

    if (d->cameraAbilities.operations &
        GP_OPERATION_CAPTURE_IMAGE)
    {
        m_captureImageSupport = true;
    }

    if (d->cameraAbilities.operations &
        GP_OPERATION_CAPTURE_PREVIEW)
    {
        m_captureImagePreviewSupport = true;
    }

    // -- Try and initialize the camera to see if its connected -----------------

    errorCode = gp_camera_init(d->camera, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to initialize camera!";
        printGphotoErrorDescription(errorCode);
        gp_camera_unref(d->camera);
        d->camera = 0;
        return false;
    }

    d->cameraInitialized = true;

    return true;
#else
    return false;
#endif /* HAVE_GPHOTO2 */
}