1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of thiz file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of thiz file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use thiz file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under thiz License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
40
#include <sys/types.h>
41
#include <sys/socket.h>
45
#include "sge_hostname.h"
47
#include "sge_stdlib.h"
48
#include "sge_string.h"
49
#include "sge_unistd.h"
50
#include "sge_answer.h"
57
u_long32 sge_qmaster_port;
58
u_long32 sge_execd_port;
60
bool qmaster_internal;
63
static bool sge_env_state_setup(sge_env_state_class_t *thiz,
66
u_long32 sge_qmaster_port,
67
u_long32 sge_execd_port,
69
bool is_qmaster_internal,
70
sge_error_class_t *eh);
71
static void sge_env_state_destroy(void *theState);
72
static void sge_env_state_dprintf(sge_env_state_class_t *thiz);
73
static const char* get_sge_root(sge_env_state_class_t *thiz);
74
static const char* get_sge_cell(sge_env_state_class_t *thiz);
75
static u_long32 get_sge_qmaster_port(sge_env_state_class_t *thiz);
76
static u_long32 get_sge_execd_port(sge_env_state_class_t *thiz);
77
static bool is_from_services(sge_env_state_class_t *thiz);
78
static bool is_qmaster_internal(sge_env_state_class_t *thiz);
79
static void set_sge_root(sge_env_state_class_t *thiz, const char *sge_root);
80
static void set_sge_cell(sge_env_state_class_t *thiz, const char *sge_cell);
81
static void set_from_services(sge_env_state_class_t *thiz, bool from_services);
82
static void set_qmaster_internal(sge_env_state_class_t *thiz, bool qmaster_internal);
83
static void set_sge_qmaster_port(sge_env_state_class_t *thiz, u_long32 sge_qmaster_port);
84
static void set_sge_execd_port(sge_env_state_class_t *thiz, u_long32 sge_qmaster_port);
86
sge_env_state_class_t *sge_env_state_class_create(const char *sge_root, const char *sge_cell, int sge_qmaster_port, int sge_execd_port, bool from_services, bool qmaster_internal, sge_error_class_t *eh)
88
sge_env_state_class_t *ret = (sge_env_state_class_t *)sge_malloc(sizeof(sge_env_state_class_t));
90
DENTER(TOP_LAYER, "sge_env_state_class_create");
92
eh->error(eh, STATUS_EMALLOC, ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
97
ret->dprintf = sge_env_state_dprintf;
99
ret->get_sge_root = get_sge_root;
100
ret->get_sge_cell = get_sge_cell;
101
ret->get_sge_qmaster_port = get_sge_qmaster_port;
102
ret->get_sge_execd_port = get_sge_execd_port;
103
ret->is_from_services = is_from_services;
104
ret->is_qmaster_internal = is_qmaster_internal;
106
ret->set_sge_root = set_sge_root;
107
ret->set_sge_cell = set_sge_cell;
108
ret->set_sge_qmaster_port = set_sge_qmaster_port;
109
ret->set_sge_execd_port = set_sge_execd_port;
111
ret->sge_env_state_handle = (sge_env_state_t*)sge_malloc(sizeof(sge_env_state_t));
112
if (ret->sge_env_state_handle == NULL) {
113
eh->error(eh, STATUS_EMALLOC, ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
114
sge_env_state_class_destroy(&ret);
118
memset(ret->sge_env_state_handle, 0, sizeof(sge_env_state_t));
120
if (!sge_env_state_setup(ret, sge_root, sge_cell, sge_qmaster_port, sge_execd_port, from_services, qmaster_internal, eh)) {
121
sge_env_state_class_destroy(&ret);
130
void sge_env_state_class_destroy(sge_env_state_class_t **pst)
132
DENTER(TOP_LAYER, "sge_env_state_class_destroy");
138
sge_env_state_destroy((*pst)->sge_env_state_handle);
144
static bool sge_env_state_setup(sge_env_state_class_t *thiz, const char *sge_root, const char *sge_cell, u_long32 sge_qmaster_port, u_long32 sge_execd_port, bool from_services, bool qmaster_internal, sge_error_class_t *eh)
146
DENTER(TOP_LAYER, "sge_env_state_setup");
148
thiz->set_sge_qmaster_port(thiz, sge_qmaster_port);
149
thiz->set_sge_execd_port(thiz, sge_execd_port);
150
thiz->set_sge_root(thiz, sge_root);
151
thiz->set_sge_cell(thiz, sge_cell);
152
set_from_services(thiz, from_services);
153
set_qmaster_internal(thiz, qmaster_internal);
155
/*thiz->dprintf(thiz);*/
161
static void sge_env_state_destroy(void *theState)
163
sge_env_state_t *s = (sge_env_state_t *)theState;
165
DENTER(TOP_LAYER, "sge_env_state_destroy");
174
static void sge_env_state_dprintf(sge_env_state_class_t *thiz)
176
sge_env_state_t *es = (sge_env_state_t *)thiz->sge_env_state_handle;
178
DENTER(TOP_LAYER, "sge_env_state_dprintf");
180
DPRINTF(("sge_root >%s<\n", es->sge_root ? es->sge_root : "NA"));
181
DPRINTF(("sge_cell >%s<\n", es->sge_cell ? es->sge_cell : "NA"));
182
DPRINTF(("sge_qmaster_port >%d<\n", es->sge_qmaster_port));
183
DPRINTF(("sge_execd_port >%d<\n", es->sge_execd_port));
184
DPRINTF(("from_services >%s<\n", es->from_services ? "true" : "false"));
185
DPRINTF(("qmaster_internal >%s<\n", es->qmaster_internal ? "true" : "false"));
190
static const char* get_sge_root(sge_env_state_class_t *thiz)
192
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
196
static const char* get_sge_cell(sge_env_state_class_t *thiz)
198
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
202
static u_long32 get_sge_qmaster_port(sge_env_state_class_t *thiz)
204
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
205
return es->sge_qmaster_port;
208
static u_long32 get_sge_execd_port(sge_env_state_class_t *thiz)
210
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
211
return es->sge_execd_port;
214
static bool is_from_services(sge_env_state_class_t *thiz)
216
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
217
return es->from_services;
220
static bool is_qmaster_internal(sge_env_state_class_t *thiz)
222
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
223
return es->qmaster_internal;
226
static void set_sge_root(sge_env_state_class_t *thiz, const char *sge_root)
228
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
229
es->sge_root = sge_strdup(es->sge_root, sge_root);
232
static void set_sge_cell(sge_env_state_class_t *thiz, const char *sge_cell)
234
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
235
es->sge_cell = sge_strdup(es->sge_cell, sge_cell);
238
static void set_sge_qmaster_port(sge_env_state_class_t *thiz, u_long32 sge_qmaster_port)
240
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
241
es->sge_qmaster_port = sge_qmaster_port;
244
static void set_sge_execd_port(sge_env_state_class_t *thiz, u_long32 sge_execd_port)
246
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
247
es->sge_execd_port = sge_execd_port;
250
static void set_from_services(sge_env_state_class_t *thiz, bool from_services)
252
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
253
es->from_services = from_services;
256
static void set_qmaster_internal(sge_env_state_class_t *thiz, bool qmaster_internal)
258
sge_env_state_t *es = (sge_env_state_t *) thiz->sge_env_state_handle;
259
es->qmaster_internal = qmaster_internal;