Input::~Input() { if (m_keyboardDevice) { m_keyboardDevice->Unacquire(); SRELEASE(m_keyboardDevice); } if (m_mouseDevice) { m_mouseDevice->Unacquire(); SRELEASE(m_mouseDevice); } SRELEASE(m_dInput); }
void ctrl_release(ctrl_exec_t *ctrl) { if(ctrl != NULL) { mid_release(ctrl->mid); SRELEASE(ctrl); } }
void msg_release_rpt_policy(adm_rpt_policy_t *msg) { AMP_DEBUG_ENTRY("msg_release_rpt_policy","(0x%x)", (unsigned long) msg); if(msg != NULL) { SRELEASE(msg); } AMP_DEBUG_EXIT("msg_release_rpt_policy","->.",NULL); }
void msg_release_reg_agent(adm_reg_agent_t *msg) { AMP_DEBUG_ENTRY("msg_release_reg_agent","(0x%x)", (unsigned long) msg); if(msg != NULL) { SRELEASE(msg); } AMP_DEBUG_EXIT("msg_release_reg_agent","->.",NULL); }
void msg_release_stat_msg(adm_stat_msg_t *msg) { AMP_DEBUG_ENTRY("msg_release_stat_msg","(0x%x)", (unsigned long) msg); if(msg != NULL) { mid_release(msg->code); midcol_destroy(&(msg->generators)); SRELEASE(msg); } AMP_DEBUG_EXIT("msg_release_stat_msg","->.",NULL); }
void ui_print_expr(expr_t *expr) { char *str; if(expr == NULL) { printf("NULL"); } str = expr_to_string(expr); printf("%s", str); SRELEASE(str); }
void ui_print_mid(mid_t *mid) { char *result = NULL; if(mid == NULL) { printf("NULL"); return; } result = names_get_name(mid); printf("%s", result); SRELEASE(result); }
void ui_print_trl(trl_t *trl) { char *mid_str = NULL; if(trl == NULL) { printf("NULL"); return; } mid_str = mid_to_string(trl->mid); printf("TRL %s: T:%d P:"UVAST_FIELDSPEC" C:"UVAST_FIELDSPEC" A:", mid_str, (uint32_t) trl->time, trl->period, trl->count); ui_print_mc(trl->action); SRELEASE(mid_str); }
void ui_print_srl(srl_t *srl) { char *mid_str = NULL; if(srl == NULL) { printf("NULL"); return; } mid_str = mid_to_string(srl->mid); printf("SRL %s: T:%d E:", mid_str, (uint32_t) srl->time); ui_print_expr(srl->expr); printf(" C:"UVAST_FIELDSPEC" A:", srl->count); ui_print_mc(srl->action); SRELEASE(mid_str); }
ctrl_exec_t* ctrl_create(time_t time, mid_t *mid, eid_t sender) { ctrl_exec_t *result = NULL; AMP_DEBUG_ENTRY("ctrl_create","(%d, 0x%x)", time, (unsigned long) mid); /* Step 0: Sanity Check. */ if(mid == NULL) { AMP_DEBUG_ERR("ctrl_create","Bad Args.",NULL); AMP_DEBUG_EXIT("ctrl_create","->NULL",NULL); return NULL; } /* Step 1: Allocate the message. */ if((result = (ctrl_exec_t*)STAKE(sizeof(ctrl_exec_t))) == NULL) { AMP_DEBUG_ERR("ctrl_create","Can't alloc %d bytes.", sizeof(ctrl_exec_t)); AMP_DEBUG_EXIT("ctrl_create","->NULL",NULL); return NULL; } /* Step 2: Find the adm_ctrl_t associated with this control. */ if((result->adm_ctrl = adm_find_ctrl(mid)) == NULL) { AMP_DEBUG_ERR("ctrl_create","Can't find ADM ctrl.",NULL); SRELEASE(result); AMP_DEBUG_EXIT("ctrl_create","->NULL",NULL); return NULL; } /* Step 3: Copy the sender information. */ memcpy(&(result->sender), &sender, sizeof(eid_t)); /* Step 4: Calculate time information for the control. */ result->time = time; result->mid = mid_copy(mid); if(result->time <= AMP_RELATIVE_TIME_EPOCH) { /* Step 4a: If relative time, that is # seconds. */ result->countdown_ticks = result->time; } else { /* * Step 4b: If absolute time, # seconds if difference * from now until then. */ result->countdown_ticks = (result->time - getUTCTime()); } /* Step 5: Populate dynamic parts of the control. */ result->status = CONTROL_ACTIVE; AMP_DEBUG_EXIT("ctrl_create","->0x%x",result); return result; }
uint8_t *ctrl_serialize(ctrl_exec_t *ctrl, uint32_t *len) { uint8_t *result = NULL; uint8_t *cursor = NULL; Sdnv time_sdnv; Sdnv status_sdnv; uint8_t *contents = NULL; uint32_t contents_len = 0; AMP_DEBUG_ENTRY("ctrl_serialize","(0x%x, 0x%x)", (unsigned long)ctrl, (unsigned long) len); /* Step 0: Sanity Checks. */ if((ctrl == NULL) || (len == NULL)) { AMP_DEBUG_ERR("ctrl_serialize","Bad Args",NULL); AMP_DEBUG_EXIT("ctrl_serialize","->NULL",NULL); return NULL; } *len = 0; /* Step 1: Serialize contents individually. */ encodeSdnv(&time_sdnv, ctrl->time); encodeSdnv(&status_sdnv, ctrl->status); if((contents = mid_serialize(ctrl->mid, &contents_len)) == NULL) { AMP_DEBUG_ERR("ctrl_serialize","Can't serialize MID.",NULL); AMP_DEBUG_EXIT("ctrl_serialize","->NULL",NULL); return NULL; } /* Step 2: Figure out the length. */ *len = time_sdnv.length + status_sdnv.length + sizeof(eid_t) + contents_len; /* STEP 3: Allocate the serialized message. */ if((result = (uint8_t*)STAKE(*len)) == NULL) { AMP_DEBUG_ERR("ctrl_serialize","Can't alloc %d bytes", *len); *len = 0; SRELEASE(contents); AMP_DEBUG_EXIT("ctrl_serialize","->NULL",NULL); return NULL; } /* Step 4: Populate the serialized message. */ cursor = result; memcpy(cursor,time_sdnv.text,time_sdnv.length); cursor += time_sdnv.length; memcpy(cursor,status_sdnv.text,status_sdnv.length); cursor += status_sdnv.length; memcpy(cursor,&(ctrl->sender),sizeof(eid_t)); cursor += sizeof(eid_t); memcpy(cursor, contents, contents_len); cursor += contents_len; SRELEASE(contents); /* Step 5: Last sanity check. */ if((cursor - result) != *len) { AMP_DEBUG_ERR("ctrl_serialize","Wrote %d bytes but allcated %d", (unsigned long) (cursor - result), *len); *len = 0; SRELEASE(result); AMP_DEBUG_EXIT("ctrl_serialize","->NULL",NULL); return NULL; } AMP_DEBUG_EXIT("ctrl_serialize","->0x%x",(unsigned long)result); return result; }
/****************************************************************************** * * \par Function Name: ctrl_deserialize * * \par Construct a control instance from an incoming message byte stream. * * \retval NULL - Error in deserializing the control. * !NULL - The control instance * * \param[in] cursor Pointer to the start of the serialized control. * \param[in] size The size of the remaining serialized data * \param[out] bytes_used The number of bytes consumed in processing this ctrl. * * Modification History: * MM/DD/YY AUTHOR DESCRIPTION * -------- ------------ --------------------------------------------- * 01/10/13 E. Birrane Initial implementation. (JHU/APL) * 05/17/15 E. Birrane Moved to ctrl.c, updated to DTNMP V0.1 (Secure DTN - NASA: NNX14CS58P) *****************************************************************************/ ctrl_exec_t *ctrl_deserialize(uint8_t *cursor, uint32_t size, uint32_t *bytes_used) { ctrl_exec_t *result = NULL; uint32_t bytes = 0; uvast val = 0; AMP_DEBUG_ENTRY("ctrl_deserialize","(0x%x, %d, 0x%x)", (unsigned long)cursor, size, (unsigned long) bytes_used); /* Step 0: Sanity Checks. */ if((cursor == NULL) || (bytes_used == 0)) { AMP_DEBUG_ERR("ctrl_deserialize","Bad Args.",NULL); AMP_DEBUG_EXIT("ctrl_deserialize","->NULL",NULL); return NULL; } /* Step 1: Allocate the new message structure. */ if((result = (ctrl_exec_t*)STAKE(sizeof(ctrl_exec_t))) == NULL) { AMP_DEBUG_ERR("ctrl_deserialize","Can't Alloc %d Bytes.", sizeof(ctrl_exec_t)); *bytes_used = 0; AMP_DEBUG_EXIT("ctrl_deserialize","->NULL",NULL); return NULL; } else { memset(result,0,sizeof(ctrl_exec_t)); } bytes = decodeSdnv(&val, cursor); result->time = val; cursor += bytes; size -= bytes; *bytes_used += bytes; bytes = decodeSdnv(&val,cursor); result->status = val; cursor += bytes; size -= bytes; *bytes_used += bytes; memcpy(&(result->sender), cursor, sizeof(eid_t)); cursor += sizeof(eid_t); size -= sizeof(eid_t); *bytes_used += sizeof(eid_t); if((result->mid = mid_deserialize(cursor, size, &bytes)) == NULL) { AMP_DEBUG_ERR("ctrl_deserialize","Can't grab contents.",NULL); *bytes_used = 0; SRELEASE(result); AMP_DEBUG_EXIT("ctrl_deserialize","->NULL",NULL); return NULL; } else { cursor += bytes; size -= bytes; *bytes_used += bytes; } AMP_DEBUG_EXIT("ctrl_deserialize","->0x%x", (unsigned long)result); return result; }
void ui_print_val(uint8_t type, uint8_t *data, uint32_t length) { uint32_t bytes = 0; if(data == NULL) { printf("NULL"); return; } switch(type) { case AMP_TYPE_VAR: { var_t *cd = var_deserialize(data, length, &bytes); char *str = var_to_string(cd); printf("%s", str); SRELEASE(str); var_release(cd); } break; case AMP_TYPE_INT: printf("%d", utils_deserialize_int(data, length, &bytes)); break; case AMP_TYPE_TS: case AMP_TYPE_UINT: printf("%d", utils_deserialize_uint(data, length, &bytes)); break; case AMP_TYPE_VAST: printf(VAST_FIELDSPEC, utils_deserialize_vast(data, length, &bytes)); break; case AMP_TYPE_SDNV: case AMP_TYPE_UVAST: printf(UVAST_FIELDSPEC, utils_deserialize_uvast(data, length, &bytes)); break; case AMP_TYPE_REAL32: printf("%f", utils_deserialize_real32(data, length, &bytes)); break; case AMP_TYPE_REAL64: printf("%f", utils_deserialize_real64(data, length, &bytes)); break; case AMP_TYPE_STRING: { char* tmp = NULL; tmp = utils_deserialize_string(data, length, &bytes); printf("%s", tmp); SRELEASE(tmp); } break; case AMP_TYPE_BLOB: { blob_t *blob = blob_deserialize(data, length, &bytes); char *str = blob_to_str(blob); printf("%s", str); SRELEASE(str); SRELEASE(blob); } break; case AMP_TYPE_DC: { uint32_t bytes = 0; Lyst dc = dc_deserialize(data, length, &bytes); ui_print_dc(dc); dc_destroy(&dc); } break; case AMP_TYPE_MID: { uint32_t bytes = 0; mid_t *mid = mid_deserialize(data, length, &bytes); ui_print_mid(mid); mid_release(mid); } break; case AMP_TYPE_MC: { uint32_t bytes = 0; Lyst mc = midcol_deserialize(data, length, &bytes); ui_print_mc(mc); midcol_destroy(&mc); } break; // \todo: Expression has no priority. Need to re-think priority. case AMP_TYPE_EXPR: { uint32_t bytes = 0; expr_t *expr = expr_deserialize(data, length, &bytes); ui_print_expr(expr); expr_release(expr); } break; /* case DTNMP_TYPE_DEF: { uint32_t bytes = 0; def_gen_t *def = def_deserialize_gen(data, length, &bytes); ui_print_def(def); def_release_gen(def); } break; */ case AMP_TYPE_TRL: { uint32_t bytes = 0; trl_t *trl = trl_deserialize(data, length, &bytes); ui_print_trl(trl); trl_release(trl); } break; case AMP_TYPE_TABLE: { uint32_t bytes = 0; table_t *table = table_deserialize(data, length, &bytes); ui_print_table(table); table_destroy(table, 1); } break; case AMP_TYPE_SRL: { uint32_t bytes = 0; srl_t *srl = srl_deserialize(data, length, &bytes); ui_print_srl(srl); srl_release(srl); } break; default: printf("Unknown."); } }
/****************************************************************************** * * \par Function Name: ui_print_table * * \par Purpose: Prints a table to stdout. * * \par * COL HDR: Name (Type), Name (Type), Name (Type)... * ROW 0: Value1, Value2, Value3... * ROW 1: Value1, Value2, Value3... * * \param[in] table The table to be printed * * Modification History: * MM/DD/YY AUTHOR DESCRIPTION * -------- ------------ --------------------------------------------- * 06/8/16 E. Birrane Initial implementation, *****************************************************************************/ void ui_print_table(table_t *table) { int32_t i = 0; uint32_t row_num = 1; int8_t first = 0; LystElt elt; LystElt elt2; char *temp = NULL; blob_t *cur_blob = NULL; table_row_t *cur_row = NULL; if(table == NULL) { printf("NULL"); return; } printf("COL HDR: "); for(elt = lyst_first(table->hdr.names); elt; elt = lyst_next(elt)) { cur_blob = (blob_t*) lyst_data(elt); if(first == 0) { first = 1; } else { printf(", "); } printf(" %s (%s)", (char *)cur_blob->value, type_to_str(table->hdr.types.value[i])); i++; } printf("\n"); for(elt = lyst_first(table->rows); elt; elt = lyst_next(elt)) { cur_row = (table_row_t*) lyst_data(elt); printf("ROW %3d: ", row_num++); if(cur_row == NULL) { printf("NULL"); } else { first = 0; i = 0; for(elt2 = lyst_first(cur_row->cels); elt2; elt2 = lyst_next(elt2)) { cur_blob = (blob_t *) lyst_data(elt2); value_t val = val_from_blob(cur_blob, table->hdr.types.value[i]); if(first == 0) { first = 1; } else { printf(", "); } temp = val_to_string(val); printf("%s", temp); SRELEASE(temp); val_release(&val, 0); i++; } printf("\n"); } } }