1 /*
2  * Copyright (C) 2000 Reinhard Müller <reinhard@src.gnome.org>
3  * Copyright (C) 2000 - 2002 Rodrigo Moya <rodrigo@gnome-db.org>
4  * Copyright (C) 2001 Carlos Perelló Marín <carlos@gnome-db.org>
5  * Copyright (C) 2001 - 2011 Vivien Malerba <malerba@gnome-db.org>
6  * Copyright (C) 2002 Gonzalo Paniagua Javier <gonzalo@src.gnome.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA  02110-1301, USA.
22  */
23 
24 #ifndef __GDA_CONNECTION_INTERNAL_H_
25 #define __GDA_CONNECTION_INTERNAL_H_
26 
27 #include <libgda/gda-decl.h>
28 #include <libgda/gda-server-provider.h>
29 #include <libgda/thread-wrapper/gda-thread-wrapper.h>
30 
31 G_BEGIN_DECLS
32 
33 /*
34  * Warnings
35  */
36 #ifdef GDA_DEBUG
37 #define ASSERT_TABLE_NAME(x,y) g_assert (!strcmp ((x), (y)))
38 #define WARN_METHOD_NOT_IMPLEMENTED(prov,method) g_warning ("Provider '%s' does not implement the META method '%s()', please report the error to bugzilla.gnome.org", gda_server_provider_get_name (prov), (method))
39 #define WARN_META_UPDATE_FAILURE(x,method) if (!(x)) g_print ("%s (meta method => %s) ERROR: %s\n", __FUNCTION__, (method), error && *error && (*error)->message ? (*error)->message : "???")
40 #else
41 #define ASSERT_TABLE_NAME(x,y)
42 #define WARN_METHOD_NOT_IMPLEMENTED(prov,method)
43 #define WARN_META_UPDATE_FAILURE(x,method)
44 #endif
45 
46 /*
47  * Opens a connection to an SQLite database. This function is intended to be used
48  * internally when objects require an SQLite connection, for example for the GdaMetaStore
49  * object
50  */
51 GdaConnection *_gda_open_internal_sqlite_connection (const gchar *cnc_string);
52 
53 typedef struct {
54 	guint jid;
55 	GdaServerProviderExecCallback async_cb;
56 	gpointer cb_data;
57 } ThreadConnectionAsyncTask;
58 void _ThreadConnectionAsyncTask_free (ThreadConnectionAsyncTask *atd);
59 
60 /*
61  * Functions dedicated to implementing a GdaConnection which uses a GdaThreadWrapper around
62  * another connection to make it thread safe.
63  */
64 typedef struct {
65         GdaConnection *sub_connection;
66 	gboolean sub_connection_has_closed;
67         GdaServerProvider *cnc_provider;
68         GdaThreadWrapper *wrapper;
69 	GArray *handlers_ids; /* array of gulong */
70 
71 	/* current async. tasks */
72 	GSList *async_tasks; /* list of ThreadConnectionAsyncTask pointers */
73 } ThreadConnectionData; /* Per connection private data for */
74 void                  _gda_thread_connection_set_data (GdaConnection *cnc, ThreadConnectionData *cdata);
75 ThreadConnectionData *_gda_thread_connection_get_data (GdaConnection *cnc);
76 void                  _gda_thread_connection_data_free (ThreadConnectionData *cdata);
77 void                  _gda_connection_force_transaction_status (GdaConnection *cnc, GdaConnection *wrapped_cnc);
78 GdaServerProvider    *_gda_connection_get_internal_thread_provider (void);
79 
80 void                  _gda_connection_define_as_thread_wrapper (GdaConnection *cnc);
81 
82 /*
83  * Used by virtual connections to keep meta data up to date when a table
84  * is added or removed, without using the update_meta_store_after_statement_exec()
85  * because it may not be called everytime
86  */
87 void               _gda_connection_signal_meta_table_update (GdaConnection *cnc, const gchar *table_name);
88 gchar             *_gda_connection_compute_table_virtual_name (GdaConnection *cnc, const gchar *table_name);
89 
90 G_END_DECLS
91 
92 #endif
93