File: globus_gfork_states.c

package info (click to toggle)
globus-gfork 5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,452 kB
  • sloc: sh: 11,067; ansic: 3,047; makefile: 96
file content (73 lines) | stat: -rw-r--r-- 1,975 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "globus_i_gfork.h"

static gfork_i_state_t **               gfork_l_state_tansitions;

static char *                           gfork_l_state_names[] =
{
    "GFORK_STATE_NONE",
    "GFORK_STATE_OPENING",
    "GFORK_STATE_OPEN",
    "GFORK_STATE_OPENING_AND_CLOSING",
    "GFORK_STATE_CLOSING",
    "GFORK_STATE_CLOSED",
    "GFORK_STATE_COUNT"
};

static char *                           gfork_l_event_names[] =
{
    "GFORK_EVENT_NONE",
    "GFORK_EVENT_ACCEPT_CB",
    "GFORK_EVENT_OPEN_RETURNS",
    "GFORK_EVENT_SIGCHILD",
    "GFORK_EVENT_CLOSE_RETURNS",
    "GFORK_EVENT_COUNT"
};


void
gfork_i_state_init()
{
    gfork_i_state_t **                  map;
    int                                 i;

    /* allocate all the pointes to each column */
    map = (gfork_i_state_t **)
        globus_calloc(GFORK_STATE_COUNT, sizeof(globus_bool_t *));
    for(i = 0; i < GFORK_STATE_COUNT; i++)
    {
        map[i] = (gfork_i_state_t *)
            globus_calloc(GFORK_EVENT_COUNT, sizeof(globus_bool_t));
    }

    map[GFORK_STATE_NONE][GFORK_EVENT_ACCEPT_CB] = GFORK_STATE_OPENING;

    map[GFORK_STATE_OPENING][GFORK_EVENT_OPEN_RETURNS] = GFORK_STATE_OPEN;
    map[GFORK_STATE_OPENING][GFORK_EVENT_SIGCHILD] =
        GFORK_STATE_OPENING_AND_CLOSING;

    map[GFORK_STATE_OPEN][GFORK_EVENT_SIGCHILD] = GFORK_STATE_CLOSING;

    map[GFORK_STATE_OPENING_AND_CLOSING][GFORK_EVENT_OPEN_RETURNS] =
        GFORK_STATE_CLOSING;

    map[GFORK_STATE_CLOSING][GFORK_EVENT_CLOSE_RETURNS] = GFORK_STATE_CLOSED;

    gfork_l_state_tansitions = map;
}

gfork_i_state_t
gfork_i_state_next(
    gfork_i_state_t                 current_state,
    gfork_i_events_t                event)
{
    gfork_i_state_t                 new_state;

    new_state = gfork_l_state_tansitions[current_state][event];
    GlobusGForkDebugState(
        gfork_l_state_names[current_state],
        gfork_l_state_names[new_state],
        gfork_l_event_names[event]);

    return new_state;
}