pict
Documentation for pict is still a work-in-progress
 
Loading...
Searching...
No Matches
libpict.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <pthread.h>
#include "ptp.h"
#include <unistd.h>
#include "cl_data.h"
#include "cl_backend.h"
#include "cl_ops.h"
#include "cl_enum.h"
#include "cl_bind.h"

Go to the source code of this file.

Classes

struct  PtpPropAvail
 Linked list to handle currently possible values for a property. More...
 
struct  PtpRuntime
 Represents a single device connection. More...
 
struct  PtpGenericEvent
 Generic event / property change. More...
 
struct  PtpEventReader
 Stream reader state struct for struct PtpGenericEvent. More...
 
struct  PtpCommand
 Generic PTP command structure - accepted by operation API. More...
 
struct  PtpArray
 Generic Struct for arrays. More...
 

Macros

#define PTP_TIMEOUT   1000
 
#define PTP_WAIT_MS   1000
 
#define PTP_SLEEP(ms)
 
#define PUB
 
#define PTP_DEFAULT_SIZE   1000000
 

Enumerations

enum  PtpGeneralError {
  PTP_OK = 0 , PTP_NO_DEVICE = -1 , PTP_NO_PERM = -2 , PTP_OPEN_FAIL = -3 ,
  PTP_OUT_OF_MEM = -4 , PTP_IO_ERR = -5 , PTP_RUNTIME_ERR = -6 , PTP_UNSUPPORTED = -7 ,
  PTP_CHECK_CODE = -8 , PTP_CANCELED = -9 , PTP_COMMAND_IGNORED = -10
}
 Library errors, not PTP return codes. More...
 
enum  PtpVendors {
  PTP_DEV_EMPTY = 0 , PTP_DEV_EOS = 1 , PTP_DEV_CANON = 2 , PTP_DEV_NIKON = 3 ,
  PTP_DEV_SONY = 4 , PTP_DEV_FUJI = 5 , PTP_DEV_PANASONIC = 6
}
 Unique camera types - each type should have similar opcodes and behavior. More...
 
enum  ImageFormats {
  IMG_FORMAT_ETC = 0 , IMG_FORMAT_RAW = 1 , IMG_FORMAT_STD = 2 , IMG_FORMAT_HIGH = 3 ,
  IMG_FORMAT_RAW_JPEG = 4
}
 
enum  PtpConnType { PTP_IP = (1 << 0) , PTP_IP_USB = (1 << 1) , PTP_USB = (1 << 2) , PTP_BLE = (1 << 3) }
 Tells lib what backend and packet style to use. More...
 

Functions

PUB void ptp_verbose_log (char *fmt,...)
 Verbose log debugging info, could be called dozens of times per second.
 
PUB void ptp_error_log (char *fmt,...)
 Used for critical IO errors, (not runtime errors)
 
PUB __attribute__ ((noreturn)) void ptp_panic(char *fmt
 Client has no way out, crash the application.
 
PUB void ptp_report_read_progress (unsigned int size)
 Update UI progress on download progress.
 
const char * ptp_perror (int rc)
 Evaluates PtpGeneralError into string message.
 
PUB int ptp_get_return_code (struct PtpRuntime *r)
 Returns the return code (RC) currently in the data buffer.
 
PUB unsigned int ptp_get_param_length (struct PtpRuntime *r)
 Get number of parameters in packet in data buffer.
 
PUB uint32_t ptp_get_param (struct PtpRuntime *r, int i)
 Get parameter at index i.
 
PUB int ptp_get_last_transaction_id (struct PtpRuntime *r)
 Get transaction ID of packet in the data buffer.
 
PUB uint8_t * ptp_get_payload (struct PtpRuntime *r)
 Get ptr of packet payload in data buffer, after packet header.
 
PUB unsigned int ptp_get_payload_length (struct PtpRuntime *r)
 Get length of payload returned by ptp_get_payload.
 
PUB struct PtpRuntimeptp_new (int options)
 Allocate new PtpRuntime based on bitfield options - see PtpConnType.
 
PUB void ptp_reset (struct PtpRuntime *r)
 Reset all session-specific fields of PtpRuntime - both libusb and libwpd backends call this before establishing connection, so calling this is not required.
 
PUB void ptp_init (struct PtpRuntime *r)
 Init PtpRuntime locally - uses default recommended settings (USB)
 
PUB void ptp_close (struct PtpRuntime *r)
 Frees PtpRuntime data buffer - doesn't free the actual structure, or device info (yet)
 
PUB int ptp_send (struct PtpRuntime *r, struct PtpCommand *cmd)
 Send a command request to the device with no data phase.
 
PUB int ptp_send_data (struct PtpRuntime *r, const struct PtpCommand *cmd, const void *data, unsigned int length)
 Send a command request to the device with a data phase (thread safe)
 
PUB int ptp_get_event (struct PtpRuntime *r, struct PtpEventContainer *ec)
 Try and get an event from the camera over int endpoint (USB-only)
 
PUB void ptp_mutex_unlock (struct PtpRuntime *r)
 Unlock the IO mutex (unless it was kept locked)
 
PUB void ptp_mutex_unlock_thread (struct PtpRuntime *r)
 Completely unlock the mutex for the current thread, to ensure there isn't a deadlock. This is normally used on handling errors, and when exiting a thread.
 
PUB void ptp_mutex_lock (struct PtpRuntime *r)
 Lock the IO mutex - only should be used by backend.
 
PUB int ptp_device_type (struct PtpRuntime *r)
 Gets type of device from r->di.
 
PUB int ptp_check_opcode (struct PtpRuntime *r, int opcode)
 Check if an opcode is supported by looking through supported props in r->di.
 
PUB int ptp_check_prop (struct PtpRuntime *r, int code)
 Check if a property code is supported by looking through supported props in r->di.
 
PUB int ptp_buffer_resize (struct PtpRuntime *r, size_t size)
 Mostly for internal use - realloc the data buffer.
 
PUB int ptp_write_unicode_string (char *dat, const char *string)
 
PUB int ptp_read_unicode_string (char *buffer, const char *dat, int max)
 
PUB int ptp_read_utf8_string (void *dat, char *string, int max)
 
PUB int ptp_read_string (uint8_t *dat, char *string, int max)
 
PUB int ptp_write_string (uint8_t *dat, const char *string)
 
PUB int ptp_write_utf8_string (void *dat, const char *string)
 
PUB int ptp_read_uint16_array (const uint8_t *dat, uint16_t *buf, int max, int *length)
 
PUB int ptp_read_uint16_array_s (uint8_t *bs, uint8_t *be, uint16_t *buf, int max, int *length)
 
unsigned int ptp_new_cmd_packet (struct PtpRuntime *r, const struct PtpCommand *cmd)
 
int ptpusb_new_data_packet (struct PtpRuntime *r, const struct PtpCommand *cmd, const void *data, unsigned int data_length)
 
unsigned int ptpip_data_start_packet (struct PtpRuntime *r, unsigned int data_length)
 
unsigned int ptpip_data_end_packet (struct PtpRuntime *r, const void *data, unsigned int data_length)
 
 __attribute__ ((deprecated)) void ptp_update_transaction(struct PtpRuntime *r
 
void ptp_set_prop_avail_info (struct PtpRuntime *r, int code, unsigned int memb_size, unsigned int cnt, void *data)
 
int ptp_dump (struct PtpRuntime *r)
 Write r->data to a file called DUMP.
 

Variables

int t
 

Macro Definition Documentation

◆ PTP_DEFAULT_SIZE

#define PTP_DEFAULT_SIZE   1000000

Definition at line 32 of file libpict.h.

◆ PTP_SLEEP

#define PTP_SLEEP ( ms)
Value:
usleep((unsigned int)(ms) * 1000)

Definition at line 22 of file libpict.h.

◆ PTP_TIMEOUT

#define PTP_TIMEOUT   1000

Definition at line 13 of file libpict.h.

◆ PTP_WAIT_MS

#define PTP_WAIT_MS   1000

Definition at line 16 of file libpict.h.

◆ PUB

#define PUB

Definition at line 28 of file libpict.h.

Enumeration Type Documentation

◆ ImageFormats

enum ImageFormats

Definition at line 85 of file libpict.h.

◆ PtpConnType

Tells lib what backend and packet style to use.

Note
This is a bitmask so that it can be passed to ptp_new with other options.

Definition at line 95 of file libpict.h.

◆ PtpGeneralError

Library errors, not PTP return codes.

Enumerator
PTP_NO_DEVICE 

No device found (USB)

PTP_NO_PERM 

EPERM or other permission denied error.

PTP_OPEN_FAIL 

Found device, but failed to connect.

PTP_OUT_OF_MEM 

malloc failed

PTP_IO_ERR 

General IO or communication error.

PTP_RUNTIME_ERR 

Unexpected, unhandled, or illegal behavior.

PTP_UNSUPPORTED 

Operation or functionality isn't implemented or supported.

PTP_CHECK_CODE 

response code is not PTP_RC_OK

PTP_CANCELED 

Operation (such as download) was canceled by another thread.

PTP_COMMAND_IGNORED 

No response.

Note
Used internally only

Definition at line 45 of file libpict.h.

◆ PtpVendors

enum PtpVendors

Unique camera types - each type should have similar opcodes and behavior.

Definition at line 74 of file libpict.h.

Function Documentation

◆ ptp_buffer_resize()

PUB int ptp_buffer_resize ( struct PtpRuntime * r,
size_t size )

Mostly for internal use - realloc the data buffer.

Note
r->data will be reassigned, any old references must be updated

◆ ptp_check_opcode()

PUB int ptp_check_opcode ( struct PtpRuntime * r,
int opcode )

Check if an opcode is supported by looking through supported props in r->di.

Returns
1 if yes, 0 if no

◆ ptp_check_prop()

PUB int ptp_check_prop ( struct PtpRuntime * r,
int code )

Check if a property code is supported by looking through supported props in r->di.

Returns
1 if yes, 0 if no

◆ ptp_device_type()

PUB int ptp_device_type ( struct PtpRuntime * r)

Gets type of device from r->di.

Returns
enum PtpDeviceType

◆ ptp_dump()

int ptp_dump ( struct PtpRuntime * r)

Write r->data to a file called DUMP.

Note
Debugging only

◆ ptp_get_last_transaction_id()

PUB int ptp_get_last_transaction_id ( struct PtpRuntime * r)

Get transaction ID of packet in the data buffer.

Note
Not thread safe.

◆ ptp_get_param()

PUB uint32_t ptp_get_param ( struct PtpRuntime * r,
int i )

Get parameter at index i.

Note
Not thread safe.

◆ ptp_get_param_length()

PUB unsigned int ptp_get_param_length ( struct PtpRuntime * r)

Get number of parameters in packet in data buffer.

Note
Not thread safe.

◆ ptp_get_payload()

PUB uint8_t * ptp_get_payload ( struct PtpRuntime * r)

Get ptr of packet payload in data buffer, after packet header.

Note
Not thread safe.

◆ ptp_get_payload_length()

PUB unsigned int ptp_get_payload_length ( struct PtpRuntime * r)

Get length of payload returned by ptp_get_payload.

Note
Not thread safe.

◆ ptp_get_return_code()

PUB int ptp_get_return_code ( struct PtpRuntime * r)

Returns the return code (RC) currently in the data buffer.

Note
Not thread safe.

Variable Documentation

◆ t

int t

Definition at line 341 of file libpict.h.