File: globus_redia.c

package info (click to toggle)
globus-common 18.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,684 kB
  • sloc: ansic: 36,506; sh: 4,534; makefile: 354; perl: 151
file content (218 lines) | stat: -rw-r--r-- 5,895 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "globus_common.h"
#include <ltdl.h>

static char * g_edge_label = "";
static char * g_outfile = "-";
static char * g_txt_file = "-";
static int g_flag = GLOBUS_STATE_DIA_NO_DUPLICATES | GLOBUS_STATE_DIA_NUMBER_LABELS;

static
globus_result_t
redia_l_opts_unknown(
   globus_options_handle_t             opts_handle,
    void *                              unknown_arg,
    int                                 argc,
    char **                             argv)
{
    return GLOBUS_SUCCESS;
/*
    return globus_error_put(globus_error_construct_error(
        NULL,
        NULL,
        2,
        __FILE__,
        "redia_l_opts_unknown",
        __LINE__,
        "Unknown parameter: %s",
        unknown_arg));
*/
}

static
globus_result_t
redia_l_opts_help(
    globus_options_handle_t             opts_handle,
    char *                              cmd,
    char **                             opt,
    void *                              arg,
    int *                               out_parms_used)
{
    fprintf(stdout, "globus-redia [options] <library name> <symbol name>\n");
    fprintf(stdout, "options:\n");
    globus_options_help(opts_handle);

    exit(0);
}


static
globus_result_t
redia_l_opts_edge_name(
    globus_options_handle_t             opts_handle,
    char *                              cmd,
    char **                             opt,
    void *                              arg,
    int *                               out_parms_used)
{
    g_flag |= GLOBUS_STATE_DIA_EDGE_EVENT;
    *out_parms_used = 0;
    return GLOBUS_SUCCESS;
}

static
globus_result_t
redia_l_opts_edge_desc(
    globus_options_handle_t             opts_handle,
    char *                              cmd,
    char **                             opt,
    void *                              arg,
    int *                               out_parms_used)
{
    g_flag |= GLOBUS_STATE_DIA_EDGE_FUNC;
    *out_parms_used = 0;
    return GLOBUS_SUCCESS;
}

static
globus_result_t
redia_l_opts_edge_label(
    globus_options_handle_t             opts_handle,
    char *                              cmd,
    char **                             opt,
    void *                              arg,
    int *                               out_parms_used)
{
    g_edge_label = opt[0];
    *out_parms_used = 1;
    return GLOBUS_SUCCESS;
}

static
globus_result_t
redia_l_opts_txt_file(
    globus_options_handle_t             opts_handle,
    char *                              cmd,
    char **                             opt,
    void *                              arg,
    int *                               out_parms_used)
{
    g_txt_file = opt[0];
    *out_parms_used = 1;
    return GLOBUS_SUCCESS;
}

static
globus_result_t
redia_l_opts_outfile(
    globus_options_handle_t             opts_handle,
    char *                              cmd,
    char **                             opt,
    void *                              arg,
    int *                               out_parms_used)
{
    g_outfile = opt[0];
    *out_parms_used = 1;
    return GLOBUS_SUCCESS;
}


globus_options_entry_t                   redia_l_opts_table[] =
{
    {"edge-name", "en", NULL, "",
        "use the library associated edge names",
        0, redia_l_opts_edge_name},
    {"edge-func", "ef", NULL, "",
        "use the function handler as the edge name",
        0, redia_l_opts_edge_desc},
    {"edge-label", "el", NULL, "",
        "additional edge directives",
        0, redia_l_opts_edge_label},
    {"outfile", "o", NULL, "",
        "outfile for dot format",
        1, redia_l_opts_outfile},
    {"txt-outfile", "to", NULL, "",
        "text file output",
        1, redia_l_opts_txt_file},
    {"help", "?", NULL, "",
        "print usage information",
        0, redia_l_opts_help},
    {NULL}
};


int
main(int argc, char ** argv)
{
    char *                              lib_name;
    char *                              symbol_name;
    int                                 rc;
    globus_state_extension_handle_t *   ext_data;
    globus_result_t                     result;
    globus_state_handle_t               handle;
    lt_dlhandle                         dlo_h;
    void *                              sym_handle;
    globus_options_handle_t             opt_h;

    globus_options_init(
        &opt_h, redia_l_opts_unknown, NULL);

    globus_options_add_table(opt_h, redia_l_opts_table, NULL);
    result = globus_options_command_line_process(opt_h, argc, argv);
    if(result != GLOBUS_SUCCESS)
    {
        exit(1);
    }

    if (argc < 3)
    {
        fprintf(stderr, "Missing parameters lib_name or symbol_name\n");
        exit(1);
    }

    lib_name = argv[argc-2];
    symbol_name = argv[argc-1];

    rc = globus_module_activate(GLOBUS_COMMON_MODULE);
    if(rc != 0)
    {
        fprintf(stderr, "Failed to activate common\n");
        exit(1);
    }

    dlo_h = lt_dlopenext(lib_name);
    if(dlo_h == NULL)
    {
        fprintf(stderr, "Failed to dlopen %s\n%s\n", lib_name, lt_dlerror());
        exit(1);
    }

    sym_handle = lt_dlsym(dlo_h, symbol_name);
    if(sym_handle == NULL)
    {
        fprintf(stderr, "Failed to dlsym %s\n%s\n", symbol_name, lt_dlerror());
        exit(1);
    }

    ext_data = (globus_state_extension_handle_t *) sym_handle;

    fprintf(stderr, "Found %s, name %s\n", symbol_name, ext_data->name);

    fprintf(stderr, "writing to file %s\n", g_outfile);

    result = globus_states_init(&handle, ext_data->init_handler);
    if(result != GLOBUS_SUCCESS)
    {
        fprintf(stderr, "Init handler returned with an error\n");
        exit(1);
    }

    /* call print function */ 
    rc = globus_state_make_graph(
        handle, g_outfile, g_txt_file, g_flag, g_edge_label); 
    if(rc != 0)
    {
        fprintf(stderr, "Failed to make graph in file %s\n", g_outfile);
        exit(1);
    }
    return 0;
}