/** * Reads a file partially from the #Camera. * * @param camera a #Camera * @param folder a folder * @param file the name of a file * @param type the #CameraFileType * @param offset the offset into the camera file * @param data the buffer receiving the data * @param size the size to be read and that was read * @param context a #GPContext * @return a gphoto2 error code * **/ int gp_camera_file_read (Camera *camera, const char *folder, const char *file, CameraFileType type, uint64_t offset, char *buf, uint64_t *size, GPContext *context) { GP_LOG_D ("Getting file '%s' in folder '%s'...", file, folder); C_PARAMS (camera && folder && file && buf && size); CHECK_INIT (camera, context); /* Did we get reasonable foldername/filename? */ if (strlen (folder) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_DIRECTORY_NOT_FOUND); } if (strlen (file) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_FILE_NOT_FOUND); } CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_read_file (camera->fs, folder, file, type, offset, buf, size, context), context); CAMERA_UNUSED (camera, context); return (GP_OK); }
/** * Captures a preview that won't be stored on the camera but returned in * supplied file. * * @param camera a #Camera * @param file a #CameraFile * @param context a #GPContext * @return a gphoto2 error code * * For example, you could use gp_capture_preview() for taking some sample * pictures before calling gp_capture(). * **/ int gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context) { char *xname; C_PARAMS (camera && file); CHECK_INIT (camera, context); CR (camera, gp_file_clean (file), context); if (!camera->functions->capture_preview) { gp_context_error (context, _("This camera can " "not capture previews.")); CAMERA_UNUSED (camera, context); return (GP_ERROR_NOT_SUPPORTED); } CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture_preview ( camera, file, context), context); gp_file_get_name_by_type (file, "capture_preview", GP_FILE_TYPE_NORMAL, &xname); /* FIXME: Marcus ... will go away, just keep compatible now. */ gp_file_set_name (file, xname); free (xname); CAMERA_UNUSED (camera, context); return (GP_OK); }
/** * \brief Check for intterupt. * * \param port a GPPort * \param data a pointer to an allocated buffer * \param size the number of bytes that should be read * * Reads a specified number of bytes from the interrupt endpoint * into the supplied buffer. * Function waits port->timeout miliseconds for data on interrupt endpoint. * * \return a gphoto2 error code **/ int gp_port_check_int (GPPort *port, char *data, int size) { int retval; gp_log (GP_LOG_DEBUG, "gphoto2-port", ngettext( "Reading %i=0x%x byte from interrupt endpoint...", "Reading %i=0x%x bytes from interrupt endpoint...", size), size, size); CHECK_NULL (port); CHECK_INIT (port); /* Check if we read as many bytes as expected */ CHECK_SUPP (port, "check_int", port->pc->ops->check_int); retval = port->pc->ops->check_int (port, data, size, port->timeout); CHECK_RESULT (retval); if (retval != size) gp_log (GP_LOG_DEBUG, "gphoto2-port", _("Could only read %i " "out of %i byte(s)"), retval, size); gp_log_data ("gphoto2-port", data, retval); return (retval); }
static html_valid_status_t html_valid_set_option (html_valid_t * htv, SV * option, SV * value) { TidyOption to; TidyOptionType tot; TidyOptionId ti; const char * coption; STRLEN coption_length; CHECK_INIT (htv); coption = SvPV (option, coption_length); to = tidyGetOptionByName(htv->tdoc, coption); if (to == 0) { warn ("unknown option %s", coption); return html_valid_unknown_option; } ti = tidyOptGetId (to); tot = tidyOptGetType (to); switch (tot) { case TidyString: CALL (set_string_option (htv, coption, ti, value)); break; case TidyInteger: CALL (set_number_option (htv, coption, ti, value)); break; case TidyBoolean: tidyOptSetBool (htv->tdoc, ti, SvTRUE (value)); break; default: fprintf (stderr, "%s:%d: bad option type %d from tidy library.\n", __FILE__, __LINE__, tot); return html_valid_bad_option_type; } return html_valid_ok; }
/** * \brief Check for interrupt without wait * \param port a GPPort * \param data a pointer to an allocated buffer * \param size the number of bytes that should be read * * Reads a specified number of bytes from the inerrupt endpoint * into the supplied buffer. * Function waits 50 miliseconds for data on interrupt endpoint. * * \return a gphoto2 error code **/ int gp_port_check_int_fast (GPPort *port, char *data, int size) { int retval; gp_log (GP_LOG_DATA, __func__, "Reading %i = 0x%x bytes from interrupt endpoint...", size, size); C_PARAMS (port); CHECK_INIT (port); /* Check if we read as many bytes as expected */ CHECK_SUPP (port, "check_int", port->pc->ops->check_int); retval = port->pc->ops->check_int (port, data, size, FAST_TIMEOUT); CHECK_RESULT (retval); #ifdef IGNORE_EMPTY_INTR_READS /* For Canon cameras, we will make lots of reads that will return zero length. Don't bother to log them as errors. */ if (retval != 0 ) #endif LOG_DATA (data, retval, size, "Read ", "from interrupt endpoint (fast):"); return (retval); }
int32_t PrioQueueTop(PrioQueue *self, Item *pItem) { CHECK_INIT(self); BinHeap *pHeap = self->pData->pHeap_; int32_t iRtnCode = pHeap->top(pHeap, pItem); return iRtnCode; }
FILE * _DEFUN_VOID (tmpfile) { int ret; FILE* fp; struct _reent *ptr = _REENT; CHECK_INIT(ptr); fp = __sfp(ptr); if (!fp) { return NULL; } ret = __send_to_ppe(SPE_C99_SIGNALCODE, SPE_C99_TMPFILE, &ret); if (ret) { fp->_fp = ret; return fp; } else { __sfp_free(fp); return NULL; } }
/** * @brief Formats input of a stdarg argument list. * * @details The function is equivalent to fscanf() except that * instead of being called with a variable number of arguments, * is called with an argument list as defined in the <stdarg.h> header. * * @return Returns the same value of fscanf(). */ int VFSCANF(register FILE *fp, const char *fmt, va_list ap) { struct _reent *reent = _REENT; CHECK_INIT(reent, fp); return __SVFSCANF_R (reent, fp, fmt, ap); }
/** * Retrieves a file from the #Camera. * * @param camera a #Camera * @param folder a folder * @param file the name of a file * @param type the #CameraFileType * @param camera_file a #CameraFile * @param context a #GPContext * @return a gphoto2 error code * **/ int gp_camera_file_get (Camera *camera, const char *folder, const char *file, CameraFileType type, CameraFile *camera_file, GPContext *context) { gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Getting file '%s' in " "folder '%s'...", file, folder); CHECK_NULL (camera && folder && file && camera_file); CHECK_INIT (camera, context); CR (camera, gp_file_clean (camera_file), context); /* Did we get reasonable foldername/filename? */ if (strlen (folder) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_DIRECTORY_NOT_FOUND); } if (strlen (file) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_FILE_NOT_FOUND); } CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_get_file (camera->fs, folder, file, type, camera_file, context), context); CAMERA_UNUSED (camera, context); return (GP_OK); }
int32_t PrioQueueSetCompare(PrioQueue *self, int32_t (*pFunc) (Item, Item)) { CHECK_INIT(self); BinHeap *pHeap = self->pData->pHeap_; int32_t iRtnCode = pHeap->set_compare(pHeap, pFunc); return iRtnCode; }
// Minimizes (but does not destroy) the window void Window::Minimize() { CHECK_INIT(); if(!CloseWindow(hwnd())) throw WIN32EXCEPTION_1("CloseWindow"); }
int32_t PrioQueueSetDestroy(PrioQueue *self, void (*pFunc) (Item)) { CHECK_INIT(self); BinHeap *pHeap = self->pData->pHeap_; int32_t iRtnCode = pHeap->set_destroy(pHeap, pFunc); return iRtnCode; }
/** * Retrieves information about a file. * * @param camera a #Camera * @param folder a folder * @param file the name of the file * @param info * @param context a #GPContext * @return a gphoto2 error code * **/ int gp_camera_file_get_info (Camera *camera, const char *folder, const char *file, CameraFileInfo *info, GPContext *context) { int result = GP_OK; const char *mime_type; const char *data; /* long int size; */ CameraFile *cfile; gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Getting file info for '%s' " "in '%s'...", file, folder); CHECK_NULL (camera && folder && file && info); CHECK_INIT (camera, context); memset (info, 0, sizeof (CameraFileInfo)); /* Check first if the camera driver supports the filesystem */ CHECK_OPEN (camera, context); result = gp_filesystem_get_info (camera->fs, folder, file, info, context); CHECK_CLOSE (camera, context); if (result != GP_ERROR_NOT_SUPPORTED) { CAMERA_UNUSED (camera, context); return (result); } /* * The CameraFilesystem doesn't support file info. We simply get * the preview and the file and look for ourselves... */ /* It takes too long to get the file */ info->file.fields = GP_FILE_INFO_NONE; /* Get the preview */ info->preview.fields = GP_FILE_INFO_NONE; CRS (camera, gp_file_new (&cfile), context); if (gp_camera_file_get (camera, folder, file, GP_FILE_TYPE_PREVIEW, cfile, context) == GP_OK) { unsigned long size; info->preview.fields |= GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE; gp_file_get_data_and_size (cfile, &data, &size); info->preview.size = size; gp_file_get_mime_type (cfile, &mime_type); strncpy (info->preview.type, mime_type, sizeof (info->preview.type)); } gp_file_unref (cfile); /* We don't trust the camera libraries */ info->file.fields |= GP_FILE_INFO_NAME; strncpy (info->file.name, file, sizeof (info->file.name)); info->preview.fields &= ~GP_FILE_INFO_NAME; CAMERA_UNUSED (camera, context); return (GP_OK); }
void Window::Move(int x, int y) { CHECK_INIT(); if(!MoveWindow(hwnd(), x, y, width(), height(), TRUE)) throw WIN32EXCEPTION_1("MoveWindow"); }
/** * \brief Send a USB interface control message with input data * * \param port a GPPort * \param request control request code * \param value control value * \param index control index * \param bytes pointer to data * \param size size of the data * * Sends a specific USB control command and read associated data. * * \return a gphoto2 error code */ int gp_port_usb_msg_interface_read (GPPort *port, int request, int value, int index, char *bytes, int size) { int retval; gp_log (GP_LOG_DEBUG, "gphoto2-port", "Reading message " "(request=0x%x value=0x%x index=0x%x size=%i=0x%x)...", request, value, index, size, size); CHECK_NULL (port); CHECK_INIT (port); CHECK_SUPP (port, "msg_read", port->pc->ops->msg_interface_read); retval = port->pc->ops->msg_interface_read (port, request, value, index, bytes, size); CHECK_RESULT (retval); if (retval != size) gp_log (GP_LOG_DEBUG, "gphoto2-port", "Could only read %i " "out of %i byte(s)", retval, size); gp_log_data ("gphoto2-port", bytes, retval); return (retval); }
void _perror_r (struct _reent *ptr, const char *s) { char *error; int dummy; FILE *fp = _stderr_r (ptr); CHECK_INIT (ptr, fp); _newlib_flockfile_start(fp); _fflush_r (ptr, fp); if (s != NULL && *s != '\0') { WRITE_STR (s); WRITE_STR (": "); } if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL) WRITE_STR (error); #ifdef __SCLE WRITE_STR ((fp->_flags & __SCLE) ? "\r\n" : "\n"); #else WRITE_STR ("\n"); #endif fp->_flags &= ~__SOFF; _newlib_flockfile_end(fp); }
int32_t PrioQueueSize(PrioQueue *self) { CHECK_INIT(self); BinHeap *pHeap = self->pData->pHeap_; int32_t iSize = pHeap->size(pHeap); return iSize; }
void ImageWindow::unsetCaptionRect() { CHECK_INIT(); _captionRectUsed = false; ZeroMemory(&_captionRect, sizeof(RECT)); }
int32_t PrioQueuePop(PrioQueue *self, bool bClean) { CHECK_INIT(self); BinHeap *pHeap = self->pData->pHeap_; int32_t iRtnCode = pHeap->pop(pHeap, bClean); return iRtnCode; }
int32_t PrioQueuePush(PrioQueue *self, Item item) { CHECK_INIT(self); BinHeap *pHeap = self->pData->pHeap_; int32_t iRtnCode = pHeap->push(pHeap, item); return iRtnCode; }
ZEND_API int _zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag ZEND_FILE_LINE_DC) { uint nIndex; Bucket *p; #ifdef ZEND_SIGNALS TSRMLS_FETCH(); #endif IS_CONSISTENT(ht); CHECK_INIT(ht); if (flag & HASH_NEXT_INSERT) { h = ht->nNextFreeElement; } nIndex = h & ht->nTableMask; p = ht->arBuckets[nIndex]; while (p != NULL) { if ((p->nKeyLength == 0) && (p->h == h)) { if (flag & HASH_NEXT_INSERT || flag & HASH_ADD) { return FAILURE; } ZEND_ASSERT(p->pData != pData); HANDLE_BLOCK_INTERRUPTIONS(); if (ht->pDestructor) { ht->pDestructor(p->pData); } UPDATE_DATA(ht, p, pData, nDataSize); HANDLE_UNBLOCK_INTERRUPTIONS(); if (pDest) { *pDest = p->pData; } return SUCCESS; } p = p->pNext; } p = (Bucket *) pemalloc_rel(sizeof(Bucket), ht->persistent); p->arKey = NULL; p->nKeyLength = 0; /* Numeric indices are marked by making the nKeyLength == 0 */ p->h = h; INIT_DATA(ht, p, pData, nDataSize); if (pDest) { *pDest = p->pData; } CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[nIndex]); HANDLE_BLOCK_INTERRUPTIONS(); ht->arBuckets[nIndex] = p; CONNECT_TO_GLOBAL_DLLIST(p, ht); HANDLE_UNBLOCK_INTERRUPTIONS(); if ((long)h >= (long)ht->nNextFreeElement) { ht->nNextFreeElement = h < LONG_MAX ? h + 1 : LONG_MAX; } ht->nNumOfElements++; ZEND_HASH_IF_FULL_DO_RESIZE(ht); return SUCCESS; }
static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_string *key, zval *pData, uint32_t flag ZEND_FILE_LINE_DC) { zend_ulong h; uint32_t nIndex; uint32_t idx; Bucket *p; IS_CONSISTENT(ht); if (UNEXPECTED(ht->nTableMask == 0)) { CHECK_INIT(ht, 0); goto add_to_hash; } else if (ht->u.flags & HASH_FLAG_PACKED) { zend_hash_packed_to_hash(ht); } else if ((flag & HASH_ADD_NEW) == 0) { p = zend_hash_find_bucket(ht, key); if (p) { zval *data; if (flag & HASH_ADD) { return NULL; } ZEND_ASSERT(&p->val != pData); data = &p->val; if ((flag & HASH_UPDATE_INDIRECT) && Z_TYPE_P(data) == IS_INDIRECT) { data = Z_INDIRECT_P(data); } HANDLE_BLOCK_INTERRUPTIONS(); if (ht->pDestructor) { ht->pDestructor(data); } ZVAL_COPY_VALUE(data, pData); HANDLE_UNBLOCK_INTERRUPTIONS(); return data; } } ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */ add_to_hash: HANDLE_BLOCK_INTERRUPTIONS(); idx = ht->nNumUsed++; ht->nNumOfElements++; if (ht->nInternalPointer == INVALID_IDX) { ht->nInternalPointer = idx; } p = ht->arData + idx; p->h = h = zend_string_hash_val(key); p->key = key; zend_string_addref(key); ZVAL_COPY_VALUE(&p->val, pData); nIndex = h & ht->nTableMask; Z_NEXT(p->val) = ht->arHash[nIndex]; ht->arHash[nIndex] = idx; HANDLE_UNBLOCK_INTERRUPTIONS(); return &p->val; }
wint_t fputwc (wchar_t wc, FILE *fp) { struct _reent *reent = _REENT; CHECK_INIT(reent, fp); return _fputwc_r (reent, wc, fp); }
/** * \brief Send a SCSI command to a port (for usb scsi ports) * * \param port a #GPPort * \param to_dev data direction, set to 1 for a scsi cmd which sends * data to the device, set to 0 for cmds which read data from the dev. * \param cmd buffer holding the command to send * \param cmd_size sizeof cmd buffer * \param sense buffer for returning scsi sense information * \param sense_size sizeof sense buffer * \param data buffer containing informatino to write to the device * (to_dev is 1), or to store data read from the device (to_dev 0). * * Send a SCSI command to a usb scsi port attached device. * * \return a gphoto2 error code **/ int gp_port_send_scsi_cmd (GPPort *port, int to_dev, char *cmd, int cmd_size, char *sense, int sense_size, char *data, int data_size) { int retval; gp_log (GP_LOG_DEBUG, "gphoto2-port", "Sending scsi cmd:"); gp_log_data ("gphoto2-port", cmd, cmd_size); if (to_dev && data_size) { gp_log (GP_LOG_DEBUG, "gphoto2-port", "scsi cmd data:"); gp_log_data ("gphoto2-port", data, data_size); } CHECK_NULL (port); CHECK_INIT (port); memset (sense, 0, sense_size); CHECK_SUPP (port, "send_scsi_cmd", port->pc->ops->send_scsi_cmd); retval = port->pc->ops->send_scsi_cmd (port, to_dev, cmd, cmd_size, sense, sense_size, data, data_size); gp_log (GP_LOG_DEBUG, "gphoto2-port", "scsi cmd result: %d", retval); if (sense[0] != 0) { gp_log (GP_LOG_DEBUG, "gphoto2-port", "sense data:"); gp_log_data ("gphoto2-port", sense, sense_size); /* https://secure.wikimedia.org/wikipedia/en/wiki/Key_Code_Qualifier */ gp_log(GP_LOG_DEBUG, "gphoto2-port","sense decided:"); if ((sense[0]&0x7f)!=0x70) { gp_log(GP_LOG_DEBUG, "gphoto2-port","\tInvalid header."); } gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tCurrent command read filemark: %s",(sense[2]&0x80)?"yes":"no"); gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tEarly warning passed: %s",(sense[2]&0x40)?"yes":"no"); gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tIncorrect blocklengt: %s",(sense[2]&0x20)?"yes":"no"); gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tSense Key: %d",sense[2]&0xf); if (sense[0]&0x80) gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tResidual Length: %d",sense[3]*0x1000000+sense[4]*0x10000+sense[5]*0x100+sense[6]); gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tAdditional Sense Length: %d",sense[7]); gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tAdditional Sense Code: %d",sense[12]); gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tAdditional Sense Code Qualifier: %d",sense[13]); if (sense[15]&0x80) { gp_log(GP_LOG_DEBUG, "gphoto2-port", "\tIllegal Param is in %s",(sense[15]&0x40)?"the CDB":"the Data Out Phase"); if (sense[15]&0x8) { gp_log(GP_LOG_DEBUG, "gphoto2-port", "Pointer at %d, bit %d",sense[16]*256+sense[17],sense[15]&0x7); } } } if (!to_dev && data_size) { gp_log (GP_LOG_DEBUG, "gphoto2-port", "scsi cmd data:"); gp_log_data ("gphoto2-port", data, data_size); } return retval; }
// Show window void Window::Show() { CHECK_INIT(); if(parentHwnd()) { EnableWindow(parentHwnd(), FALSE); } ShowWindow(hwnd(), SW_SHOW); }
// Set text for window caption void Window::setCaption(LPCTSTR str) { CHECK_INIT(); if(!str) throw INVALID_ARGUMENT_EXCEPTION_1("str"); if(!SetWindowText(_hwnd, str)) throw WIN32EXCEPTION_1("SetWindowText"); }
void Window::getRect(LPRECT rect) const { CHECK_INIT(); if(!rect) throw INVALID_ARGUMENT_EXCEPTION_1("rect"); if(!GetWindowRect(hwnd(), rect)) throw WIN32EXCEPTION_1("GetWindowRect"); }
void Window::Resize(int width, int height) { CHECK_INIT(); RECT rect; getRect(&rect); if(!MoveWindow(hwnd(), rect.left/*x*/, rect.top/*y*/, width, height, TRUE)) throw WIN32EXCEPTION_1("MoveWindow"); }
int ferror (FILE * fp) { int result; CHECK_INIT(_REENT, fp); _newlib_flockfile_start (fp); result = __sferror (fp); _newlib_flockfile_end (fp); return result; }
// Hide window void Window::Hide() { CHECK_INIT(); ShowWindow(hwnd(), SW_HIDE); if(parentHwnd()) { EnableWindow(parentHwnd(), TRUE); SetFocus(parentHwnd()); } }