예제 #1
0
파일: symuser.c 프로젝트: 070499/xbmc
static int start(void *d) {
	plugin_data_t *data = d;
	cp_extension_t **exts;
	
	exts = cp_get_extensions_info(data->ctx, "symuser.strings", NULL, NULL);
	if (exts != NULL && exts[0] != NULL) {
		const char *symname;
		
		symname = cp_lookup_cfg_value(exts[0]->configuration, "@string-symbol");
		if (symname != NULL) {
			data->str = cp_resolve_symbol(data->ctx, exts[0]->plugin->identifier, symname, NULL);
			if (data->str == NULL) {
				cp_log(data->ctx, CP_LOG_ERROR, "Could not resolve symbol specified by extension.");
			}
		} else {
			cp_log(data->ctx, CP_LOG_ERROR, "No string-symbol attribute present in extension.");
		} 
	} else {
		cp_log(data->ctx, CP_LOG_ERROR, "No extensions available.");
	}
	if (exts != NULL) {
		cp_release_info(data->ctx, exts);
	}
	if (data->str == NULL) {
		return CP_ERR_RUNTIME;
	}
	return cp_define_symbol(data->ctx, "used_string", (void *) data->str);
}
예제 #2
0
/**
 * Classifies a file based on file extension. This classifier uses extensions
 * installed at the file type extension point. Therefore we need pointer to
 * the plug-in context to access the extensions. A plug-in instance initializes
 * the classifier structure with the plug-in context pointer and registers a
 * virtual symbol pointing to the classifier.
 */
static int classify(void *d, const char *path) {
	cp_context_t *ctx = d;
	cp_extension_t **exts;
	const char *type = NULL;
	int i;

	// Go through all extensions registered at the extension point
	exts = cp_get_extensions_info(ctx, "org.c-pluff.examples.cpfile.extension.file-types", NULL, NULL);
	if (exts == NULL) {
		cp_log(ctx, CP_LOG_ERROR, "Could not resolve file type extensions.");
		return 0;
	}
	for (i = 0; type == NULL && exts[i] != NULL; i++) {
		int j;

		// Go through all file types provided by the extension
		for (j = 0; type == NULL && j < exts[i]->configuration->num_children; j++) {
			cp_cfg_element_t *elem = exts[i]->configuration->children + j;
			const char *desc = NULL;

			if (strcmp(elem->name, "file-type") == 0
				&& (desc = cp_lookup_cfg_value(elem, "@description")) != NULL
				&& (is_of_type(path, elem))) {
				type = desc;
			}
		}
	}

	// Release extension information
	cp_release_info(ctx, exts);

	// Print file type if recognized, otherwise try other classifiers
	if (type != NULL) {
		fputs(type, stdout);
		putchar('\n');
		return 1;
	} else {
		return 0;
	}
}