📄 trafbuild_active_attrib_handler.ex.c
字号:
/* trafbuild_active_attrib_handlers.ex.c: Support file for Active *//* attribute handlers used in application models. *//****************************************//* Copyright (c) 2000 *//* by OPNET Technologies, Inc. *//* (A Delaware Corporation) *//* 3400 International Drive, N.W. *//* Washington, D.C., U.S.A. *//* All Rights Reserved. *//****************************************//***** Include Files *****/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <opnet.h>#include <prg.h>#include <ets_api.h>#include <ets_client.h>/***** Function protocotypes *****/DLLEXPORT EtsT_Obj_Dbox_Click_Options trafbuild_node_name_get_click_handler (const char *attr_name, EtsT_Obj_Handle orig_object, EtsT_Obj_Handle copy_object, VosT_Textlist *menu_tlptr);char * trafbuild_hierarchical_name_get (EtsT_Obj_Handle obj_handle);/***** Function declarations. *****/DLLEXPORT EtsT_Obj_Dbox_Click_Optionstrafbuild_node_name_get_click_handler (const char *attr_name, EtsT_Obj_Handle orig_object, EtsT_Obj_Handle copy_object, VosT_Textlist *menu_tlptr) { EtsT_Model_Handle model_handle; int num_nodes, node_index; EtsT_Obj_Handle node_obj_handle; char source_name [255]; char temp_model[255]; int line_num, i, match, totalNum = 0;
char tmp[255];
VosT_Textlist *aliasList; /** Attribute click handler that iterates through the fixed **/ /** nodes of network model, looks for IP devices, and **/
/** returns a menu of IP node names. **/ FIN (trafbuild_node_name_get_click_handler (attr_name, orig_object, copy_object, menu_tlptr)); /* Get the handle to the Network Model */ model_handle = Ets_Model_Current_Get (EtsC_Model_Nt); /* Remove all symbol maps. */ while (Vos_Textlist_Line_Count (menu_tlptr)) Vos_Textlist_Line_Delete (menu_tlptr, 0); /* Use the ETS topo package to go through the model and retrieve all nodes. */ num_nodes = Ets_Topo_Object_Count_Get (model_handle, EtsC_Obj_Type_Node_Fix); /* Start a progress bar. */ if (num_nodes > 1) Ets_Progress_Bar_Start ("Loading Node Names...", num_nodes); for (node_index = 0; node_index < num_nodes; node_index++) { /* Advance progress bar. */ if ((num_nodes > 1) && (node_index % 1 == 0)) Ets_Progress_Bar_Advance (1); /* Get a handle to the node. */ node_obj_handle = Ets_Topo_Object_Get (model_handle, EtsC_Obj_Type_Node_Fix, node_index);
/* Check if this node has the attribute "IP Address Information". */
if (Ets_Obj_Attr_Exists (node_obj_handle, "IP Address Information") ||
Ets_Obj_Attr_Exists (node_obj_handle, "IP Ping Traffic") ||
Ets_Obj_Attr_Exists (node_obj_handle, "IP Routing Speed") ||
Ets_Obj_Attr_Exists (node_obj_handle, "IP Forwarding Rate") ||
Ets_Obj_Attr_Exists (node_obj_handle, "TCP Parameters"))
{
aliasList = Vos_Textlist_Create ();
Vos_Textlist_Append (aliasList, trafbuild_hierarchical_name_get (node_obj_handle), VOSC_EOL);
Ets_Nt_Node_Aliases_Set (node_obj_handle, aliasList);
/* Get the model type */
Ets_Obj_Attr_Get (node_obj_handle, "model", &temp_model);
match = 1;
for (i = 0; i < totalNum; i++)
{
Vos_Textlist_Line_Get (menu_tlptr, i, tmp);
if (!strcmp (temp_model, tmp))
{
match = 0;
break;
}
}
if (match)
{
printf ("\n%s", temp_model);
Vos_Textlist_Append (menu_tlptr, temp_model, VOSC_EOL);
totalNum++;
}
} }
/* Add 'Edit...' at the end. */ Vos_Textlist_Append (menu_tlptr, "Edit...", VOSC_EOL); /* End progress bar. */ if (num_nodes > 1) Ets_Progress_Bar_End (); FRET (EtsC_Obj_Dbox_Click_Show_Menu); }
/**************** Internal functions ****************/char *trafbuild_hierarchical_name_get (EtsT_Obj_Handle obj_handle) { EtsT_Obj_Handle cur_obj; char* result_str; char* name_str; Prg_List* parent_lptr; int full_name_len = 0; int list_size; int i; char object_name [255]; /** PURPOSE: Returns the hierarchical name of the object in a newly **/ /** allocated block. This name does not include the top subnet. **/ /** **/ /** REQUIRES: The object is a valid object. **/ /** **/ /** EFFECTS: Caller takes ownership of RESULT. **/ /** In the event of an error, RESULT == PRGC_NIL. **/ /** In the event the top subnet is passed in, RESULT == empty string **/ FIN (trafbuild_hierarchical_name_get (obj_handle)); /* Check the object handle for validity. If it is invalid return an error. */ if (Ets_Obj_Invalid (obj_handle)) { FRET (PRGC_NIL); } /* The current object at the beginning will be the object handle passed in. */ cur_obj = obj_handle; /* Create the list that will store all of the parts of the hierarchical name */ /* This list will then be traveresed to create the whole name. By doing this */ /* the length of the resulting name can be determined and the proper amount of */ /* memory can be dynamically allocated. */ parent_lptr = prg_list_create (); if (parent_lptr == PRGC_NIL) { FRET (PRGC_NIL); } /* Go through the parent of each object and insert the name of each at the end */ /* of the list. When PRGC_NIl is returned the top has been reached and the */ /* list can be used to form the full name. */ while (!Ets_Obj_Invalid (cur_obj)) { /* Retrieve the name of the current subnet */ Ets_Obj_Attr_Get (cur_obj, "name", object_name); /* Allocate memory for object name. */ name_str = (char*) prg_mem_alloc (sizeof (char) * (strlen (object_name) + 1)); strcpy (name_str, object_name); /* Insert the new element at the head of the list of names. */ prg_list_insert (parent_lptr, name_str, PRGC_LISTPOS_HEAD); /* Add the size of the current name to the full name length plus one for */ /* period between names. This will be used later to allocated the proper */ /* amount of space for the hierarchical name. */ full_name_len += ( strlen (name_str) + 1); /* Get the parent of this object so that the next part of the name can be */ /* retrieved. */ cur_obj = Ets_Topo_Parent_Get (cur_obj); } /* The top subnet should not be part of the name therefore we need to remove */ /* it from the list of names before forming the final name. */ prg_list_remove (parent_lptr, PRGC_LISTPOS_HEAD); /* Recalculate the name length as top is not part of the name. */ full_name_len -= 4; /* If the full_name_len is equal to zero, the top subnet was passed in. */ /* one space for an empty string. */ if (full_name_len == 0) full_name_len++; /* Allocate space for the hierarchical name based on the length of all parts of */ /* the name including the period between the parts. */ result_str = (char *) prg_mem_alloc (full_name_len); /* Print an error message and return an error if no space could be allocated. */ /* for the name. */ if (result_str == PRGC_NIL) { FRET (PRGC_NIL); } /* Initialize the string to be empty. */ *result_str = '\0'; /* Go through the list from the beginning adding each elemnt of the list to the */ /* full hierarchical name. At the end of this loop the name is complete. */ list_size = prg_list_size (parent_lptr); /* Build the string based on the list of parent names. */ for (i = 0; i < list_size; i++) { name_str = prg_list_remove (parent_lptr, OPC_LISTPOS_HEAD); /* Prepend the dot only when this is not the first part of the name. */ if (i != 0) strcat (result_str, "."); strcat (result_str, name_str); /* Free element in list. */ prg_mem_free (name_str); } /* The parent_list is no longer used, therefore free up all the memory in use */ /* by the list. */ prg_list_free (parent_lptr); FRET (result_str); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -