|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/connect/ncbi_host_info.c |
source navigation diff markup identifier search freetext search file search |
1 /* $Id: ncbi_host_info.c,v 6.13 2009/02/03 16:39:35 kazimird Exp $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Anton Lavrentiev
27 *
28 * File Description:
29 * NCBI host info constructor and getters
30 *
31 */
32
33 #include "ncbi_lbsmd.h"
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifndef M_PI
39 /* Not defined on MacOS.9 :-( */
40 # define M_PI 3.14159265358979323846
41 #endif
42
43 #define HINFO_MAGIC M_PI
44
45
46 HOST_INFO HINFO_Create(unsigned int addr, const void* hinfo, size_t hinfo_size,
47 const char* env, const char* arg, const char* val)
48 {
49 SHOST_Info* host_info;
50 size_t size;
51 size_t e_s;
52 size_t a_s;
53 size_t v_s;
54 char* s;
55
56 if (!hinfo)
57 return 0;
58 e_s = env && *env ? strlen(env) + 1 : 0;
59 a_s = arg && *arg ? strlen(arg) + 1 : 0;
60 v_s = a_s && val ? strlen(val) + 1 : 0;
61 size = sizeof(*host_info) + hinfo_size;
62 if (!(host_info = (SHOST_Info*) calloc(1, size + e_s + a_s + v_s)))
63 return 0;
64 host_info->addr = addr;
65 memcpy((char*) host_info + sizeof(*host_info), hinfo, hinfo_size);
66 s = (char*) host_info + size;
67 if (e_s) {
68 host_info->env = (const char*) memcpy(s, env, e_s);
69 s += e_s;
70 }
71 if (a_s) {
72 host_info->arg = (const char*) memcpy(s, arg, a_s);
73 s += a_s;
74 }
75 if (v_s) {
76 host_info->val = (const char*) memcpy(s, val, v_s);
77 s += v_s;
78 }
79 host_info->pad = HINFO_MAGIC;
80 return host_info;
81 }
82
83
84 unsigned int HINFO_HostAddr(const HOST_INFO host_info)
85 {
86 if (!host_info || host_info->pad != HINFO_MAGIC)
87 return 0;
88 return host_info->addr;
89 }
90
91
92 int HINFO_CpuCount(const HOST_INFO host_info)
93 {
94 if (!host_info || host_info->pad != HINFO_MAGIC)
95 return -1;
96 return LBSM_HINFO_CpuCount(host_info);
97 }
98
99
100 int HINFO_CpuUnits(const HOST_INFO host_info)
101 {
102 if (!host_info || host_info->pad != HINFO_MAGIC)
103 return -1;
104 return LBSM_HINFO_CpuUnits(host_info);
105 }
106
107
108 double HINFO_CpuClock(const HOST_INFO host_info)
109 {
110 if (!host_info || host_info->pad != HINFO_MAGIC)
111 return 0.0;
112 return LBSM_HINFO_CpuClock(host_info);
113 }
114
115 int HINFO_TaskCount(const HOST_INFO host_info)
116 {
117 if (!host_info || host_info->pad != HINFO_MAGIC)
118 return -1;
119 return LBSM_HINFO_TaskCount(host_info);
120 }
121
122
123 int HINFO_Memusage(const HOST_INFO host_info, double memusage[5])
124 {
125 memset(memusage, 0, sizeof(memusage[0]) * 5);
126 if (!host_info || host_info->pad != HINFO_MAGIC)
127 return 0;
128 return LBSM_HINFO_Memusage(host_info, memusage);
129 }
130
131
132 int HINFO_MachineParams(const HOST_INFO host_info, SHINFO_Params* p)
133 {
134 memset(p, 0, sizeof(*p));
135 if (!host_info || host_info->pad != HINFO_MAGIC)
136 return 0;
137 return LBSM_HINFO_MachineParams(host_info, p);
138 }
139
140
141 int/*bool*/ HINFO_LoadAverage(const HOST_INFO host_info, double lavg[2])
142 {
143 memset(lavg, 0, sizeof(lavg[0]) * 2);
144 if (!host_info || host_info->pad != HINFO_MAGIC)
145 return 0;
146 return LBSM_HINFO_LoadAverage(host_info, lavg);
147 }
148
149
150 int/*bool*/ HINFO_Status(const HOST_INFO host_info, double status[2])
151 {
152 memset(status, 0, sizeof(status[0]) * 2);
153 if (!host_info || host_info->pad != HINFO_MAGIC)
154 return 0;
155 return LBSM_HINFO_Status(host_info, status);
156 }
157
158
159 const char* HINFO_Environment(const HOST_INFO host_info)
160 {
161 if (!host_info || host_info->pad != HINFO_MAGIC)
162 return 0;
163 return host_info->env;
164 }
165
166
167 const char* HINFO_AffinityArgument(const HOST_INFO host_info)
168 {
169 if (!host_info || host_info->pad != HINFO_MAGIC)
170 return 0;
171 return host_info->arg;
172 }
173
174
175 const char* HINFO_AffinityArgvalue(const HOST_INFO host_info)
176 {
177 if (!host_info || host_info->pad != HINFO_MAGIC)
178 return 0;
179 return host_info->val;
180 }
181 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |