2
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; version 2 of the
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21
#ifndef __CHASSIS_FRONTEND_H__
22
#define __CHASSIS_FRONTEND_H__
25
#define CHASSIS_NEWLINE "\r\n"
27
#define CHASSIS_NEWLINE "\n"
32
#include "chassis-exports.h"
33
#include "chassis-options.h"
37
* a collections of common functions used by chassis frontends
39
* take a look at mysql-proxy-cli.c on what sequence to call these functions
43
* setup glib, gthread and gmodule
45
* may abort of glib headers and glib libs don't match
47
* @return 0 on success, -1 on error
49
CHASSIS_API int chassis_frontend_init_glib(void);
56
* @return 0 on success, -1 on error
58
CHASSIS_API int chassis_frontend_init_win32(void);
63
* if *_basedir is not NULL, don't change it
64
* otherwise extract the basedir from the prg_name
66
* @param prg_name program-name (usually argv[0])
67
* @param _basedir user-supplied basedir
68
* @return 0 on success, -1 on error
70
CHASSIS_API int chassis_frontend_init_basedir(const char *prg_name, char **_base_dir);
75
* @param filename name of the configfile
76
* @param gerr a pointer to a clean GError * or NULL in case the possible error should be ignored
78
* @see g_key_file_free
80
CHASSIS_API GKeyFile *chassis_frontend_open_config_file(const char *filename, GError **gerr);
82
CHASSIS_API int chassis_frontend_init_plugin_dir(char **_plugin_dir, const char *base_dir);
83
CHASSIS_API int chassis_frontend_init_lua_path(const char *set_path, const char *base_dir, char **lua_subdirs);
84
CHASSIS_API int chassis_frontend_init_lua_cpath(const char *set_path, const char *base_dir, char **lua_subdirs);
87
* extract --version and --defaults-file from comandline options
89
* @param option_ctx a fresh GOptionContext
90
* @param argc_p pointer to the number of args in argv_p
91
* @param argv_p pointer to arguments to parse
92
* @param print_version pointer to int to set if --version is specified
93
* @param config_file pointer to char * to store if --defaults-file is specified
94
* @param gerr a pointer to a clean GError * or NULL in case the possible error should be ignored
96
CHASSIS_API int chassis_frontend_init_base_options(GOptionContext *option_ctx,
97
int *argc_p, char ***argv_p,
105
* loads the plugins from 'plugin_names' from the 'plugin_dir' and store their chassis_plugin structs
108
* the filename of the plugin is constructed based depending on the platform
110
* @param plugins empty array
111
* @param plugin_dir directory to load the plugins from
112
* @param plugin_names NULL terminated list of plugin names
114
* @see chassis_frontend_init_plugins
116
CHASSIS_API int chassis_frontend_load_plugins(GPtrArray *plugins,
117
const gchar *plugin_dir,
118
gchar **plugin_names);
121
* init the loaded plugins and setup their config
123
* @param plugins array of chassis_plugin structs
124
* @param option_ctx a fresh GOptionContext
125
* @param argc_p pointer to the number of args in argv_p
126
* @param argv_p pointer to arguments to parse
127
* @param keyfile the configfile
128
* @param base_dir base directory
129
* @param gerr a pointer to a clean GError * or NULL in case the possible error should be ignored
131
* @see chassis_frontend_init_basedir, chassis_frontend_init_plugins
133
CHASSIS_API int chassis_frontend_init_plugins(GPtrArray *plugins,
134
GOptionContext *option_ctx,
135
int *argc_p, char ***argv_p,
137
const char *keyfile_section_name,
138
const char *base_dir,
142
* print the version of the program
144
CHASSIS_API int chassis_frontend_print_version(void);
147
* print the versions of the initialized plugins
149
CHASSIS_API int chassis_frontend_print_plugin_versions(GPtrArray *plugins);
151
CHASSIS_API void chassis_frontend_print_lua_version();
154
* write the PID to a file
156
* @param pid_file name of the PID file
158
* @return 0 on success, -1 on error
160
CHASSIS_API int chassis_frontend_write_pidfile(const char *pid_file, GError **gerr);
162
CHASSIS_API int chassis_options_set_cmdline_only_options(chassis_options_t *opts,