Changeset 16255
- Timestamp:
- 04/28/08 09:12:26 (7 months ago)
- Files:
-
- trunk/midgard/core/midgard/src/midgard_config.c (modified) (1 diff)
- trunk/midgard/core/midgard/src/midgard_connection.c (modified) (11 diffs)
- trunk/midgard/core/midgard/src/midgard_connection.h (modified) (3 diffs)
- trunk/midgard/core/midgard/src/midgard_core_object.h (modified) (1 diff)
- trunk/midgard/core/midgard/test/midgard-query.c (modified) (1 diff)
- trunk/midgard/core/midgard/test/midgard-schema.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midgard/core/midgard/src/midgard_config.c
r16202 r16255 827 827 } 828 828 829 GHashTable *hash = NULL; 830 if(!midgard_connection_open_config(mgd, config, &hash)){ 829 if(!midgard_connection_open_config(mgd, config)){ 831 830 g_object_unref(mgd); 832 g_object_unref(config); 833 if(hash) g_hash_table_destroy(hash); 831 g_object_unref(config); 834 832 return NULL; 835 833 } 836 if(hash) g_hash_table_destroy(hash);837 834 838 835 /* trunk/midgard/core/midgard/src/midgard_connection.c
r16191 r16255 142 142 143 143 cnc_private->config = NULL; 144 cnc_private->free_config = FALSE; 144 145 cnc_private->loghandler = 0; 145 146 cnc_private->loglevel = 0; … … 231 232 g_free(self->priv->cache); 232 233 self->priv->cache = NULL; 234 } 235 236 if(self->priv->free_config) { 237 g_object_unref(self->priv->config); 238 self->priv->config = NULL; 239 self->priv->free_config = FALSE; 233 240 } 234 241 … … 433 440 /* Private members */ 434 441 self->priv = midgard_connection_private_new(); 442 self->priv->free_config= FALSE; 435 443 self->priv->cache = NULL; 436 444 self->priv->user = NULL; … … 496 504 } 497 505 506 static void _to_close_cnc_callback(GdaConnection *cnc, 507 GdaConnectionEvent *event, gpointer ud) 508 { 509 g_warning("Midgard connection to close: %s, No:(%li), src:%s, SQL: %s", 510 gda_connection_event_get_description(event), 511 (long) gda_connection_event_get_code(event), 512 gda_connection_event_get_source(event), 513 gda_connection_event_get_sqlstate (event)); 514 } 515 516 static void _closed_cnc_callback(GdaConnection *cnc, 517 GdaConnectionEvent *event, gpointer ud) 518 { 519 g_warning("Midgard CONNECTION CLOSED"); 520 } 498 521 499 522 /** … … 731 754 g_signal_connect(G_OBJECT(connection), "error", 732 755 G_CALLBACK(_connect_cnc_callback), (gpointer) mgd); 756 g_signal_connect(G_OBJECT(connection), "conn_to_close", 757 G_CALLBACK(_to_close_cnc_callback), (gpointer) mgd); 758 g_signal_connect(G_OBJECT(connection), "conn_closed", 759 G_CALLBACK(_closed_cnc_callback), (gpointer) mgd); 760 761 733 762 734 763 if(init_schema) { … … 789 818 * @mgd: #MidgardConnection instance 790 819 * @name: configuration file name 791 * @hash: GHashTable table792 820 * 793 821 * Opens a connection to the database defined in named configuration. … … 802 830 */ 803 831 gboolean midgard_connection_open( 804 MidgardConnection *mgd, const char *name, 805 GHashTable **hash) 832 MidgardConnection *mgd, const char *name) 806 833 { 807 834 g_assert(mgd != NULL); … … 822 849 823 850 mgd->priv->config = config; 824 825 if(!__midgard_connection_open(mgd, hash, TRUE)) 851 mgd->priv->free_config = TRUE; 852 853 GHashTable *hash = NULL; 854 gboolean rv = TRUE; 855 856 if(!__midgard_connection_open(mgd, &hash, TRUE)) 857 rv = FALSE; 858 859 g_hash_table_destroy(hash); 860 861 return rv; 862 } 863 864 /** 865 * midgard_connection_open_all: 866 * @userdir: switch to read configuration from system or user's directory 867 * 868 * Every key is configuration name, and value is #MidgardConnection object. 869 * Use g_hash_table_destroy to free hashtable and all opened connections. 870 * 871 * Returns: Newly allocated full #GHashTable. 872 */ 873 extern GHashTable *midgard_connection_open_all(gboolean userdir) 874 { 875 GHashTable *cncs = 876 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref); 877 GHashTable *hash = NULL; 878 879 gchar **cfgs = midgard_config_list_files(userdir); 880 881 if(!cfgs) 826 882 return FALSE; 827 883 828 return TRUE; 884 guint i = 0; 885 886 while(cfgs[i] != NULL) { 887 888 MidgardConnection *cnc = midgard_connection_new(); 889 g_debug("Initialize new connection using '%s' configuration", cfgs[i]); 890 891 MidgardConfig *config = midgard_config_new(); 892 if(!midgard_config_read_file(config, cfgs[i], userdir)) 893 g_warning("Can not open %s configuration", cfgs[i]); 894 895 cnc->priv->config = config; 896 cnc->priv->free_config = TRUE; 897 898 if(__midgard_connection_open(cnc, &hash, TRUE)) { 899 900 g_hash_table_insert(cncs, g_strdup(cfgs[i]), cnc); 901 902 } else { 903 904 g_object_unref(cnc); 905 g_warning("Configuration %s failed", cfgs[i]); 906 } 907 908 i++; 909 } 910 911 if(hash) 912 g_hash_table_destroy(hash); 913 914 g_strfreev(cfgs); 915 916 return cncs; 829 917 } 830 918 … … 833 921 * @self: [in]newly initialized #MidgardConnection object 834 922 * @config: #MidgardConfig object 835 * @hash: table to store reusable cache data836 923 * 837 924 * Opens a #MidgardConnection with the given configuration. 838 *839 * Third @hash parameter usage is exactly the same as in840 * midgard_connection_open function.841 925 * 842 926 * Returns: %TRUE on success, %FALSE otherwise 843 927 */ 844 928 gboolean midgard_connection_open_config( 845 MidgardConnection *self, MidgardConfig *config, 846 GHashTable **hashtable) 929 MidgardConnection *self, MidgardConfig *config) 847 930 { 848 931 g_assert(self != NULL); … … 850 933 851 934 self->priv->config = config; 852 853 if(!__midgard_connection_open(self, hashtable, TRUE)) 854 return FALSE; 855 856 return TRUE; 935 936 GHashTable *hash = NULL; 937 gboolean rv = TRUE; 938 939 if(!__midgard_connection_open(self, &hash, TRUE)) 940 rv = FALSE; 941 942 g_hash_table_destroy(hash); 943 944 return rv; 857 945 } 858 946 859 947 gboolean midgard_connection_struct_open_config( 860 MidgardConnection *self, MidgardConfig *config, 861 GHashTable **hashtable) 948 MidgardConnection *self, MidgardConfig *config) 862 949 { 863 950 g_assert(self != NULL); … … 866 953 self->priv->config = config; 867 954 868 if(!__midgard_connection_open(self, hashtable, FALSE))955 if(!__midgard_connection_open(self, NULL, FALSE)) 869 956 return FALSE; 870 957 trunk/midgard/core/midgard/src/midgard_connection.h
r16191 r16255 50 50 51 51 /* class members */ 52 gboolean (*open) (MidgardConnection *mgd, 53 const char *name, GHashTable **hash); 54 gboolean (*open_config) (MidgardConnection *mgd, 55 MidgardConfig *config, GHashTable **hash); 52 gboolean (*open) (MidgardConnection *mgd, const char *name); 53 gboolean (*open_config) (MidgardConnection *mgd, MidgardConfig *config); 56 54 void (*close) (MidgardConnection *mgd); 57 55 … … 106 104 extern MidgardConnection *midgard_connection_new(void); 107 105 108 extern gboolean midgard_connection_open( 109 MidgardConnection *self, const char *name, 110 GHashTable **hash); 106 extern gboolean midgard_connection_open(MidgardConnection *self, const char *name); 111 107 112 extern gboolean midgard_connection_open_config(113 MidgardConnection *self, MidgardConfig *config, 114 GHashTable **hash);108 extern GHashTable *midgard_connection_open_all(gboolean userdir); 109 110 extern gboolean midgard_connection_open_config(MidgardConnection *self, MidgardConfig *config); 115 111 116 112 extern void midgard_connection_close(MidgardConnection *self); … … 173 169 174 170 extern gboolean midgard_connection_struct_open_config( 175 MidgardConnection *mgd, MidgardConfig *config, 176 GHashTable **hash); 171 MidgardConnection *mgd, MidgardConfig *config); 177 172 178 173 extern void midgard_connection_workaround_set(MidgardConnection *mgd); trunk/midgard/core/midgard/src/midgard_core_object.h
r15473 r16255 114 114 struct _MidgardConnectionPrivate{ 115 115 MidgardConfig *config; 116 gboolean free_config; 116 117 guint loghandler; 117 118 guint loglevel; trunk/midgard/core/midgard/test/midgard-query.c
r15476 r16255 80 80 if(!midgard_config_read_file(config, (const gchar *)config_name, cts)) 81 81 return 1; 82 83 GHashTable *hash = NULL; 84 if(!midgard_connection_open_config(mgd, config, &hash)) { 85 if(hash) g_hash_table_destroy(hash); 86 return 1; 87 } 88 if(hash) g_hash_table_destroy(hash); 82 83 if(!midgard_connection_open_config(mgd, config)) 84 return 1; 89 85 90 86 //midgard_connection_set_loglevel(mgd, "warning"); trunk/midgard/core/midgard/test/midgard-schema.c
r16211 r16255 176 176 midgard, config)) 177 177 */ 178 GHashTable *hash = NULL; 179 if(!midgard_connection_open_config(mgd, config, &hash)) { 180 if(hash) g_hash_table_destroy(hash); 178 if(!midgard_connection_open_config(mgd, config)) 181 179 return 1; 182 } 183 if(hash) g_hash_table_destroy(hash); 184 180 185 181 guint n_types, i; 186 182 GType *all_types = g_type_children(MIDGARD_TYPE_OBJECT, &n_types);
