コード例 #1
0
ファイル: create_objects.c プロジェクト: piotras/MDTs
int
main (int argc, char **argv)
{
	midgard_init ();	

	MidgardConfig *config = midgard_config_new ();
	midgard_config_read_file_at_path (config, "/tmp/test_SQLITE.conf", NULL);

	MidgardConnection *mgd = midgard_connection_new ();
	midgard_connection_open_config (mgd, config);

	//midgard_storage_create_base_storage (mgd);
	//midgard_storage_create (mgd,"midgard_snippetdir");

	MidgardObject *obj = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	midgard_object_create (obj);

	MidgardObject *obja = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	midgard_object_create (obja);

	MidgardObject *objb = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	midgard_object_create (objb);

	MidgardObject *objc = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	midgard_object_create (objc);
	
	MidgardObject *objd = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	midgard_object_create (objd);

	g_print ("END TEST FUNC \n");
	return 0;
}
コード例 #2
0
/**
 * midgard_connection_open_all:
 * @userdir: switch to read configuration from system or user's directory
 *
 * Every key is configuration name, and value is #MidgardConnection object.
 * Use g_hash_table_destroy to free hashtable and all opened connections.
 *
 * Returns: Newly allocated full #GHashTable.
 */
extern GHashTable *midgard_connection_open_all(gboolean userdir)
{
	GHashTable *cncs = 
		g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
	GHashTable *hash = NULL;

	gchar **cfgs = midgard_config_list_files(userdir);
	
	if(!cfgs) 
		return FALSE;

	guint i = 0;

	while(cfgs[i] != NULL) {
		
		MidgardConnection *cnc = midgard_connection_new();
		g_debug("Initialize new connection using '%s' configuration", cfgs[i]);
		
		GError *error = NULL;
		MidgardConfig *config = midgard_config_new();
		
		if(!midgard_config_read_file(config, cfgs[i], userdir, &error)) {

			if(error) {
				g_warning("%s", error->message);
				g_error_free(error);
			}

			i++;
			continue;
		}

		cnc->priv->config = config;

		if(__midgard_connection_open(cnc, &hash, TRUE)) {

			g_hash_table_insert(cncs, g_strdup(cfgs[i]), cnc);
		
		} else {
			
			g_object_unref(cnc);
			g_warning("Configuration %s failed", cfgs[i]);
		}
		
		i++;
	}
	
	if(hash)
		g_hash_table_destroy(hash);

	g_strfreev(cfgs);
	
	return cncs;
}
コード例 #3
0
/**
 * midgard_connection_open:	
 * @self: #MidgardConnection instance
 * @name: configuration file name
 * @error: pointer to store error 
 *
 * Opens a connection to the database, which is defined in named configuration. 
 * The configuration file is read from the system configuration directory
 * and is used as the configuration for the created connection. For example: `/etc`
 * directory is taken into account if library is compiled with `/usr' prefix, 
 * `/usr/local/etc` if compiled with `/usr/local` prefix, etc.
 *
 * Consider using midgard_connection_open_config(), if you need to open connection to 
 * database which is configured in user's home directory.
 *
 * If the named database configuration can not be read or the connection fails,
 * then %FALSE is returned and an error message is written to the global midgard
 * error state.
 *
 * It also initializes #MidgardSchema object (which is encapsulated by implementation )
 * and register all MgdSchema, #MidgardObjectClass derived classes defined by user.
 * This happens only when basic Midgard classes are not registered in GType system.
 * This is recommended way to initialize MgdSchema types.
 *  
 * Returns: %TRUE if the operation succeeded, %FALSE otherwise.
 */ 
gboolean 
midgard_connection_open (MidgardConnection *self, const char *name, GError **error)
{	
	g_assert(self != NULL);
	g_assert (name != NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	MIDGARD_ERRNO_SET (self, MGD_ERR_OK);
	gboolean rv = TRUE;
	
	__SELF_REOPEN (self, rv);
	if (!rv)
		return rv;	

	/* FIXME, it should be handled by GError */
	if(self->priv->config != NULL){
		midgard_set_error(self,
				MGD_GENERIC_ERROR,
				MGD_ERR_USER_DATA,
				"MidgardConfig already associated with "
				"MidgardConnection");
		return FALSE;
	}
	
	MidgardConfig *config = midgard_config_new();

	GError *rf_error = NULL;
	if(!midgard_config_read_file(config, name, FALSE, &rf_error)) {

		if(rf_error) 
			g_propagate_error(error, rf_error);	
		
		MIDGARD_ERRNO_SET (self, MGD_ERR_NOT_CONNECTED);
		return FALSE;
	}
	
	if(error)
		g_clear_error(&rf_error);

	self->priv->config = config;

	GHashTable *hash = NULL;

	if(!__midgard_connection_open(self, &hash, TRUE)) {

		MIDGARD_ERRNO_SET (self, MGD_ERR_NOT_CONNECTED);
		rv = FALSE;
	}

	g_hash_table_destroy(hash);
	
	return rv;
}
コード例 #4
0
/**
 * midgard_connection_open_from_file:	
 * @mgd: #MidgardConnection instance
 * @filepath: configuration file path
 * @error: pointer to store error 
 *
 * Opens a connection to the database. 
 * The configuration file is read from given filepath. 
 * 
 * Take a look at midgard_connection_open() wrt #MidgardSchema.
 *  
 * Returns: %TRUE if the operation succeeded, %FALSE otherwise.
 */ 
gboolean midgard_connection_open_from_file(
		MidgardConnection *mgd, const char *filepath, GError **error)
{	
	g_assert(mgd != NULL);
	g_assert (filepath != NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	gboolean rv = TRUE;

	__SELF_REOPEN (mgd, rv);
	if (!rv) 
		return rv;
	
	/* FIXME, it should be handled by GError */
	if(mgd->priv->config != NULL){
		midgard_set_error(mgd,
				MGD_GENERIC_ERROR,
				MGD_ERR_USER_DATA,
				"MidgardConfig already associated with "
				"MidgardConnection");
		return FALSE;
	}
	
	MidgardConfig *config = midgard_config_new();

	GError *rf_error = NULL;
	if(!midgard_config_read_file_at_path(config, filepath, &rf_error)) {

		if(rf_error) 
			g_propagate_error(error, rf_error);	

		return FALSE;
	}
	
	if(error)
		g_clear_error(&rf_error);

	mgd->priv->config = config;

	GHashTable *hash = NULL;

	if(!__midgard_connection_open(mgd, &hash, TRUE)) 
		rv = FALSE;

	if(hash)
		g_hash_table_destroy(hash);
	
	return rv;
}
コード例 #5
0
/* Object constructor */
static PHP_METHOD(midgard_config, __construct)
{
	RETVAL_FALSE;

	zval *object = getThis();

	if (zend_parse_parameters_none() == FAILURE)
		return;

	MidgardConfig *config = midgard_config_new();

	if (!config)
		RETURN_FALSE;

	MGD_PHP_SET_GOBJECT(object, config);
}
コード例 #6
0
ファイル: prog.c プロジェクト: piotras/pkgs
int main()
{
	midgard_init();

	MidgardConfig *config = midgard_config_new();
	g_object_set (config, 
			"dbtype", "SQLite", 
			"dbdir", "/tmp",
			"database", "MidgardStaticDB", 
			NULL);
	MidgardConnection *mgd = midgard_connection_new();
	midgard_connection_open_config (mgd, config, NULL);
	g_print("Connected '%s' \n", midgard_connection_get_error_string(mgd));

	midgard_storage_create_base_storage(mgd);
	g_print("Created storage: '%s' \n", midgard_connection_get_error_string(mgd));

	return 0;
}
コード例 #7
0
ファイル: pool.c プロジェクト: piotras/MDTs
int
main (int argc, char **argv)
{
	midgard_init ();	

	MidgardConfig *config = midgard_config_new ();
	midgard_config_read_file_at_path (config, "/tmp/test_SQLITE.conf", NULL);

	MidgardConnection *mgd = midgard_connection_new ();
	midgard_connection_open_config (mgd, config);

	GThreadPool *pool = g_thread_pool_new (pool_func, (gpointer) mgd, 10, TRUE, NULL);


	//midgard_storage_create_base_storage (mgd);
	//midgard_storage_create (mgd,"midgard_snippetdir");
	
	g_print ("START OPERATIONS \n");

	MidgardObject *obj = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) obj, NULL);

	MidgardObject *obja = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) obja, NULL);

	MidgardObject *objb = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) objb, NULL);
	
	MidgardObject *objc = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) objc, NULL);
	
	MidgardObject *objd = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) objd, NULL);

	g_print ("END OPERATIONS \n");

	g_print ("THREADS REMAIN (%d) \n", g_thread_pool_unprocessed (pool));	

	g_thread_pool_free (pool, FALSE, TRUE);

	return 0;
}