connectionpooling.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * connectionpooling.c
  3. *
  4. * $Id$
  5. *
  6. * The iODBC driver manager.
  7. *
  8. * Copyright (C) 1996-2021 OpenLink Software <[email protected]>
  9. * All Rights Reserved.
  10. *
  11. * This software is released under the terms of either of the following
  12. * licenses:
  13. *
  14. * - GNU Library General Public License (see LICENSE.LGPL)
  15. * - The BSD License (see LICENSE.BSD).
  16. *
  17. * Note that the only valid version of the LGPL license as far as this
  18. * project is concerned is the original GNU Library General Public License
  19. * Version 2, dated June 1991.
  20. *
  21. * While not mandated by the BSD license, any patches you make to the
  22. * iODBC source code may be contributed back into the iODBC project
  23. * at your discretion. Contributions will benefit the Open Source and
  24. * Data Access community as a whole. Submissions may be made at:
  25. *
  26. * http://www.iodbc.org
  27. *
  28. *
  29. * GNU Library Generic Public License Version 2
  30. * ============================================
  31. * This library is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU Library General Public
  33. * License as published by the Free Software Foundation; only
  34. * Version 2 of the License dated June 1991.
  35. *
  36. * This library is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  39. * Library General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU Library General Public
  42. * License along with this library; if not, write to the Free
  43. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  44. *
  45. *
  46. * The BSD License
  47. * ===============
  48. * Redistribution and use in source and binary forms, with or without
  49. * modification, are permitted provided that the following conditions
  50. * are met:
  51. *
  52. * 1. Redistributions of source code must retain the above copyright
  53. * notice, this list of conditions and the following disclaimer.
  54. * 2. Redistributions in binary form must reproduce the above copyright
  55. * notice, this list of conditions and the following disclaimer in
  56. * the documentation and/or other materials provided with the
  57. * distribution.
  58. * 3. Neither the name of OpenLink Software Inc. nor the names of its
  59. * contributors may be used to endorse or promote products derived
  60. * from this software without specific prior written permission.
  61. *
  62. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  63. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  64. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  65. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR
  66. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  67. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  68. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  69. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  70. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  71. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  72. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  73. */
  74. #include "gui.h"
  75. static void
  76. connectionpool_finish_clicked (GtkWidget *widget,
  77. TCONNECTIONPOOLING *connectionpool_t)
  78. {
  79. if (connectionpool_t)
  80. {
  81. connectionpool_t->changed = TRUE;
  82. memset(connectionpool_t->timeout, 0, sizeof(connectionpool_t->timeout));
  83. memset(connectionpool_t->probe, 0, sizeof(connectionpool_t->probe));
  84. strncpy (connectionpool_t->timeout,
  85. gtk_entry_get_text (GTK_ENTRY (connectionpool_t->timeout_entry)),
  86. sizeof(connectionpool_t->timeout)-1);
  87. strncpy (connectionpool_t->probe,
  88. gtk_entry_get_text (GTK_ENTRY (connectionpool_t->probe_entry)),
  89. sizeof(connectionpool_t->probe)-1);
  90. gtk_signal_disconnect_by_func (GTK_OBJECT (connectionpool_t->mainwnd),
  91. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  92. gtk_main_quit ();
  93. gtk_widget_destroy (connectionpool_t->mainwnd);
  94. }
  95. }
  96. static void
  97. connectionpool_cancel_clicked (GtkWidget *widget,
  98. TCONNECTIONPOOLING *connectionpool_t)
  99. {
  100. if (connectionpool_t)
  101. {
  102. connectionpool_t->changed = FALSE;
  103. gtk_signal_disconnect_by_func (GTK_OBJECT (connectionpool_t->mainwnd),
  104. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  105. gtk_main_quit ();
  106. gtk_widget_destroy (connectionpool_t->mainwnd);
  107. }
  108. }
  109. static gint
  110. delete_event (GtkWidget *widget,
  111. GdkEvent *event, TCONNECTIONPOOLING *connectionpool_t)
  112. {
  113. connectionpool_cancel_clicked (widget, connectionpool_t);
  114. return FALSE;
  115. }
  116. BOOL
  117. create_connectionpool (HWND hwnd, TCONNECTIONPOOLING *choose_t)
  118. {
  119. GdkPixmap *pixmap;
  120. GdkBitmap *mask;
  121. GtkStyle *style;
  122. GtkWidget *connectionpool;
  123. GtkWidget *dialog_vbox7;
  124. GtkWidget *frame1;
  125. GtkWidget *alignment76;
  126. GtkWidget *vbox40;
  127. GtkWidget *frame93;
  128. GtkWidget *alignment77;
  129. GtkWidget *label154;
  130. GtkWidget *frame94;
  131. GtkWidget *alignment78;
  132. GtkWidget *hbox55;
  133. GtkWidget *label156;
  134. GtkWidget *t_cptimeout;
  135. GtkWidget *frame95;
  136. GtkWidget *alignment79;
  137. GtkWidget *label155;
  138. GtkWidget *frame96;
  139. GtkWidget *alignment80;
  140. GtkWidget *hbox56;
  141. GtkWidget *label157;
  142. GtkWidget *t_probe;
  143. GtkWidget *flabel1;
  144. GtkWidget *dialog_action_area7;
  145. GtkWidget *b_cancel;
  146. GtkWidget *b_finish;
  147. char msg[1024];
  148. if (hwnd == NULL || !GTK_IS_WIDGET (hwnd) || !choose_t)
  149. return FALSE;
  150. connectionpool = gtk_dialog_new ();
  151. gtk_widget_set_name (connectionpool, "connectionpool");
  152. gtk_widget_set_size_request (connectionpool, 433, 227);
  153. gtk_window_set_title (GTK_WINDOW (connectionpool), _("Connection pooling attributes"));
  154. gtk_window_set_position (GTK_WINDOW (connectionpool), GTK_WIN_POS_CENTER);
  155. gtk_window_set_modal (GTK_WINDOW (connectionpool), TRUE);
  156. gtk_window_set_default_size (GTK_WINDOW (connectionpool), 433, 227);
  157. gtk_window_set_type_hint (GTK_WINDOW (connectionpool), GDK_WINDOW_TYPE_HINT_DIALOG);
  158. #if GTK_CHECK_VERSION(2,0,0)
  159. gtk_widget_show (connectionpool);
  160. #endif
  161. dialog_vbox7 = GTK_DIALOG (connectionpool)->vbox;
  162. gtk_widget_set_name (dialog_vbox7, "dialog_vbox7");
  163. gtk_widget_show (dialog_vbox7);
  164. frame1 = gtk_frame_new (choose_t->driver);
  165. gtk_widget_set_name (frame1, "frame1");
  166. gtk_widget_show (frame1);
  167. gtk_box_pack_start (GTK_BOX (dialog_vbox7), frame1, TRUE, TRUE, 0);
  168. alignment76 = gtk_alignment_new (0.5, 0.5, 1, 1);
  169. gtk_widget_set_name (alignment76, "alignment76");
  170. gtk_widget_show (alignment76);
  171. gtk_container_add (GTK_CONTAINER (frame1), alignment76);
  172. vbox40 = gtk_vbox_new (FALSE, 0);
  173. gtk_widget_set_name (vbox40, "vbox40");
  174. gtk_widget_show (vbox40);
  175. gtk_container_add (GTK_CONTAINER (alignment76), vbox40);
  176. frame93 = gtk_frame_new (NULL);
  177. gtk_widget_set_name (frame93, "frame93");
  178. gtk_widget_show (frame93);
  179. gtk_box_pack_start (GTK_BOX (vbox40), frame93, FALSE, TRUE, 0);
  180. gtk_frame_set_shadow_type (GTK_FRAME (frame93), GTK_SHADOW_NONE);
  181. alignment77 = gtk_alignment_new (0.5, 0.5, 1, 1);
  182. gtk_widget_set_name (alignment77, "alignment77");
  183. gtk_widget_show (alignment77);
  184. gtk_container_add (GTK_CONTAINER (frame93), alignment77);
  185. label154 = gtk_label_new (_("Enable connection pooling for this driver by specifying\na timeout in seconds"));
  186. gtk_widget_set_name (label154, "label154");
  187. gtk_widget_show (label154);
  188. gtk_container_add (GTK_CONTAINER (alignment77), label154);
  189. frame94 = gtk_frame_new (NULL);
  190. gtk_widget_set_name (frame94, "frame94");
  191. gtk_widget_show (frame94);
  192. gtk_box_pack_start (GTK_BOX (vbox40), frame94, FALSE, TRUE, 0);
  193. gtk_frame_set_shadow_type (GTK_FRAME (frame94), GTK_SHADOW_NONE);
  194. alignment78 = gtk_alignment_new (0.5, 0.5, 1, 1);
  195. gtk_widget_set_name (alignment78, "alignment78");
  196. gtk_widget_show (alignment78);
  197. gtk_container_add (GTK_CONTAINER (frame94), alignment78);
  198. gtk_alignment_set_padding (GTK_ALIGNMENT (alignment78), 0, 0, 4, 10);
  199. hbox55 = gtk_hbox_new (FALSE, 0);
  200. gtk_widget_set_name (hbox55, "hbox55");
  201. gtk_widget_show (hbox55);
  202. gtk_container_add (GTK_CONTAINER (alignment78), hbox55);
  203. label156 = gtk_label_new (_("Timeout : "));
  204. gtk_widget_set_name (label156, "label156");
  205. gtk_widget_show (label156);
  206. gtk_box_pack_start (GTK_BOX (hbox55), label156, FALSE, FALSE, 0);
  207. t_cptimeout = gtk_entry_new ();
  208. gtk_widget_set_name (t_cptimeout, "t_cptimeout");
  209. gtk_widget_show (t_cptimeout);
  210. gtk_box_pack_start (GTK_BOX (hbox55), t_cptimeout, TRUE, TRUE, 0);
  211. if (choose_t)
  212. gtk_entry_set_text (GTK_ENTRY (t_cptimeout), choose_t->timeout);
  213. frame95 = gtk_frame_new (NULL);
  214. gtk_widget_set_name (frame95, "frame95");
  215. gtk_widget_show (frame95);
  216. gtk_box_pack_start (GTK_BOX (vbox40), frame95, FALSE, TRUE, 0);
  217. gtk_frame_set_shadow_type (GTK_FRAME (frame95), GTK_SHADOW_NONE);
  218. alignment79 = gtk_alignment_new (0.5, 0.5, 1, 1);
  219. gtk_widget_set_name (alignment79, "alignment79");
  220. gtk_widget_show (alignment79);
  221. gtk_container_add (GTK_CONTAINER (frame95), alignment79);
  222. label155 = gtk_label_new (_("Set an optional probe query, used for additional verification\nof the connection state"));
  223. gtk_widget_set_name (label155, "label155");
  224. gtk_widget_show (label155);
  225. gtk_container_add (GTK_CONTAINER (alignment79), label155);
  226. frame96 = gtk_frame_new (NULL);
  227. gtk_widget_set_name (frame96, "frame96");
  228. gtk_widget_show (frame96);
  229. gtk_box_pack_start (GTK_BOX (vbox40), frame96, FALSE, TRUE, 0);
  230. gtk_frame_set_shadow_type (GTK_FRAME (frame96), GTK_SHADOW_NONE);
  231. alignment80 = gtk_alignment_new (0.5, 0.5, 1, 1);
  232. gtk_widget_set_name (alignment80, "alignment80");
  233. gtk_widget_show (alignment80);
  234. gtk_container_add (GTK_CONTAINER (frame96), alignment80);
  235. gtk_alignment_set_padding (GTK_ALIGNMENT (alignment80), 0, 10, 4, 10);
  236. hbox56 = gtk_hbox_new (FALSE, 0);
  237. gtk_widget_set_name (hbox56, "hbox56");
  238. gtk_widget_show (hbox56);
  239. gtk_container_add (GTK_CONTAINER (alignment80), hbox56);
  240. label157 = gtk_label_new (_(" Query : "));
  241. gtk_widget_set_name (label157, "label157");
  242. gtk_widget_show (label157);
  243. gtk_box_pack_start (GTK_BOX (hbox56), label157, FALSE, FALSE, 0);
  244. t_probe = gtk_entry_new ();
  245. gtk_widget_set_name (t_probe, "t_probe");
  246. gtk_widget_show (t_probe);
  247. gtk_box_pack_start (GTK_BOX (hbox56), t_probe, TRUE, TRUE, 0);
  248. if (choose_t)
  249. gtk_entry_set_text (GTK_ENTRY (t_probe), choose_t->probe);
  250. dialog_action_area7 = GTK_DIALOG (connectionpool)->action_area;
  251. gtk_widget_set_name (dialog_action_area7, "dialog_action_area7");
  252. gtk_widget_show (dialog_action_area7);
  253. gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area7), GTK_BUTTONBOX_END);
  254. b_cancel = gtk_button_new_from_stock ("gtk-cancel");
  255. gtk_widget_set_name (b_cancel, "b_cancel");
  256. gtk_widget_show (b_cancel);
  257. gtk_dialog_add_action_widget (GTK_DIALOG (connectionpool), b_cancel, GTK_RESPONSE_CANCEL);
  258. GTK_WIDGET_SET_FLAGS (b_cancel, GTK_CAN_DEFAULT);
  259. b_finish = gtk_button_new_from_stock ("gtk-ok");
  260. gtk_widget_set_name (b_finish, "b_finish");
  261. gtk_widget_show (b_finish);
  262. gtk_dialog_add_action_widget (GTK_DIALOG (connectionpool), b_finish, GTK_RESPONSE_OK);
  263. GTK_WIDGET_SET_FLAGS (b_finish, GTK_CAN_DEFAULT);
  264. /* Store pointers to all widgets, for use by lookup_widget(). */
  265. GLADE_HOOKUP_OBJECT_NO_REF (connectionpool, connectionpool, "connectionpool");
  266. GLADE_HOOKUP_OBJECT_NO_REF (connectionpool, dialog_vbox7, "dialog_vbox7");
  267. GLADE_HOOKUP_OBJECT (connectionpool, frame1, "frame1");
  268. GLADE_HOOKUP_OBJECT (connectionpool, alignment76, "alignment76");
  269. GLADE_HOOKUP_OBJECT (connectionpool, vbox40, "vbox40");
  270. GLADE_HOOKUP_OBJECT (connectionpool, frame93, "frame93");
  271. GLADE_HOOKUP_OBJECT (connectionpool, alignment77, "alignment77");
  272. GLADE_HOOKUP_OBJECT (connectionpool, label154, "label154");
  273. GLADE_HOOKUP_OBJECT (connectionpool, frame94, "frame94");
  274. GLADE_HOOKUP_OBJECT (connectionpool, alignment78, "alignment78");
  275. GLADE_HOOKUP_OBJECT (connectionpool, hbox55, "hbox55");
  276. GLADE_HOOKUP_OBJECT (connectionpool, label156, "label156");
  277. GLADE_HOOKUP_OBJECT (connectionpool, t_cptimeout, "t_cptimeout");
  278. GLADE_HOOKUP_OBJECT (connectionpool, frame95, "frame95");
  279. GLADE_HOOKUP_OBJECT (connectionpool, alignment79, "alignment79");
  280. GLADE_HOOKUP_OBJECT (connectionpool, label155, "label155");
  281. GLADE_HOOKUP_OBJECT (connectionpool, frame96, "frame96");
  282. GLADE_HOOKUP_OBJECT (connectionpool, alignment80, "alignment80");
  283. GLADE_HOOKUP_OBJECT (connectionpool, hbox56, "hbox56");
  284. GLADE_HOOKUP_OBJECT (connectionpool, label157, "label157");
  285. GLADE_HOOKUP_OBJECT (connectionpool, t_probe, "t_probe");
  286. GLADE_HOOKUP_OBJECT (connectionpool, flabel1, "flabel1");
  287. GLADE_HOOKUP_OBJECT_NO_REF (connectionpool, dialog_action_area7, "dialog_action_area7");
  288. GLADE_HOOKUP_OBJECT (connectionpool, b_cancel, "b_cancel");
  289. GLADE_HOOKUP_OBJECT (connectionpool, b_finish, "b_finish");
  290. /* Finish button events */
  291. gtk_signal_connect (GTK_OBJECT (b_finish), "clicked",
  292. GTK_SIGNAL_FUNC (connectionpool_finish_clicked), choose_t);
  293. /* Cancel button events */
  294. gtk_signal_connect (GTK_OBJECT (b_cancel), "clicked",
  295. GTK_SIGNAL_FUNC (connectionpool_cancel_clicked), choose_t);
  296. /* Close window button events */
  297. gtk_signal_connect (GTK_OBJECT (connectionpool), "delete_event",
  298. GTK_SIGNAL_FUNC (delete_event), choose_t);
  299. gtk_signal_connect (GTK_OBJECT (connectionpool), "destroy",
  300. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  301. choose_t->timeout_entry = t_cptimeout;
  302. choose_t->probe_entry = t_probe;
  303. choose_t->mainwnd = connectionpool;
  304. gtk_widget_show_all (connectionpool);
  305. gtk_main ();
  306. return choose_t->changed;
  307. }