예제 #1
0
int 
bot_ctrans_get_trans_latest_timestamp(BotCTrans *ctrans, 
        const char *from_frame, const char *to_frame, int64_t *timestamp)
{
    BotCTransPath * path = _get_path(ctrans, from_frame, to_frame);
    if(!path)
        return 0;
    return bot_ctrans_path_latest_timestamp(path, timestamp);
}
예제 #2
0
int 
bot_ctrans_get_trans_latest(BotCTrans *ctrans, const char *from_frame,
        const char *to_frame, BotTrans *result)
{
    BotCTransPath * path = _get_path(ctrans, from_frame, to_frame);
    if(!path)
        return 0;
    return bot_ctrans_path_to_trans_latest(path, result);
}
예제 #3
0
int 
bot_ctrans_have_trans(BotCTrans *ctrans, const char *from_frame,
        const char *to_frame)
{
    BotCTransPath * path = _get_path(ctrans, from_frame, to_frame);
    if(!path) {
        g_warning("%s: invalid transformation requested (%s -> %s)\n", 
                __FUNCTION__, from_frame, to_frame);
        return 0;
    }
    return bot_ctrans_path_have_trans(path);
}
예제 #4
0
파일: directory.c 프로젝트: JohnChu/Snoopy
static int
remove_dir_func (CameraFilesystem *fs, const char *folder, const char *name,
		 void *data, GPContext *context)
{
	char path[2048];
	Camera *camera = (Camera*)data;
	int result;

	result = _get_path (camera->port, folder, name, path, sizeof(path));
	if (result < GP_OK)
		return result;
	return gp_system_rmdir (path);
}
예제 #5
0
파일: directory.c 프로젝트: JohnChu/Snoopy
static int
get_info_func (CameraFilesystem *fs, const char *folder, const char *file,
		      CameraFileInfo *info, void *data, GPContext *context)
{
	char path[1024];
	const char *mime_type;
	struct stat st;
	Camera *camera = (Camera*)data;
	int result;

	gp_log (GP_LOG_DEBUG, "directory/get_info_func", "%s %s", folder, file);
	result = _get_path (camera->port, folder, file, path, sizeof(path));
	if (result < GP_OK)
		return result;

	if (lstat (path, &st) != 0) {
		gp_context_error (context, _("Could not get information "
			"about '%s' in '%s' (%m)."), file, folder);
		return (GP_ERROR);
	}

        info->preview.fields = GP_FILE_INFO_NONE;
        info->file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_NAME |
                            GP_FILE_INFO_TYPE | GP_FILE_INFO_PERMISSIONS |
			    GP_FILE_INFO_MTIME;

	info->file.mtime = st.st_mtime;
	info->file.permissions = GP_FILE_PERM_NONE;
	if (st.st_mode & S_IRUSR)
		info->file.permissions |= GP_FILE_PERM_READ;
	if (st.st_mode & S_IWUSR)
		info->file.permissions |= GP_FILE_PERM_DELETE;
        strcpy (info->file.name, file);
        info->file.size = st.st_size;
	mime_type = get_mime_type (file);
	if (!mime_type)
		mime_type = "application/octet-stream";
	strcpy (info->file.type, mime_type);

        return (GP_OK);
}
예제 #6
0
static void *
_load_plugin_reader(const char  *dl_name,
                    const char  *f_name)
{
  char  *lib_path = NULL;
  void  *dl_lib = NULL;
  static char *env_pkglibdir = NULL;
  const char *pkglibdir = _get_path("lib/" PACKAGE_NAME, PKGLIBDIR,
                                    &env_pkglibdir);

  void * retval = NULL, *error = NULL;

  /* Open from shared library */

  ECS_MALLOC(lib_path,
             strlen(pkglibdir) + 1 + 3 + strlen(dl_name) + 3 + 1,
             char);
  sprintf(lib_path, "%s/%s.so", pkglibdir, dl_name);

  dl_lib = dlopen(lib_path, RTLD_LAZY);

  ECS_FREE(lib_path);

  /* Load symbols from shared library */

  if (dl_lib == NULL)
    ecs_error(__FILE__, __LINE__, 0,
              _("Error loading %s: %s."), lib_path, dlerror());

  dlerror();    /* Clear any existing error */

  retval = dlsym(dl_lib, f_name);

  error = dlerror();

  if (error != NULL)
    ecs_error(__FILE__, __LINE__, 0,
              _("Error calling dlsym: %s\n"), error);

  return retval;
}
예제 #7
0
파일: directory.c 프로젝트: JohnChu/Snoopy
static int
delete_file_func (CameraFilesystem *fs, const char *folder,
		  const char *file, void *data, GPContext *context)
{
	char path[2048];
	int result;
	Camera *camera = (Camera*)data;

	result = _get_path (camera->port, folder, file, path, sizeof(path));
	if (result < GP_OK)
		return result;
	result = unlink (path);
	if (result) {
		gp_context_error (context, _("Could not delete file '%s' "
			"in folder '%s' (error code %i: %m)."),
			file, folder, result);
		return (GP_ERROR);
	}

	return (GP_OK);
}
예제 #8
0
void ResourceManager::LoadShader(const std::string& fileName, std::string& shader_string)
{
	shader_string.clear();

	// Find path of the file - for later use
	std::string path;
	_get_path(fileName, path);

	std::ifstream file;
	file.open(fileName.c_str());

	std::string line;

	if (file.is_open())
	{
		while (file.good())
		{
			std::getline(file, line);
			if (line.find(INCLUDE_KEYWORD) != std::string::npos)
			{
				// Parse included files
				std::vector<std::string> include_file;
				_split_string(line, " ", include_file);

				std::string included_file_string;
				LoadShader(path + include_file[1].substr(1, include_file[1].length() - 2), included_file_string);

				shader_string.append(included_file_string + "\n");
			}
			else
			{
				shader_string.append(line + "\n");
			}
		}
	}
	else
	{
		throw ResourceException("Unable to load shader: " + fileName);
	}
}
예제 #9
0
파일: directory.c 프로젝트: JohnChu/Snoopy
static int
put_file_func (CameraFilesystem *fs, const char *folder,
	       CameraFile *file, void *data, GPContext *context)
{
	char path[2048];
	const char *name;
	int result;
#ifdef DEBUG
	unsigned int i, id;
#endif
	Camera *camera = (Camera*)data;

	gp_file_get_name (file, &name);

	result = _get_path (camera->port, folder, name, path, sizeof(path));
	if (result < GP_OK)
		return result;

	result = gp_file_save (file, path);
	if (result < 0)
		return (result);

#ifdef DEBUG
	id = gp_context_progress_start (context, 500., "Uploading file...");
	for (i = 0; i < 500; i++) {
		gp_context_progress_update (context, id, i + 1);
		gp_context_idle (context);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL)
			return (result);
		usleep (10);
	}
	gp_context_progress_stop (context, id);
#endif

	return (GP_OK);
}
예제 #10
0
파일: directory.c 프로젝트: JohnChu/Snoopy
static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
	       CameraFileType type, CameraFile *file, void *user_data,
	       GPContext *context)
{
        char path[1024];
	int result = GP_OK;
	struct stat stbuf;
	int fd, id;
	unsigned int curread, toread;
	unsigned char *buf;
#ifdef HAVE_LIBEXIF
	ExifData *data;
	unsigned int buf_len;
#endif /* HAVE_LIBEXIF */
	Camera *camera = (Camera*)user_data;

	result = _get_path (camera->port, folder, filename, path, sizeof(path));
	gp_log (GP_LOG_DEBUG, "directory/get_file_func", "%s %s",folder,filename);
	if (result < GP_OK)
		return result;
	gp_log (GP_LOG_DEBUG, "directory/get_file_func", "->%s",path);
	

	switch (type) {
	case GP_FILE_TYPE_NORMAL:
#ifdef DEBUG
	case GP_FILE_TYPE_PREVIEW:
#endif
		fd = open (path,O_RDONLY);
		if (fd == -1)
			return GP_ERROR_IO_READ;
		break;
#ifdef HAVE_LIBEXIF
	case GP_FILE_TYPE_EXIF:
		data = exif_data_new_from_file (path);
		if (!data) {
			gp_context_error (context, _("Could not open '%s'."),
					  path);
			return (GP_ERROR);
		}
		exif_data_save_data (data, &buf, &buf_len);
		exif_data_unref (data);
		gp_file_set_data_and_size (file, buf, buf_len);
		return (GP_OK);
#endif /* HAVE_LIBEXIF */
	default:
		return (GP_ERROR_NOT_SUPPORTED);
	}

	if (-1 == fstat(fd,&stbuf)) {
		close (fd);
		return GP_ERROR_IO_READ;
	}
#define BLOCKSIZE 65536
	/* do it in 64kb blocks */
	buf = malloc(BLOCKSIZE);
	if (!buf) {
		close (fd);
		return GP_ERROR_NO_MEMORY;
	}

	curread = 0;
	id = gp_context_progress_start (context, (1.0*stbuf.st_size/BLOCKSIZE), _("Getting file..."));
	GP_DEBUG ("Progress id: %i", id);
	result = GP_OK;
	while (curread < stbuf.st_size) {
		int ret;

		toread = stbuf.st_size-curread;
		if (toread>BLOCKSIZE) toread = BLOCKSIZE;
		ret = read(fd,buf,toread);
		if (ret == -1) {
			result = GP_ERROR_IO_READ;
			break;
		}
		curread += ret;
		gp_file_append (file, buf, ret);
		gp_context_progress_update (context, id, (1.0*curread/BLOCKSIZE));
		gp_context_idle (context);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
			result = GP_ERROR_CANCEL;
			break;
		}
#if 0
		/* We could take 2 seconds to download this image. everytime. */
		/* But actually this driver is used in production by some frontends,
		 * so do not delay at all
		 */
		usleep(2000000/(stbuf.st_size/BLOCKSIZE));
#endif
	}
	gp_context_progress_stop (context, id);
	free (buf);
	close (fd);
	return (GP_OK);
}
예제 #11
0
파일: directory.c 프로젝트: JohnChu/Snoopy
static int
set_info_func (CameraFilesystem *fs, const char *folder, const char *file,
	       CameraFileInfo info, void *data, GPContext *context)
{
	int retval;
	char path[1024];
	Camera *camera = (Camera*)data;

	retval = _get_path (camera->port, folder, file, path, sizeof(path));
	if (retval < GP_OK)
		return retval;

	/* We don't support updating permissions (yet) */
	if (info.file.fields & GP_FILE_INFO_PERMISSIONS)
		return (GP_ERROR_NOT_SUPPORTED);

	if (info.file.fields & GP_FILE_INFO_MTIME) {
		struct utimbuf utimbuf;

		utimbuf.actime  = info.file.mtime;
		utimbuf.modtime = info.file.mtime;
		if (utime (path, &utimbuf) != 0) {
			gp_context_error (context, _("Could not change "
				"time of file '%s' in '%s' (%m)."),
				file, folder);
			return (GP_ERROR);
		}
	}

#if 0 /* implement this using new api -Marcus */
	if (info.file.fields & GP_FILE_INFO_NAME) {
        	if (!strcasecmp (info.file.name, file))
        	        return (GP_OK);

	        /* We really have to rename the poor file... */
		if (strlen (folder) == 1) {
			snprintf (path_old, sizeof (path_old), "/%s",
				  file);
			snprintf (path_new, sizeof (path_new), "/%s",
				  info.file.name);
		} else {
			snprintf (path_old, sizeof (path_old), "%s/%s",
				  folder, file);
			snprintf (path_new, sizeof (path_new), "%s/%s",
				  folder, info.file.name);
		}
                retval = rename (path_old, path_new);
		if (retval != 0) {
	                switch (errno) {
	                case EISDIR:
	                        return (GP_ERROR_DIRECTORY_EXISTS);
	                case EEXIST:
	                        return (GP_ERROR_FILE_EXISTS);
	                case EINVAL:
	                        return (GP_ERROR_BAD_PARAMETERS);
	                case EIO:
	                        return (GP_ERROR_IO);
	                case ENOMEM:
	                        return (GP_ERROR_NO_MEMORY);
	                case ENOENT:
	                        return (GP_ERROR_FILE_NOT_FOUND);
	                default:
	                        return (GP_ERROR);
	                }
	        }
	}
#endif

        return (GP_OK);
}