File: lcc.c

package info (click to toggle)
ion 3.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,700 kB
  • ctags: 10,983
  • sloc: ansic: 141,798; sh: 22,848; makefile: 7,818; python: 1,638; sql: 311; perl: 197; awk: 178; xml: 50; java: 19
file content (200 lines) | stat: -rw-r--r-- 5,684 bytes parent folder | download | duplicates (2)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/******************************************************************************
 **                           COPYRIGHT NOTICE
 **      (c) 2012 The Johns Hopkins University Applied Physics Laboratory
 **                         All rights reserved.
 **
 **     This material may only be used, modified, or reproduced by or for the
 **       U.S. Government pursuant to the license rights granted under
 **          FAR clause 52.227-14 or DFARS clauses 252.227-7013/7014
 **
 **     For any other permissions, please contact the Legal Office at JHU/APL.
 ******************************************************************************/

/*****************************************************************************
 **
 ** File Name: lcc.c
 **
 ** Description: This implements the NM Agent Local Command and Control (LDC).
 **
 ** Notes:
 **
 ** Assumptions:
 **
 **
 ** Modification History:
 **  MM/DD/YY  AUTHOR         DESCRIPTION
 **  --------  ------------   ---------------------------------------------
 **  01/22/13  E. Birrane     Update to latest version of DTNMP. Cleanup.
 *****************************************************************************/

#include "shared/adm/adm.h"
#include "shared/primitives/mid.h"
#include "shared/primitives/rules.h"
#include "shared/primitives/instr.h"

#include "nmagent.h"
#include "lcc.h"


/******************************************************************************
 *
 * \par Function Name: lcc_run_ctrl_mid
 *
 * \par Run a control given the MID associated with that control.
 *
 * \param[in]  id   The MID identifying the control
 *
 * \par Notes:
 *
 * \return -1 - Error
 *         !(-1) - Value returned from the run control.
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 *  01/22/13  E. Birrane     Initial implementation.
 *****************************************************************************/

int lcc_run_ctrl_mid(mid_t *id)
{
    int result = 0;
    adm_ctrl_t *adm_ctrl = NULL;
    def_gen_t *macro_def = NULL;
    static int nesting = 0;
    char *msg = NULL;
    Lyst parms = NULL;


    nesting++;

    DTNMP_DEBUG_ENTRY("lcc_run_ctrl_mid","(0x%#llx)", (unsigned long) id);


    /* Step 0: Sanity Check */
    if((id == NULL) || (id->oid == NULL))
    {
    	DTNMP_DEBUG_ERR("lcc_run_ctrl_mid","Bad Args.",NULL);
    	DTNMP_DEBUG_EXIT("lcc_run_ctrl_mid","-> -1",NULL);
    	nesting--;
    	return -1;
    }

    if(nesting > 5)
    {
    	DTNMP_DEBUG_ERR("lcc_run_ctrl_mid","Too many nesting levels (%d).",nesting);
    	DTNMP_DEBUG_EXIT("lcc_run_ctrl_mid","-> -1",NULL);
    	nesting--;
    	return -1;
    }

    msg = mid_to_string(id);
    DTNMP_DEBUG_INFO("lcc_run_ctrl_mid","Running control: %s", msg);

    /* Step 1: See if this identifies an atomic control. */
    if((adm_ctrl = adm_find_ctrl(id)) != NULL)
    {
    	DTNMP_DEBUG_INFO("lcc_run_ctrl_mid","Found control.", NULL);
    	result = adm_ctrl->run(id->oid->params);
    	gAgentInstr.num_ctrls_run++;

    }

    /* Step 2: Otherwise, see if this identifies a pre-defined macro. */
    else if((macro_def = def_find_by_id(gAgentVDB.macros, &(gAgentVDB.macros_mutex), id)) != NULL)
    {
    	LystElt elt;
    	mid_t *mid;

    	/*
    	 * Step 2.1: This is a macro. Walk through each control running
    	 *           the controls as we go.
    	 */
    	for(elt = lyst_first(macro_def->contents); elt; elt = lyst_next(elt))
    	{
    		mid = (mid_t *)lyst_data(elt);
    		result = lcc_run_ctrl_mid(mid);
    		if(result != 0)
    		{
    			DTNMP_DEBUG_WARN("lcc_run_ctrl_mid","Running MID %s returned %d",
    					         msg, result);
    		}
    	}
    }

    /* Step 3: Otherwise, give up. */
    else
    {
    	DTNMP_DEBUG_ERR("lcc_run_ctrl_mid","Could not find control for MID %s",
    			        msg);
    	result = -1;
    }

    MRELEASE(msg);

    nesting--;
    DTNMP_DEBUG_EXIT("lcc_run_ctrl_mid","-> %d", result);
    return result;
}



/******************************************************************************
 *
 * \par Function Name: lcc_run_ctrl
 *
 * \par Run a control given a control execution structure.
 *
 * \param[in]  ctrl_p  The control execution structure.
 *
 * \par Notes:
 *
 * \return -1 - Error
 *         !(-1) - Value returned from the run control.
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 *  01/22/13  E. Birrane     Initial implementation.
 *****************************************************************************/

int lcc_run_ctrl(ctrl_exec_t *ctrl_p)
{
	int result = 0;
	char *msg = NULL;
	Lyst parms = NULL;
    LystElt elt;
    mid_t *cur_ctrl = NULL;
    char *str = NULL;

	DTNMP_DEBUG_ENTRY("lcc_run_ctrl","(0x%x)", (unsigned long) ctrl_p);

	/* Step 0: Sanity Check */
	if(ctrl_p == NULL)
	{
		DTNMP_DEBUG_ERR("lcc_run_ctrl","Bad Args.",NULL);
		DTNMP_DEBUG_EXIT("lcc_run_ctrl","-> -1",NULL);
		return -1;
	}


    /* Step 1: Walk through the macro, running controls as we go. */
    for (elt = lyst_first(ctrl_p->contents); elt; elt = lyst_next(elt))
    {
        /* Step 1.1: Grab the next ctrl...*/
        if((cur_ctrl = (mid_t *) lyst_data(elt)) == NULL)
        {
            DTNMP_DEBUG_ERR("lcc_run_ctrl","Found NULL ctrl. Exiting", NULL);
            DTNMP_DEBUG_EXIT("lcc_run_ctrl","->-1.", NULL);
            return -1;
        }

    	result = lcc_run_ctrl_mid(cur_ctrl);
    	if(result != 0)
    	{
    		DTNMP_DEBUG_WARN("lcc_run_ctrl","Error running control.", NULL);
    	}
    }

	DTNMP_DEBUG_EXIT("lcc_run_ctrl","-> %d", result);
	return result;
}