Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
032abec57d14b6cbef291f2a957e25e13a5e85a5
[simgrid.git] / src / gras / Virtu / rl_process.c
1 /* $Id$ */
2
3 /* process_rl - GRAS process handling on real life                          */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "gras_modinter.h" /* module initialization interface */
11 #include "gras/Virtu/virtu_rl.h"
12 #include "portable.h"
13
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_virtu_process);
15
16 /* globals */
17 static gras_procdata_t *_gras_procdata = NULL;
18 XBT_EXPORT_NO_IMPORT(char const *) _gras_procname = NULL;
19 static xbt_dict_t _process_properties = NULL;
20 static xbt_dict_t _host_properties = NULL;
21
22 /* the environment, as specified by the opengroup, used to initialize the process properties */
23 #ifdef DARWIN
24 #  include <crt_externs.h>
25 #  define environ (*_NSGetEnviron())
26 #endif
27
28 extern char **environ;
29
30 void gras_process_init() {
31   char **env_iter;
32   _gras_procdata=xbt_new0(gras_procdata_t,1);
33   gras_procdata_init();
34    
35   /* initialize the host & process properties */
36   _host_properties = xbt_dict_new();
37   _process_properties = xbt_dict_new();
38   env_iter = environ;
39   while (*env_iter) {
40      char *equal, *buf = xbt_strdup(*env_iter);
41      equal = strchr(buf, '=');
42      if (!equal) {
43         WARN1("The environment contains an entry without '=' char: %s (ignore it)",*env_iter);
44         continue;
45      }
46      *equal = '\0';
47      xbt_dict_set(_process_properties,buf,xbt_strdup(equal + 1),xbt_free_f);
48      free(buf);
49      env_iter++;
50   }   
51 }
52 void gras_process_exit() {
53   gras_procdata_exit();
54   free(_gras_procdata);
55   xbt_dict_free(&_process_properties);
56 }
57
58 const char *xbt_procname(void) {
59   if(_gras_procname) return _gras_procname;
60   else return "";
61 }
62
63 int gras_os_getpid(void) {
64 #ifdef _WIN32
65    return (long int) GetCurrentProcessId();
66 #else
67    return (long int) getpid();
68 #endif
69 }
70
71 /* **************************************************************************
72  * Process data
73  * **************************************************************************/
74
75 gras_procdata_t *gras_procdata_get(void) {
76   xbt_assert0(_gras_procdata,"Run gras_process_init (ie, gras_init)!");
77
78   return _gras_procdata;
79 }
80
81 void gras_agent_spawn(const char *name, void *data, 
82                       xbt_main_func_t code, int argc, char *argv[], xbt_dict_t properties) {
83    THROW_UNIMPLEMENTED;
84 }
85
86 /* **************************************************************************
87  * Properties
88  * **************************************************************************/
89
90 const char* gras_process_property_value(const char* name) {
91    return xbt_dict_get_or_null(_process_properties,name);
92 }
93 xbt_dict_t gras_process_properties(void) {
94    return _process_properties;
95 }
96
97 const char* gras_os_host_property_value(const char* name) {
98    return xbt_dict_get_or_null(_host_properties,name);
99 }
100 xbt_dict_t gras_os_host_properties(void) {
101    return _host_properties;
102 }