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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
/******************************************************************************
** 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 admin.c
**
**
** Description: Administrative primitives.
**
** Notes:
**
** Assumptions:
**
** Modification History:
** MM/DD/YY AUTHOR DESCRIPTION
** -------- ------------ ---------------------------------------------
** 01/17/13 E. Birrane Redesign of messaging architecture.
** 06/24/13 E. Birrane Migrated from uint32_t to time_t.
*****************************************************************************/
#include "platform.h"
#include "shared/utils/utils.h"
#include "shared/primitives/mid.h"
#include "admin.h"
/* Create functions. */
/**
* \brief Convenience function to build Register Agent message.
*
* \author Ed Birrane
*
* \note
* - We shallow copy information into the message. So, don't release anything
* provided as an argument to this function.
*
* \return NULL - Failure
* !NULL - Created message.
*
* \param[in] eid The agent EID.
*/
adm_reg_agent_t *msg_create_reg_agent(eid_t eid)
{
adm_reg_agent_t *result = NULL;
DTNMP_DEBUG_ENTRY("msg_create_reg_agent","(%s)", eid.name);
/* Step 1: Allocate the message. */
if((result = (adm_reg_agent_t*) MTAKE(sizeof(adm_reg_agent_t))) == NULL)
{
DTNMP_DEBUG_ERR("msg_create_reg_agent","Can't alloc %d bytes.",
sizeof(adm_reg_agent_t));
DTNMP_DEBUG_EXIT("msg_create_reg_agent","->NULL",NULL);
return NULL;
}
/* Step 2: Populate the message. */
result->agent_id = eid;
DTNMP_DEBUG_EXIT("msg_create_reg_agent","->0x%x",result);
return result;
}
/**
* \brief COnvenience function to build Report Policy message.
*
* \author Ed Birrane
*
* \note
* - We shallow copy information into the message. So, don't release anything
* provided as an argument to this function.
*
* \return NULL - Failure
* !NULL - Created message.
*
* \param[in] eid The report policy mask.
*/
adm_rpt_policy_t *msg_create_rpt_policy(uint8_t mask)
{
adm_rpt_policy_t *result = NULL;
DTNMP_DEBUG_ENTRY("msg_create_rpt_policy","(0x%x)", mask);
/* Step 1: Allocate the message. */
if((result = (adm_rpt_policy_t*)MTAKE(sizeof(adm_reg_agent_t))) == NULL)
{
DTNMP_DEBUG_ERR("msg_create_rpt_policy","Can't alloc %d bytes.",
sizeof(adm_reg_agent_t));
DTNMP_DEBUG_EXIT("msg_create_rpt_policy","->NULL",NULL);
return NULL;
}
/* Step 2: Populate the message. */
result->mask = mask;
DTNMP_DEBUG_EXIT("msg_create_rpt_policy","->0x%x",result);
return result;
}
/**
* \brief Convenience function to build a Status message.
*
* \author Ed Birrane
*
* \note
* - We shallow copy information into the message. So, don't release anything
* provided as an argument to this function.
*
* \return NULL - Failure
* !NULL - Created message.
*
* \param[in] code The status, as a MID.
* \param[in] time When the status occured.
* \param[in] generators The MIDs causing the status.
*/
adm_stat_msg_t *msg_create_stat_msg(mid_t *code,
time_t time,
Lyst generators)
{
adm_stat_msg_t *result = NULL;
DTNMP_DEBUG_ENTRY("msg_create_stat_msg","(code,0x%x,0x%x)",
time, (unsigned long) generators);
/* Step 0: Sanity Check. */
if((code == NULL) || (generators == NULL))
{
DTNMP_DEBUG_ERR("msg_create_stat_msg","Bad Args.",NULL);
DTNMP_DEBUG_EXIT("msg_create_stat_msg","->NULL",NULL);
return NULL;
}
/* Step 1: Allocate the message. */
if((result = (adm_stat_msg_t*)MTAKE(sizeof(adm_reg_agent_t))) == NULL)
{
DTNMP_DEBUG_ERR("msg_create_stat_msg","Can't alloc %d bytes.",
sizeof(adm_reg_agent_t));
DTNMP_DEBUG_EXIT("msg_create_stat_msg","->NULL",NULL);
return NULL;
}
/* Step 2: Populate the message. */
result->code = code;
result->time = time;
result->generators = generators;
DTNMP_DEBUG_EXIT("msg_create_stat_msg","->0x%x",result);
return result;
}
/* Release functions.*/
/**
* \brief Release Register Agent message.
*
* \author Ed Birrane
*
* \param[in,out] msg The message being released.
*/
void msg_release_reg_agent(adm_reg_agent_t *msg)
{
DTNMP_DEBUG_ENTRY("msg_release_reg_agent","(0x%x)",
(unsigned long) msg);
if(msg != NULL)
{
MRELEASE(msg);
}
DTNMP_DEBUG_EXIT("msg_release_reg_agent","->.",NULL);
}
/**
* \brief Release Report Policy message.
*
* \author Ed Birrane
*
* \param[in,out] msg The message being released.
*/
void msg_release_rpt_policy(adm_rpt_policy_t *msg)
{
DTNMP_DEBUG_ENTRY("msg_release_rpt_policy","(0x%x)",
(unsigned long) msg);
if(msg != NULL)
{
MRELEASE(msg);
}
DTNMP_DEBUG_EXIT("msg_release_rpt_policy","->.",NULL);
}
/**
* \brief Release Status message.
*
* \author Ed Birrane
*
* \param[in,out] msg The message being released.
*/
void msg_release_stat_msg(adm_stat_msg_t *msg)
{
DTNMP_DEBUG_ENTRY("msg_release_stat_msg","(0x%x)",
(unsigned long) msg);
if(msg != NULL)
{
mid_release(msg->code);
midcol_destroy(&(msg->generators));
MRELEASE(msg);
}
DTNMP_DEBUG_EXIT("msg_release_stat_msg","->.",NULL);
}
|