Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
soc:fredrikhultin [2006/07/11 22:26]
noname
soc:fredrikhultin [2006/07/12 00:24] (current)
noname
Line 7: Line 7:
  
 ===== Design ===== ===== Design =====
 +
 ==== User interface ==== ==== User interface ====
  
Line 12: Line 13:
  
 <​file>​ <​file>​
 +Welcome to Etherboot
 +
 ?>help ?>help
  
Line 80: Line 83:
   /* Name and describe the list set */   /* Name and describe the list set */
   cmdl_param_list_set_name(ipv4,​ "​ipv4"​);​   cmdl_param_list_set_name(ipv4,​ "​ipv4"​);​
-  ​cmdl_param_list_set_descr(ipv4, "Set the IP adress and netmask (IPv4)"​);​+  ​cmdl_param_list_set_desc(ipv4, "Set the IP adress and netmask (IPv4)"​);​
  
   /* Add the parameters with name, type and example value */   /* Add the parameters with name, type and example value */
Line 94: Line 97:
   /* Name and describe the list set */   /* Name and describe the list set */
   cmdl_param_list_set_name(ipv6,​ "​ipv6"​);​   cmdl_param_list_set_name(ipv6,​ "​ipv6"​);​
-  ​cmdl_param_list_set_descr(ipv6, "Set the IP adress (IPv6)"​);​+  ​cmdl_param_list_set_desc(ipv6, "Set the IP adress (IPv6)"​);​
  
   cmdl_param_list_set_add(ipv6,​ "​ip",​ CMDL_IPV6, "​2001:​0db8::​1428:​57ab"​);​   cmdl_param_list_set_add(ipv6,​ "​ip",​ CMDL_IPV6, "​2001:​0db8::​1428:​57ab"​);​
Line 106: Line 109:
   /* Name and describe the list set */   /* Name and describe the list set */
   cmdl_param_list_set_name(view,​ "​view"​);​   cmdl_param_list_set_name(view,​ "​view"​);​
-  ​cmdl_param_list_set_descr(view, "View the IP/​netmask"​);​+  ​cmdl_param_list_set_desc(view, "View the IP/​netmask"​);​
  
   /* (No parameters = view) */   /* (No parameters = view) */
Line 116: Line 119:
   /* Add the three list sets to the parameter list */   /* Add the three list sets to the parameter list */
  
-  cmdl_param_list_add(ipv4);​ +  cmdl_param_list_add(param_list, ​ipv4); 
-  cmdl_param_list_add(ipv6);​ +  cmdl_param_list_add(param_list, ​ipv6); 
-  cmdl_param_list_add(view);​+  cmdl_param_list_add(param_list, ​view);
  
   /* Return the parameter list to the command line */   /* Return the parameter list to the command line */
Line 125: Line 128:
  
 static int cmd_ip_exec ( cmd_line* cmd, cmdl_params* params ) { static int cmd_ip_exec ( cmd_line* cmd, cmdl_params* params ) {
-        ​return 0;+ 
 +  /* View */ 
 +  if(strcmp("​view",​ params->​set_name) == 0){ 
 +    int protocolv;​ 
 +    cmdl_ipv4 ip4, netmask; 
 +    cmdl_ipv6 ip6; 
 + 
 +    protocolv = ...(); 
 +    cmdl_printf(cmd,​ "​Protocol version: %i\n"​);​ 
 + 
 +    if(protocol != 4){ 
 +    }else{ 
 +      ip4 = ...(); 
 +      netmask = ...(); 
 +      cmdl_printf(cmd,​ "​Adress:​ %i.%i.%i.%i\nNetmask:​ %i.%i.%i.%i\n",​  
 +                       ​ip4.octet[0], ​    ​ip4.octet[1], ​    ​ip4.octet[2], ​    ​ip4.octet[3],​  
 +                   ​netmask.octet[0],​ netmask.octet[1],​ netmask.octet[2],​ netmask.octet[3] ); 
 +    }else{ 
 +       ... 
 +    } 
 +  } 
 + 
 +  /* ipv4 */ 
 +  if(strcmp("​ipv4",​ params->​set_name) == 0){ 
 +    if( !set_gpxe_ip_something( cmdl_param_get_ipv4(params->​param[0]) ){ 
 +      return -1; 
 +    } 
 +    if( !set_gpxe_netmask_something( cmdl_param_get_ipv4(params,​ 1) ){ 
 +      return -1; 
 +    } 
 +  } 
 + 
 +  /* ipv6 */ 
 +  if(strcmp("​ipv6",​ params->​set_name) == 0){ 
 +    if( !set_gpxe_ip6_something( cmdl_param_get_ipv6(params,​ 0) ){ 
 +      return -1; 
 +    } 
 +  } 
 + 
 +  ​return 0;
 } }
 </​code>​ </​code>​
 +
 +Observe that the output of "help ip" is generated from this implementation.
  
 ==== Structures ==== ==== Structures ====
Line 159: Line 203:
 <code c> <code c>
 typedef struct { typedef struct {
-  int num_sets; +  int num_sets; ​// The number of sets in the list 
-  cmdl_param_list_set* param_list_set;​+  cmdl_param_list_set** param_list_set; ​// An array of list set pointers
 } cmdl_param_list;​ } cmdl_param_list;​
 </​code>​ </​code>​
Line 171: Line 215:
 <code c> <code c>
 typedef struct { typedef struct {
-  char* name; +  char* name;  // Name of the list set (used for identification) 
-  char* desc; +  char* desc;  // Description of the list set (used for the automated help) 
-  int num_params;​ +  int num_params; ​  // The number of parameters 
-  cmdl_param_desc param;+  cmdl_param_desc** param; ​// An array of parameter description pointers
 } cmdl_param_list_set;​ } cmdl_param_list_set;​
 </​code>​ </​code>​
Line 184: Line 228:
 <code c> <code c>
 typedef struct { typedef struct {
-  int type; +  int type; // Parameter type 
-  char* name; +  char* name; // Parameter name 
-  char* example;+  char* example; ​// Example of possible value
 } cmdl_param_desc;​ } cmdl_param_desc;​
 </​code>​ </​code>​
Line 198: Line 242:
 enum{ enum{
   CMDL_INT=0,   CMDL_INT=0,
-  ​CMDL_FLOAT,+  ​CMDL_FP,
   CMDL_STR,   CMDL_STR,
   CMDL_IPV4,   CMDL_IPV4,
Line 205: Line 249:
 </​code>​ </​code>​
  
 +=== cmdl_params ===
 +Contains one named parameter set
 +
 +<code c>
 +typedef struct{
 +  char* set_name; // Name of the set
 +  int num_params; // The number of parameters the set contains
 +  cmdl_param** param; // An array of param pointers
 +}cmdl_params;​
 +</​code>​
 +
 +=== cmdl_param ===
 +Container class for parameter values. Only one parameter type is valid per parameter.
 +
 +<code c>
 +typedef struct{
 +  int valid_type; // Defines the param type (which pointer is valid)
 +
 +  // Pointers to available types
 +
 +  int* integer;
 +  double* fp;
 +  char* str;
 +  cmdl_ipv4* ipv4;
 +  cmdl_ipv6* ipv6;
 +  // ...
 +
 +}cmdl_param;​
 +
 +// with supporting structures like
 +
 +typedef struct{
 +  unsigned char octet[4];
 +}cmdl_ipv4;
 +
 +typedef struct{
 +  unsigned short int part[
 +
 +8];
 +}cmdl_ipv6;
 +
 +// ...etc
 +</​code>​
 +
 +==== Functions ====
 +Functions for the command implementation interface
 +
 +=== cmdl_param_list_set_create ===
 +Allocates a new list set and returns it.
 +
 +<​code>​
 +cmdl_param_list_set* cmdl_param_list_set_create();​
 +</​code>​
 +
 +=== cmdl_param_list_set_name ===
 +Names a given list set with a given name.
 +
 +<​code>​
 +void cmdl_param_list_set_name(cmdl_param_list_set* list_set, char* name);
 +</​code>​
 +
 +=== cmdl_param_list_set_desc ===
 +Adds a description to a given list set.
 +
 +<​code>​
 +void cmdl_param_list_set_desc(cmdl_param_list_set* list_set, char* desc);
 +</​code>​
 +
 +=== cmdl_param_list_set_add ===
 +Adds a parameter description to a given list set.
 +
 +<​code>​
 +void cmdl_param_list_set_add(cmdl_param_list_set* list_set, char* name, int type, char* example);
 +</​code>​
 +
 +
 +=== cmdl_param_list_create ===
 +Allocates and returns a parameter new parameter list.
 +
 +<​code>​
 +cmdl_param_list* cmdl_param_list_create();​
 +</​code>​
 +
 +=== cmdl_param_list_add ===
 +Adds a parameter list set to a given parameter list.
 +
 +<​code>​
 +void cmdl_param_list_add(cmdl_param_list* param_list, cmdl_param
 +</​code>​
 +
 +=== cmdl_printf ===
 +Prints formated text to a given command line.
 +
 +<​code>​
 +int cmdl_printf(cmd_line* cmd, const char *format, ...);
 +</​code>​
 +
 +=== cmdl_param_get_TYPE ===
 +Returns the given parameter from a cmdl_params as TYPE.
 +Rturns NULL if the parameter isn't a TYPE.
 +
 +<​code>​
 +int *cmdl_param_get_int(cmdl_params* params, int param_num);
 +cmdl_ipv4 *cmdl_param_get_ipv4(cmdl_params* params, int param_num);
 +...
 +</​code>​
  
 +==== Concerns ====
 +Perhaps this implementation would be a bit over the top. I got an email from Michael last week and he suggested, without reading this, that I should use ordinary C-style command structures (int argc, char** argv). That might not be as grandiose, and it would be harder to generate standardized automated help output, but it'd be much easier to implement. With some nice parse helper functions available to the command implementations,​ then perhaps it wouldn'​t be so bad. Hmm...
  
 ===== Status ===== ===== Status =====
  
 The command line is working and accepts input from the user, which it parses and then, at the moment, disregards. The command line is working and accepts input from the user, which it parses and then, at the moment, disregards.

Navigation

* [[:start|Home]] * [[:about|About our Project]] * [[:download|Download]] * [[:screenshots|Screenshots]] * Documentation * [[:howtos|HowTo Guides]] * [[:appnotes|Application Notes]] * [[:faq:|FAQs]] * [[:doc|General Doc]] * [[:talks|Videos, Talks, and Papers]] * [[:hardwareissues|Hardware Issues]] * [[:mailinglists|Mailing lists]] * [[http://support.etherboot.org/|Bugtracker]] * [[:contributing|Contributing]] * [[:editing_permission|Wiki Edit Permission]] * [[:wiki:syntax|Wiki Syntax]] * [[:contact|Contact]] * [[:relatedlinks|Related Links]] * [[:commerciallinks|Commercial Links]] * [[:acknowledgements|Acknowledgements]] * [[:logos|Logo Art]]

QR Code
QR Code soc:fredrikhultin (generated for current page)