midgard_connection

midgard_connection

Synopsis

#define             GETTEXT_PACKAGE
typedef             MidgardConnectionClass;
                    MidgardConnectionPrivate;
                    MidgardConnectionCache;
typedef             midgard_connection;
MidgardConnection*  midgard_connection_new              (void);
gboolean            midgard_connection_open             (MidgardConnection *self,
                                                         const char *name,
                                                         GError **error);
gboolean            midgard_connection_open_config      (MidgardConnection *self,
                                                         MidgardConfig *config);
void                midgard_connection_close            (MidgardConnection *self);
gboolean            midgard_connection_set_sitegroup    (MidgardConnection *self,
                                                         const gchar *name);
const gchar*        midgard_connection_get_sitegroup    (MidgardConnection *self);
gboolean            midgard_connection_set_lang         (MidgardConnection *self,
                                                         const char *language);
gboolean            midgard_connection_set_default_lang (MidgardConnection *self,
                                                         const gchar *language);
const gchar*        midgard_connection_get_lang         (MidgardConnection *self);
const gchar*        midgard_connection_get_default_lang (MidgardConnection *self);
gboolean            midgard_connection_set_loglevel     (MidgardConnection *self,
                                                         const gchar *level,
                                                         GLogFunc log_func);
guint               midgard_connection_get_loglevel     (MidgardConnection *self);
void                midgard_connection_set_loghandler   (MidgardConnection *self,
                                                         guint loghandler);
guint               midgard_connection_get_loghandler   (MidgardConnection *self);
const gchar*        midgard_connection_get_sitegroup_from_id
                                                        (MidgardConnection *self,
                                                         guint id);
guint               midgard_connection_get_sitegroup_id (MidgardConnection *self);
const gchar*        midgard_connection_get_lang_from_id (MidgardConnection *self,
                                                         guint id);
guint               midgard_connection_get_lang_id      (MidgardConnection *self,
                                                         const gchar *language);
gint                midgard_connection_get_error        (MidgardConnection *self);
const gchar*        midgard_connection_get_error_string (MidgardConnection *self);
MidgardUser*        midgard_connection_get_user         (MidgardConnection *self);
MidgardConnection*  midgard_connection_struct_new       (void);
MidgardConnection*  midgard_connection_struct2gobject   (MidgardConnection *conn);
gboolean            midgard_connection_struct_open_config
                                                        (MidgardConnection *mgd,
                                                         MidgardConfig *config);
void                midgard_connection_workaround_set   (MidgardConnection *mgd);
MidgardConnection*  midgard_connection_workaround_get   (void);
void                midgard_connection_struct_free      (MidgardConnection *self);

Object Hierarchy

  GObject
   +----midgard_connection

Properties

  "errnum"                   gint                  : Read
  "errstr"                   gchar*                : Read
  "person"                   midgard_object*       : Read
  "request-config"           GObject*              : Read
  "user"                     midgard_user*         : Read

Signals

  "auth-changed"                                   : Run Last / No Recursion / No Hooks
  "error"                                          : Run Last / No Recursion / No Hooks
  "lang-changed"                                   : Run Last / No Recursion / No Hooks
  "sitegroup-changed"                              : Run Last / No Recursion / No Hooks

Description

Details

GETTEXT_PACKAGE

#define GETTEXT_PACKAGE "midgard"


MidgardConnectionClass

typedef struct MidgardConnectionClass MidgardConnectionClass;


MidgardConnectionPrivate

typedef struct _MidgardConnectionPrivate MidgardConnectionPrivate;


MidgardConnectionCache

typedef struct _MidgardConnectionCache MidgardConnectionCache;


midgard_connection

typedef struct _midgardConnection midgard_connection;


midgard_connection_new ()

MidgardConnection*  midgard_connection_new              (void);

Initializes new instance of MidgardConnection object type.

MidgardConnectionClass has no properties registered as class members. Every internal data of MidgardConnection object is accessible with API functions, and is not settable or gettable as property's value. Particular methods should be implemented for language bindings.

MidgardConnection objects holds runtime ( or request ) non persistent data like language, sitegroup, authentication type.

Persistent data like database name, blobs directory are associated with MidgardConfig object.

Returns :

pointer to MidgardConnection object or NULL on failure.

midgard_connection_open ()

gboolean            midgard_connection_open             (MidgardConnection *self,
                                                         const char *name,
                                                         GError **error);

Opens a connection to the database defined in named configuration. The configuration file is read from the standard configuration directories and used as the configuration for the created connection.

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.

self :

name :

configuration file name

error :

pointer to store error

Returns :

TRUE if the operation succeeded, FALSE otherwise.

midgard_connection_open_config ()

gboolean            midgard_connection_open_config      (MidgardConnection *self,
                                                         MidgardConfig *config);

Opens a MidgardConnection with the given configuration.

self :

[in]newly initialized MidgardConnection object

config :

MidgardConfig object

Returns :

TRUE on success, FALSE otherwise

midgard_connection_close ()

void                midgard_connection_close            (MidgardConnection *self);

Closes database connection.

This function closes database connection , destroys MidgardConnection object and frees its memory. It may be replaced by g_object_unref, with one exception.

When MidgardConnection object is initialized with midgard_connection_open function then MidgardConfig object is also destroyed and its memory is freed.

Caller is responsible to free MidgardConfig object when is used with MidgardConnection and connection object was initialized with midgard_connection_open_config function.

self :

MidgardConnection object

midgard_connection_set_sitegroup ()

gboolean            midgard_connection_set_sitegroup    (MidgardConnection *self,
                                                         const gchar *name);

Sets sitegroup's value for the given MidgardConnection.

Given sitegroup's name must be the value of exisiting in database sitegroup's record. When there is no sitegroup with such name or sitegroup is private , then connection's sitegroup is unchanged and method return FALSE.

See also: midgard_sitegroup_list if you need to get list of available sitegroup names.

Emits: "sitegroup_changed"

self :

MidgardConnection instance

name :

name of the sitegroup to switch

Returns :

TRUE on success, FALSE otherwise

midgard_connection_get_sitegroup ()

const gchar*        midgard_connection_get_sitegroup    (MidgardConnection *self);

Returns name of a sitegroup which is currently used for a connection.

Read more about Midgard sitegroups concept

self :

MidgardConnection instance

Returns :

sitegroup's name, or NULL if no sitegroup is set ( default SG0 )

midgard_connection_set_lang ()

gboolean            midgard_connection_set_lang         (MidgardConnection *self,
                                                         const char *language);

Sets the language of the given Midgard connection. The connection language affects all MultiLang database accesses as described in the Midgard MultiLang documentation.

The given language parameter is the two-letter language code stored in the language table in the Midgard database. This method returns FALSE if the given language is not found.

Read more about Multilingual content

See also: midgard_connection_set_default_lang

Emits: "lang-changed"

self :

MidgardConnection instance

language :

the new language code

Returns :

TRUE if the connection language has been changed, FALSE otherwise

midgard_connection_set_default_lang ()

gboolean            midgard_connection_set_default_lang (MidgardConnection *self,
                                                         const gchar *language);

Sets default language of the given MidgardConnection.

This function behaves almost the same as midgard_connection_set_lang. The only difference is that default language is used as fallback language.

self :

MidgardConnection

language :

the new language code

Returns :

TRUE if the connection language has been changed, FALSE otherwise

midgard_connection_get_lang ()

const gchar*        midgard_connection_get_lang         (MidgardConnection *self);

Returned language string is the two-letter language code. See also: midgard_connection_get_default_lang

self :

MidgardConnection instance

Returns :

language code of the given MidgardConnection or NULL if no language is set.

midgard_connection_get_default_lang ()

const gchar*        midgard_connection_get_default_lang (MidgardConnection *self);

\return

Returned language string is the two-letter language code.

See also: midgard_connection_get_lang

self :

MidgardConnection for which language is returned.

Returns :

language's code string or NULL if there's no default language set for MidgardConnection.

midgard_connection_set_loglevel ()

gboolean            midgard_connection_set_loglevel     (MidgardConnection *self,
                                                         const gchar *level,
                                                         GLogFunc log_func);

Sets log level of the given MidgardConnection. Overwrites internal MidgardConnection's log level defined in configuration file. By default MidgardConnection holds loglevel which is associated with ( and duplicated from ) MidgardConfig. MidgardConfig object's log level isn't changed by this function

This method is a shortcut which sets correctly loghandler,loglevel and GLib's log function. Default log function will be used if NULL is defined. Core's default function is midgard_error_default_log.

Available levels: error, warn, warning, info, message, debug. warn is default loglevel, SQL queries are logged with debug level. With info level, function names ( and classes' names ) are ( at least should be) logged in language bindings

self :

MidgardConnection instance

level :

Loglevel string

log_func :

log handler function

Returns :

TRUE if debug level is set, FALSE otherwise

midgard_connection_get_loglevel ()

guint               midgard_connection_get_loglevel     (MidgardConnection *self);

self :

MidgardConnection instance

Returns :

unsigned integer flag specified by GLogLevelFlags.

midgard_connection_set_loghandler ()

void                midgard_connection_set_loghandler   (MidgardConnection *self,
                                                         guint loghandler);

Sets internal loghandler id associated with G_LOG_DOMAIN and loglevel. Caller is responsible to remove loghandler using g_log_remove_handler when new loglevel for G_LOG_DOMAIN is set.

See also: midgard_connection_set_loglevel

self :

MidgardConnection instance

loghandler :

loghandler id

midgard_connection_get_loghandler ()

guint               midgard_connection_get_loghandler   (MidgardConnection *self);

self :

MidgardConnection instance

Returns :

unsigned integer value which is associated with G_LOG_DOMAIN and MidgardConnection's loglevel currently set.

midgard_connection_get_sitegroup_from_id ()

const gchar*        midgard_connection_get_sitegroup_from_id
                                                        (MidgardConnection *self,
                                                         guint id);

This method returns name for the sitegroup which is identified by given id. You should use this method only ( and only ) when you need ( for example ) set connection's sitegroup using sitegroup's id set to an object.

This is transition helper method.

self :

MidgardConnection instance

id :

sitegroup's id

Returns :

sitegroup name or NULL if there's no sitegroup with given id.

midgard_connection_get_sitegroup_id ()

guint               midgard_connection_get_sitegroup_id (MidgardConnection *self);

self :

MidgardConnection instance

Returns :

id unsigned integer which identifies sitegroup for the given MidgardConnection.

midgard_connection_get_lang_from_id ()

const gchar*        midgard_connection_get_lang_from_id (MidgardConnection *self,
                                                         guint id);

This is transition helper method.

self :

MidgardConnection instance

id :

language's id

Returns :

code for the language which is identified by given id or NULL.

midgard_connection_get_lang_id ()

guint               midgard_connection_get_lang_id      (MidgardConnection *self,
                                                         const gchar *language);

Returned id is an integer which identifies language for the given MidgardConnection. If language parameter is different than NULL, internal lookup is made to find matching language id.

self :

MidgardConnection instance

language :

optional two letter language code

Returns :

language id

midgard_connection_get_error ()

gint                midgard_connection_get_error        (MidgardConnection *self);

Error id may be one of set by midgard_error.

self :

MidgardConnection instance

Returns :

Last error id set

midgard_connection_get_error_string ()

const gchar*        midgard_connection_get_error_string (MidgardConnection *self);

Error string may be one set by midgard_error.

self :

MidgardConnection instance

Returns :

last error string

midgard_connection_get_user ()

MidgardUser*        midgard_connection_get_user         (MidgardConnection *self);

NULL is explicitly returned if there's no midgard_user logged in for the given MidgardConnection. See also MidgardUser methods if you need midgard_person associated with user.

self :

MidgardConnection instance

Returns :

A pointer to MidgardUser instance or NULL

midgard_connection_struct_new ()

MidgardConnection*  midgard_connection_struct_new       (void);

Returns :


midgard_connection_struct2gobject ()

MidgardConnection*  midgard_connection_struct2gobject   (MidgardConnection *conn);

conn :

Returns :


midgard_connection_struct_open_config ()

gboolean            midgard_connection_struct_open_config
                                                        (MidgardConnection *mgd,
                                                         MidgardConfig *config);

mgd :

config :

Returns :


midgard_connection_workaround_set ()

void                midgard_connection_workaround_set   (MidgardConnection *mgd);

mgd :


midgard_connection_workaround_get ()

MidgardConnection*  midgard_connection_workaround_get   (void);

Returns :


midgard_connection_struct_free ()

void                midgard_connection_struct_free      (MidgardConnection *self);

self :

Property Details

The "errnum" property

  "errnum"                   gint                  : Read

Error code which is currently set.

Allowed values: >= 0

Default value: 0


The "errstr" property

  "errstr"                   gchar*                : Read

Error string which i scurrently set.

Default value: ""


The "person" property

  "person"                   midgard_object*       : Read

midgard_person which is currently logged in.


The "request-config" property

  "request-config"           GObject*              : Read

midgard_request_config object which is valid during connection.


The "user" property

  "user"                     midgard_user*         : Read

midgard_user which is currently logged in.

Signal Details

The "auth-changed" signal

void                user_function                      (midgard_connection *midgard_connection,
                                                        gpointer            user_data)               : Run Last / No Recursion / No Hooks

midgard_connection :

the object which received the signal.

user_data :

user data set when the signal handler was connected.

The "error" signal

void                user_function                      (midgard_connection *midgard_connection,
                                                        gpointer            user_data)               : Run Last / No Recursion / No Hooks

midgard_connection :

the object which received the signal.

user_data :

user data set when the signal handler was connected.

The "lang-changed" signal

void                user_function                      (midgard_connection *midgard_connection,
                                                        gpointer            user_data)               : Run Last / No Recursion / No Hooks

midgard_connection :

the object which received the signal.

user_data :

user data set when the signal handler was connected.

The "sitegroup-changed" signal

void                user_function                      (midgard_connection *midgard_connection,
                                                        gpointer            user_data)               : Run Last / No Recursion / No Hooks

midgard_connection :

the object which received the signal.

user_data :

user data set when the signal handler was connected.