~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to connect/ncbi_host_info.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: ncbi_host_info.c,v 6.6 2003/01/17 19:44:46 lavr 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
 
 
44
typedef struct SHostInfoTag {
 
45
    const char* env;
 
46
    double      pad;    /* for proper 'hinfo' alignment; also as a magic */
 
47
    char        hinfo[1];
 
48
} SHOST_Info;
 
49
 
 
50
 
 
51
HOST_INFO HINFO_Create(const void* hinfo, size_t hinfo_size, const char* env)
 
52
{
 
53
    SHOST_Info* host_info;
 
54
    size_t      size;
 
55
 
 
56
    if (!hinfo)
 
57
        return 0;
 
58
    if (env && !*env)
 
59
        env = 0;
 
60
    size = sizeof(*host_info) + hinfo_size;
 
61
    if (!(host_info = (SHOST_Info*) malloc(size + (env ? strlen(env) : 0))))
 
62
        return 0;
 
63
    host_info->env = env ? strcpy((char*) host_info + size - 1, env) : 0;
 
64
    host_info->pad = M_PI;
 
65
    memcpy(host_info->hinfo, hinfo, hinfo_size);
 
66
    return host_info;
 
67
}
 
68
 
 
69
 
 
70
int HINFO_CpuCount(HOST_INFO host_info)
 
71
{
 
72
    if (!host_info || host_info->pad != M_PI)
 
73
        return -1;
 
74
    return LBSM_HINFO_CpuCount(host_info->hinfo);
 
75
}
 
76
 
 
77
 
 
78
int HINFO_TaskCount(HOST_INFO host_info)
 
79
{
 
80
    if (!host_info || host_info->pad != M_PI)
 
81
        return -1;
 
82
    return LBSM_HINFO_TaskCount(host_info->hinfo);
 
83
}
 
84
 
 
85
 
 
86
int/*bool*/ HINFO_LoadAverage(HOST_INFO host_info, double lavg[2])
 
87
{
 
88
    if (!host_info || host_info->pad != M_PI)
 
89
        return 0;
 
90
    return LBSM_HINFO_LoadAverage(host_info->hinfo, lavg);
 
91
}
 
92
 
 
93
 
 
94
int/*bool*/ HINFO_Status(HOST_INFO host_info, double status[2])
 
95
{
 
96
    if (!host_info || host_info->pad != M_PI)
 
97
        return 0;
 
98
    return LBSM_HINFO_Status(host_info->hinfo, status);
 
99
}
 
100
 
 
101
 
 
102
int/*bool*/ HINFO_BLASTParams(HOST_INFO host_info, unsigned int blast[8])
 
103
{
 
104
    if (!host_info || host_info->pad != M_PI)
 
105
        return 0;
 
106
    return LBSM_HINFO_BLASTParams(host_info->hinfo, blast);
 
107
}
 
108
 
 
109
 
 
110
const char* HINFO_Environment(HOST_INFO host_info)
 
111
{
 
112
    if (!host_info || host_info->pad != M_PI)
 
113
        return 0;
 
114
    return host_info->env;
 
115
}
 
116
 
 
117
 
 
118
/*
 
119
 * --------------------------------------------------------------------------
 
120
 * $Log: ncbi_host_info.c,v $
 
121
 * Revision 6.6  2003/01/17 19:44:46  lavr
 
122
 * Reduce dependencies
 
123
 *
 
124
 * Revision 6.5  2002/10/29 22:19:07  lavr
 
125
 * Fix typo in the file description
 
126
 *
 
127
 * Revision 6.4  2002/10/29 00:31:08  lavr
 
128
 * Fixed hinfo overflow from the use of precalculated size
 
129
 *
 
130
 * Revision 6.3  2002/10/28 21:55:38  lavr
 
131
 * LBSM_HINFO introduced for readability to replace plain "const void*"
 
132
 *
 
133
 * Revision 6.2  2002/10/28 20:49:04  lavr
 
134
 * Conditionally define M_PI if it is not already defined by <math.h>
 
135
 *
 
136
 * Revision 6.1  2002/10/28 20:13:45  lavr
 
137
 * Initial revision
 
138
 *
 
139
 * ==========================================================================
 
140
 */