GCOV Execution Analysis for session.c

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

Exec CodeLine #
 
Source:session.c
1
 
Graph:.libs/session.gcno
2
 
Data:.libs/session.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_utils.h>
22
 
#include <oh_session.h>
23
 
#include <oh_domain.h>
24
 
#include <string.h>
25
 
26
 
struct oh_session_table oh_sessions = {        
27
 
        .table = NULL,
28
 
        .lock = G_STATIC_REC_MUTEX_INIT
29
 
};
30
 
31
 
static struct oh_event *oh_generate_hpi_event(void)
32
0 
{
33
0 
        struct oh_event *event = NULL;
34
 
35
0 
        event = g_new0(struct oh_event, 1);        
36
0 
        event->type = OH_ET_HPI;
37
0 
        event->u.hpi_event.res.ResourceId= SAHPI_UNSPECIFIED_RESOURCE_ID;
38
0 
        event->u.hpi_event.rdr.RecordId = SAHPI_ENTRY_UNSPECIFIED;
39
0 
        event->u.hpi_event.event.Source = SAHPI_UNSPECIFIED_RESOURCE_ID;
40
0 
        event->u.hpi_event.event.EventType = SAHPI_ET_HPI_SW;
41
0 
        event->u.hpi_event.event.Timestamp = SAHPI_TIME_UNSPECIFIED;
42
0 
        event->u.hpi_event.event.Severity = SAHPI_CRITICAL;
43
0 
        event->u.hpi_event.event.EventDataUnion.HpiSwEvent.MId =
44
 
                SAHPI_MANUFACTURER_ID_UNSPECIFIED;
45
0 
        event->u.hpi_event.event.EventDataUnion.HpiSwEvent.Type =
46
 
                SAHPI_HPIE_OTHER;
47
0 
        event->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.DataType =
48
 
                SAHPI_TL_TYPE_TEXT;
49
0 
        event->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.Language =
50
 
                SAHPI_TL_TYPE_TEXT;        
51
0 
        strcpy(event->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.Data,
52
 
                "This session is being destroyed now!");
53
0 
        event->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.DataLength =
54
 
                strlen(event->u.hpi_event.event.EventDataUnion.HpiSwEvent.EventData.Data);
55
 
56
0 
        return event;
57
 
}
58
 
59
 
/**
60
 
 * oh_create_session
61
 
 * @did:
62
 
 *
63
 
 *
64
 
 *
65
 
 * Returns:
66
 
 **/
67
 
SaHpiSessionIdT oh_create_session(SaHpiDomainIdT did)
68
374 
{
69
374 
        struct oh_session *session = NULL;
70
374 
        struct oh_domain *domain = NULL;
71
374 
        static SaHpiSessionIdT id = 1; /* Session ids will start at 1 */
72
 
73
374 
        if (did < 1) return 0;
74
 
75
374 
        session = g_new0(struct oh_session, 1);
76
374 
        if (!session) return 0;
77
 
78
374 
        session->did = did;
79
374 
        session->eventq = g_async_queue_new();
80
 
81
374 
        domain = oh_get_domain(did);
82
374 
        if (!domain) {
83
1 
                g_async_queue_unref(session->eventq);
84
1 
                g_free(session);
85
1 
                return 0;
86
 
        }
87
373 
        g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
88
373 
        session->id = id++;
89
373 
        g_hash_table_insert(oh_sessions.table, &(session->id), session);
90
373 
        g_array_append_val(domain->sessions, session->id);
91
373 
        g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */        
92
373 
        oh_release_domain(domain);
93
 
                
94
373 
        return session->id;
95
 
}
96
 
97
 
/**
98
 
 * oh_get_session_domain
99
 
 * @sid:
100
 
 *
101
 
 *
102
 
 *
103
 
 * Returns:
104
 
 **/
105
 
SaHpiDomainIdT oh_get_session_domain(SaHpiSessionIdT sid)
106
2730 
{
107
2730 
        struct oh_session *session = NULL;
108
2730 
        SaHpiDomainIdT did;
109
 
        
110
2730 
        if (sid < 1) return 0;
111
 
112
2730 
        g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
113
2730 
        session = g_hash_table_lookup(oh_sessions.table, &sid);
114
2730 
        if (!session) {
115
0 
                g_static_rec_mutex_unlock(&oh_sessions.lock);
116
0 
                return 0;
117
 
        }
118
 
        
119
2730 
        did = session->did;
120
2730 
        g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
121
 
        
122
 
123
2730 
        return did;
124
 
}
125
 
126
 
/**
127
 
 * oh_list_sessions
128
 
 * @did:
129
 
 *
130
 
 *
131
 
 *
132
 
 * Returns: A dynamically allocated array of session ids.
133
 
 * The caller needs to free this array when he is done with it.
134
 
 **/
135
 
GArray *oh_list_sessions(SaHpiDomainIdT did)
136
4405 
{
137
4405 
        struct oh_domain *domain = NULL;
138
4405 
        GArray *session_ids = NULL;
139
4405 
        guint i, length;
140
 
141
4405 
        if (did < 1) return NULL;
142
 
143
4405 
        dbg("About to get domain");
144
4405 
        domain = oh_get_domain(did);
145
4405 
        if (!domain) return NULL;
146
4405 
        dbg("Got domain");
147
 
        
148
4405 
        length = domain->sessions->len;
149
4405 
        session_ids = g_array_sized_new(FALSE, TRUE,
150
 
                                        sizeof(SaHpiSessionIdT),
151
 
                                        length);
152
 
        
153
8810 
        for (i = 0; i < length; i++) {
154
4405 
                g_array_append_val(session_ids,
155
 
                                   g_array_index(domain->sessions,
156
 
                                                 SaHpiSessionIdT,
157
 
                                                 i)
158
 
                                   );
159
 
        }
160
4405 
        oh_release_domain(domain);
161
 
162
4405 
        return session_ids;
163
 
}
164
 
165
 
/**
166
 
 * oh_get_session_state
167
 
 * @sid:
168
 
 * @state:
169
 
 *
170
 
 *
171
 
 *
172
 
 * Returns:
173
 
 **/
174
 
SaErrorT oh_get_session_subscription(SaHpiSessionIdT sid, SaHpiBoolT *state)
175
7588 
{
176
7588 
        struct oh_session *session = NULL;
177
 
178
7588 
        if (sid < 1 || (state == NULL)) return SA_ERR_HPI_INVALID_PARAMS;
179
 
180
7588 
        g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
181
7588 
        session = g_hash_table_lookup(oh_sessions.table, &sid);
182
7588 
        if (!session) {
183
62 
                g_static_rec_mutex_unlock(&oh_sessions.lock);
184
62 
                return SA_ERR_HPI_INVALID_SESSION;
185
 
        }
186
7526 
        *state = session->state;
187
7526 
        g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
188
 
189
7526 
        return SA_OK;
190
 
}
191
 
192
 
/**
193
 
 * oh_set_session_state
194
 
 * @sid:
195
 
 * @state:
196
 
 *
197
 
 *
198
 
 *
199
 
 * Returns:
200
 
 **/
201
 
SaErrorT oh_set_session_subscription(SaHpiSessionIdT sid, SaHpiBoolT state)
202
19 
{
203
19 
       struct oh_session *session = NULL;
204
 
205
19 
       if (sid < 1) return SA_ERR_HPI_INVALID_PARAMS;
206
 
207
19 
       g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
208
19 
       session = g_hash_table_lookup(oh_sessions.table, &sid);
209
19 
       if (!session) {
210
0 
               g_static_rec_mutex_unlock(&oh_sessions.lock);
211
0 
               return SA_ERR_HPI_INVALID_SESSION;
212
 
       }
213
19 
       session->state = state;
214
19 
       g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
215
 
216
19 
       return SA_OK;
217
 
}
218
 
219
 
/**
220
 
 * oh_queue_session_event
221
 
 * @sid:
222
 
 * @event:
223
 
 *
224
 
 *
225
 
 *
226
 
 * Returns:
227
 
 **/
228
 
SaErrorT oh_queue_session_event(SaHpiSessionIdT sid, struct oh_event *event)
229
2 
{      
230
2 
       struct oh_session *session = NULL;
231
2 
       struct oh_event *qevent = NULL;
232
 
233
2 
       if (sid < 1 || !event) return SA_ERR_HPI_INVALID_PARAMS;
234
 
235
2 
       qevent = g_memdup(event, sizeof(struct oh_event));
236
2 
       g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
237
2 
       session = g_hash_table_lookup(oh_sessions.table, &sid);
238
2 
       if (!session) {               
239
0 
               g_static_rec_mutex_unlock(&oh_sessions.lock);
240
0 
               g_free(qevent);
241
0 
               return SA_ERR_HPI_INVALID_SESSION;
242
 
       }
243
2 
       g_async_queue_push(session->eventq, qevent);
244
2 
       g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
245
 
246
2 
       return SA_OK;
247
 
}
248
 
249
 
/**
250
 
 * oh_dequeue_session_event
251
 
 * @sid:
252
 
 * @event:
253
 
 *
254
 
 *
255
 
 *
256
 
 * Returns:
257
 
 **/
258
 
SaErrorT oh_dequeue_session_event(SaHpiSessionIdT sid,
259
 
                                  SaHpiTimeoutT timeout,
260
 
                                  struct oh_event *event)
261
10 
{
262
10 
       struct oh_session *session = NULL;
263
10 
       struct oh_event *devent = NULL;
264
10 
       GTimeVal gfinaltime;
265
10 
       GAsyncQueue *eventq = NULL;
266
 
267
10 
       if (sid < 1 || (event == NULL)) return SA_ERR_HPI_INVALID_PARAMS;
268
 
269
10 
       g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
270
10 
       session = g_hash_table_lookup(oh_sessions.table, &sid);
271
10 
       if (!session) {
272
0 
               g_static_rec_mutex_unlock(&oh_sessions.lock);
273
0 
               return SA_ERR_HPI_INVALID_SESSION;
274
 
       }
275
10 
       eventq = session->eventq;
276
10 
       g_async_queue_ref(eventq);
277
10 
       g_static_rec_mutex_unlock(&oh_sessions.lock);
278
 
279
10 
       if (timeout == SAHPI_TIMEOUT_IMMEDIATE) {
280
10 
               devent = g_async_queue_try_pop(eventq);
281
0 
       } else if (timeout == SAHPI_TIMEOUT_BLOCK) {
282
0 
               devent = g_async_queue_pop(eventq); /* FIXME: Need to time this. */
283
 
       } else {               
284
0 
               g_get_current_time(&gfinaltime);
285
0 
               g_time_val_add(&gfinaltime, (glong) (timeout / 1000));
286
0 
               devent = g_async_queue_timed_pop(eventq, &gfinaltime);
287
 
       }
288
10 
       g_async_queue_unref(eventq);
289
 
290
10 
       if (devent) {
291
0 
               memcpy(event, devent, sizeof(struct oh_event));
292
0 
               g_free(devent);
293
0 
               return SA_OK;
294
 
       } else {
295
10 
               memset(event, 0, sizeof(struct oh_event));
296
10 
               return SA_ERR_HPI_TIMEOUT;
297
 
       }
298
 
}
299
 
300
 
/**
301
 
 * oh_destroy_session
302
 
 * @sid:
303
 
 *
304
 
 *
305
 
 *
306
 
 * Returns:
307
 
 **/
308
 
SaErrorT oh_destroy_session(SaHpiSessionIdT sid)
309
362 
{
310
362 
        struct oh_session *session = NULL;
311
362 
        struct oh_domain *domain = NULL;
312
362 
        SaHpiDomainIdT did;
313
362 
        gpointer event = NULL;
314
362 
        int i, len;
315
 
316
362 
        if (sid < 1) return SA_ERR_HPI_INVALID_PARAMS;
317
 
318
362 
        g_static_rec_mutex_lock(&oh_sessions.lock); /* Locked session table */
319
362 
        session = g_hash_table_lookup(oh_sessions.table, &sid);
320
362 
        if (!session) {
321
0 
                g_static_rec_mutex_unlock(&oh_sessions.lock);
322
0 
                return SA_ERR_HPI_INVALID_SESSION;
323
 
        }
324
 
325
362 
        g_hash_table_remove(oh_sessions.table, &(session->id));
326
362 
        g_static_rec_mutex_unlock(&oh_sessions.lock); /* Unlocked session table */
327
362 
        did = session->did;
328
 
329
 
        /* Finalize session */
330
362 
        len = g_async_queue_length(session->eventq);
331
362 
        if (len < 0) {
332
0 
                for (i = 0; i > len; i--) {
333
0 
                        g_async_queue_push(session->eventq, oh_generate_hpi_event());
334
 
                }
335
362 
        } else if (len > 0) {
336
4 
                for (i = 0; i < len; i++) {
337
2 
                        event = g_async_queue_try_pop(session->eventq);
338
2 
                        if (event) g_free(event);
339
2 
                        event = NULL;
340
 
                }
341
 
        }
342
362 
        g_async_queue_unref(session->eventq);
343
362 
        g_free(session);
344
 
345
 
        /* Update domain about session deletion. */
346
362 
        domain = oh_get_domain(did);
347
362 
        if (domain) {
348
362 
                len = domain->sessions->len;
349
362 
                for (i = 0; i < len; i++) {
350
362 
                        if (g_array_index(domain->sessions,SaHpiSessionIdT,i) == sid) {
351
362 
                                g_array_remove_index(domain->sessions,i);
352
362 
                                break;
353
 
                        }
354
 
                }
355
362 
                oh_release_domain(domain);
356
 
        }
357
 
358
362 
        return SA_OK;
359
 
}
360