GCOV Execution Analysis for domain.c

The left column is the number of times the code was executed during the unit test suites.

Exec CodeLine #
 
Source:domain.c
1
 
Graph:.libs/domain.gcno
2
 
Data:.libs/domain.gcda
3
 
Runs:378
4
 
Programs:378
5
 
/*      -*- linux-c -*-
6
 
 *
7
 
 * (C) Copyright IBM Corp. 2004
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  This
12
 
 * file and program are licensed under a BSD style license.  See
13
 
 * the Copying file included with the OpenHPI distribution for
14
 
 * full licensing terms.
15
 
 *
16
 
 * Author(s):
17
 
 *      Renier Morales < address removed >
18
 
 *
19
 
 */
20
 
21
 
#include <oh_domain.h>
22
 
#include <oh_session.h>
23
 
#include <oh_error.h>
24
 
#include <oh_utils.h>
25
 
#include <string.h>
26
 
27
 
#define OH_FIRST_DOMAIN 1
28
 
29
 
struct oh_domain_table oh_domains = {        
30
 
        .table = NULL,
31
 
        .lock = G_STATIC_REC_MUTEX_INIT,
32
 
};
33
 
34
 
/**
35
 
 * oh_create_domain
36
 
 * @capabilities:
37
 
 * @isPeer:
38
 
 * @tag:
39
 
 *
40
 
 *
41
 
 *
42
 
 * Returns: Domain id of newly created domain, or 0 if failed to create.
43
 
 **/
44
 
SaHpiDomainIdT oh_create_domain(SaHpiDomainCapabilitiesT capabilities,
45
 
                                SaHpiBoolT is_peer,
46
 
                                SaHpiTextBufferT *tag)
47
374 
{
48
374 
        struct oh_domain *domain = NULL;
49
374 
        static SaHpiDomainIdT id = OH_FIRST_DOMAIN; /* domain ids will start at 1 */
50
 
51
374 
        domain = g_new0(struct oh_domain,1);
52
374 
        if (!domain) return 0;
53
 
54
374 
        domain->capabilities = capabilities;
55
374 
        domain->is_peer = is_peer;
56
374 
        oh_init_rpt(&(domain->rpt));
57
 
58
374 
        if (tag)
59
374 
                memcpy(&(domain->tag), tag, sizeof(SaHpiTextBufferT));
60
374 
        domain->del = oh_el_create(OH_EL_MAX_SIZE);
61
374 
        domain->sessions = g_array_sized_new(FALSE, TRUE,
62
 
                                             sizeof(SaHpiSessionIdT),
63
 
                                             OH_SESSION_PREALLOC);
64
 
65
374 
        g_static_rec_mutex_init(&(domain->lock));
66
 
67
374 
        if (!domain->del || !domain->sessions) {
68
0 
                g_free(domain->del);
69
0 
                g_array_free(domain->sessions, TRUE);
70
0 
                g_static_rec_mutex_free(&(domain->lock));
71
0 
                g_free(domain);
72
0 
                return 0;
73
 
        }
74
374 
        g_static_rec_mutex_lock(&(oh_domains.lock)); /* Locked domain table */
75
374 
        domain->id = id++;
76
374 
        g_hash_table_insert(oh_domains.table, &(domain->id), domain);
77
374 
        g_static_rec_mutex_unlock(&(oh_domains.lock));  /* Unlocked domain table */
78
 
79
374 
        return domain->id;
80
 
}
81
 
82
 
/**
83
 
 * oh_get_default_domain_id
84
 
 *
85
 
 * Returns:
86
 
 **/
87
 
SaHpiDomainIdT oh_get_default_domain_id()
88
13581 
{
89
13581 
        return (SaHpiDomainIdT)OH_FIRST_DOMAIN;
90
 
}
91
 
92
 
/**
93
 
 * oh_destroy_domain
94
 
 * @did:
95
 
 *
96
 
 *
97
 
 *
98
 
 * Returns:
99
 
 **/
100
 
SaErrorT oh_destroy_domain(SaHpiDomainIdT did)
101
0 
{
102
0 
        struct oh_domain *domain = NULL;
103
 
104
0 
        if (did < 1) return SA_ERR_HPI_INVALID_PARAMS;
105
 
106
0 
        g_static_rec_mutex_lock(&(oh_domains.lock)); /* Locked domain table */
107
0 
        domain = g_hash_table_lookup(oh_domains.table, &did);
108
0 
        if (!domain) {
109
0 
                g_static_rec_mutex_unlock(&(oh_domains.lock));
110
0 
                return SA_ERR_HPI_NOT_PRESENT;
111
 
        }
112
 
113
0 
        g_static_rec_mutex_lock(&(domain->lock));
114
0 
        g_hash_table_remove(oh_domains.table, &(domain->id));
115
0 
        g_static_rec_mutex_unlock(&(oh_domains.lock)); /* Unlocked domain table */
116
 
117
0 
        oh_flush_rpt(&(domain->rpt));
118
0 
        oh_el_close(domain->del);
119
0 
        g_array_free(domain->sessions, TRUE);
120
0 
        g_static_rec_mutex_unlock(&(domain->lock));
121
0 
        g_static_rec_mutex_free(&(oh_domains.lock)); /* Unlocked domain table */
122
 
        
123
0 
        g_free(domain);
124
 
125
0 
        return SA_OK;
126
 
}
127
 
128
 
/**
129
 
 * oh_get_domain
130
 
 * @did:
131
 
 *
132
 
 *
133
 
 *
134
 
 * Returns:
135
 
 **/
136
 
struct oh_domain *oh_get_domain(SaHpiDomainIdT did)
137
20152 
{
138
20152 
        struct oh_domain *domain = NULL;
139
 
140
20152 
        if (did < 1) return NULL;
141
 
        
142
 
        /* unspecified domain id always gives us id 1 */
143
20152 
        if (did == SAHPI_UNSPECIFIED_DOMAIN_ID) {
144
0 
                did = 1;
145
 
        }
146
 
147
20152 
        g_static_rec_mutex_lock(&(oh_domains.lock)); /* Locked domain table */
148
20152 
        domain = g_hash_table_lookup(oh_domains.table, &did);
149
20152 
        if (!domain) {
150
1 
                g_static_rec_mutex_unlock(&(oh_domains.lock));
151
1 
                return NULL;
152
 
        }
153
 
154
20151 
        g_static_rec_mutex_lock(&(domain->lock));
155
20151 
        g_static_rec_mutex_unlock(&(oh_domains.lock)); /* Unlocked domain table */
156
 
157
20151 
        return domain;
158
 
}
159
 
160
 
static void collect_domain_ids(gpointer key, gpointer value, gpointer user_data)
161
0 
{
162
0 
        struct oh_domain *domain = (struct oh_domain *)value;
163
0 
        GArray *data = (GArray *)user_data;
164
 
165
0 
        g_array_append_val(data, domain->id);
166
 
}
167
 
/**
168
 
 * oh_list_domains
169
 
 *
170
 
 *
171
 
 *
172
 
 * Returns:
173
 
 **/
174
 
GArray *oh_list_domains()
175
0 
{
176
0 
        dbg("Entering list_domains");
177
0 
        GArray *domain_ids = NULL;
178
 
179
0 
        domain_ids = g_array_new(FALSE, TRUE, sizeof(SaHpiDomainIdT));
180
0 
        if (!domain_ids) return NULL;
181
0 
        dbg("setup domain ids");
182
0 
        g_static_rec_mutex_lock(&(oh_domains.lock));
183
0 
        g_hash_table_foreach(oh_domains.table, collect_domain_ids, domain_ids);
184
0 
        dbg("Looping through table");
185
0 
        g_static_rec_mutex_unlock(&(oh_domains.lock));
186
 
187
0 
        return domain_ids;
188
 
}
189
 
190
 
/**
191
 
 * oh_release_domain
192
 
 * @domain:
193
 
 *
194
 
 *
195
 
 *
196
 
 * Returns:
197
 
 **/
198
 
SaErrorT oh_release_domain(struct oh_domain *domain)
199
20151 
{
200
20151 
        if (!domain) return SA_ERR_HPI_INVALID_PARAMS;
201
 
202
20151 
        g_static_rec_mutex_unlock(&(domain->lock));
203
 
204
20151 
        return SA_OK;
205
 
}
206