[
Index ] [ Bottom ]

Process Template v2 library (Part 2)


[
Top | Index | Bottom | Source ]

void Replace_Tokens(char *string)
---------------------------------

lace_Tokens - replaces all the tokens on a string 

opsis
cription
lace_Tokens(string) replaces all the tokens on a string.  
ing: the string for which the tokens will be replaced.    


[
Top | Index | Bottom | Source ]

void Token_Replace(char *string)
--------------------------------

en_Replace -  replaces a given token with its value 

opsis
cription
en_Replace(string) replaces a given token with its value. 
ing: the token to be replaced.                           


[
Top | Index | Bottom | Source ]

int Attach_Table()
------------------

Initialize the shared memories;
if the memory does not exists it's created and attached
else only attached.
 

[
Top | Index | Bottom | Source ]

int Detach_Table()
------------------
 
 Detach the shared memories from a process.
 (called on exit)

[
Top | Index | Bottom | Source ]

int Delete_Table()
------------------
 
 Delete the shared memories.
 (only called when resetting the system)

[
Top | Index | Bottom | Source ]

int Read_from_Table(Table *entry, char *index_ptr)
--------------------------------------------------
 
Read process entry from memory; 
the table starting at location "index_ptr" is copied 
into the output arg "entry" 
 

[
Top | Index | Bottom | Source ]

char * Read_by_Index(Table *entry, int index)
---------------------------------------------
 
Read process entry from memory; 
the table at position "index" is copied 
into the output arg "entry". 
 
Return the pointer to beginning of "index"th table or NULL.
 

[
Top | Index | Bottom | Source ]

char * Search_Table(char *process_name)
---------------------------------------
 
Search in memory for process "process_name"; 
if the matching entry is found return the pointer to it,
else return NULL.
 
 The entries are linked by the field "next_table".

[
Top | Index | Bottom | Source ]

int Write_to_Table(Table *entry, char *index_ptr)
-------------------------------------------------
 
 Write the table "entry" to the location "index_ptr"
 

[
Top | Index | Bottom | Source ]

int Get_Table(Table new_entry[])
--------------------------------
 
 Make the output arg "new_entry" point to the list 
                                       of all proc tables.
 Return the number of procs found.
 (only called when resetting the system)

[
Top | Index | Bottom | Source ]

int Add_Entry_to_Table()
------------------------
 
 Add the process entry to the Common Table;
 
 The process name is first searched:
 if there is no entry for this process, 
    all the fields are filled and the entry is added at the end
    of the Table;
 if a match is found (but the proc is DEAD),
    if the number of variables matches,   
       the process_id and msgq_id are overwritten by new values;  
    else a new segment is allocated at the end  
       and the previous table is deleted (the segment is lost).
 

[
Top | Index | Bottom | Source ]

int Fill_Entry(Table *entry, int size)
--------------------------------------
 
 Fill  the fields of the "entry" structure.
 

[
Top | Index | Bottom | Source ]

char * Add_to_Table(Table *entry)
---------------------------------
 
 Add "entry" at the end of the table.
 
 Compute the new total size of the Common Table,
 search for the tail of the list of entries and 
 append the new one at the end.
 
 Return the pointer to the new entry.

[
Top | Index | Bottom | Source ]

void Get_Proc_and_Host(char *full,char *dest,char *node)
--------------------------------------------------------

Extract from "full" the name of the destination process and
of the node where it is running.

[
Top | Index | Bottom | Source ]

int Get_Value(char *process, char *varname, struct var_dict_type *var_ptr)
----------------------------------------------------------------------

 Read the value of a process variable;
 if the process is local the value is read from the sh memory 
 else a request is sent remotely.
 
 Before reading the variable, the values in the shared memory    
 are updated. (CANCELLED)
 
 fill the output structure "var_ptr". Remember:
    struct var_dict_type {
          char name[VAR_NAME];
          int  type;
          long  addr;
          };
 Memory space to hold the value is allocated internally 
 by var_read_variable() or ksnmp_vars_read_variable().
 A call to Free_Value() is needed to free this memory.
   
 Return SUCCESS or ERROR

[
Top | Index | Bottom | Source ]

Free_Value(struct var_dict_type *var_ptr)
-----------------------------------------
Free memory allocated in Get_Value() for the variable value.

[
Top | Index | Bottom | Source ]

int Send_Message(char *process_name, char *message,int ack_flag)
----------------------------------------------------------------

Sends "message" to process "process_name";
"process_name" can be on the same node as the sender or not.
Wait for acknowledge if "ack_flag" is TRUE (ACK_WAIT).
 
First "process_name" is split in two: the name of dest process
and the node where it runs (can be blank).
The name of the sending process is put as header to the message.
 
If the destination node is specified,  
   if it is local node: send_to_single() is called,
   if it is a remote node: ksnmp_send_message() is called.
If the destination node is not specified,  
   if the process is found in the local table: send_to_single(),  
   else  give error (search for the proc on the network?).
 

[
Top | Index | Bottom | Source ]

int Get_Ack(char *process_name, char *message)
----------------------------------------------

Check that process_name has received and executed the command 
contained in message. 
Useful when Set_Ack(FALSE) has been done before the Send_Message():
this means that the Send_Message() does not requires the ack itself,

[
Top | Index | Bottom | Source ]

void Set_Ack(int ack_flag)
--------------------------

Set the global variable wait_for_ack to the ack_flag. 
All the calls to Send_Message use the set value of wait_for_ack.
The default value is ACK_WAIT (TRUE)

[
Top | Index | Bottom | Source ]

int decode_filename(partial,full)
---------------------------------
checks if partial starts with an environment variable,
if so it tries to decode it.
The full filename is set in full. If the decoding fails
full will be the null-string.
Return codes:
      -1 The structure of partial is NOT ok
       -2 Partial does NOT start with a '$' or a '/'
       -3 The environment variable cannot be decoded
        0 all is ok

[
Top | Index | Bottom | Source ]

int get_nodes(char *nodelist,int nodesize,int *n_nodes)
-------------------------------------------------------

Get the list of all the nodes where the DAQ is running.

[
Top | Index | Bottom | Source ]

char * get_name_from_args(int argc, char **argv)
------------------------------------------------

Extract the argument of the option "-n", 
that corresponds to the process name.

[
Top | Index | Bottom | Source ]

float stof(char *str)
---------------------
Convert string to float value.

[
Top | Index | Bottom | Source ]

int Add_Vars_to_Table()
-----------------------

 Called by Template_Init

 Add User and System variables to the shared memory
 at initialization time;
 variables are placed just after the process table
 and represented in memory as: SIZE_TYPE_NAME_VALUE.
 
 The value can be integer, real, string or sequence of bytes;
 If it is a string, the max allowed lenght (VAR_LENGTH) 
 is allocated;
 If it is a BYTESEQ, we allocate the max allowed lenght BITESEQ_SIZE 
 + the space to hold the actual lenght of the sequence (since  
 there is no termination character).  
 
 As the name string can occupy a odd number of chars,
 the alignment to a even address is done before adding
 the next var.
 

[
Top | Index | Bottom | Source ]

int add_var_entry(char *begin, int size, int type, char *varname, char *value)
----------------------------------------------------------------------

 Called for each user and sys variable by Add_Vars_to_Table;

 starting at "begin" address,
 copy to memory "size", "type", "varname" and "value".
 

[
Top | Index | Bottom | Source ]

int var_set_value(char *varname, char *value)
---------------------------------------------

 Write the value of an existing variable in memory;

 point to the vars block,
 get the pointer to the segment related to "varname" 
 copy "value" in shared memory, with appropriate size
 

[
Top | Index | Bottom | Source ]

int var_set_all_values()
------------------------
set the value of all user and system level variables in memory 

[
Top | Index | Bottom | Source ]

int var_read_value(char *procname,char *varname,
                   short *ret_type, char *value)
------------------------------------------------

 Read from memory the value of a variable belonging to
 a local process. 
 Space for value must be allocated externally.
 
 See Get_Value() (utillib.c) for reading variables
 of remote/local processes.

 point to the table of process "procname",
 point to its vars block,
 get the pointer to the segment related to "varname" 
 
 fill the output args  "ret_type", "ret_size" and "value".
 

[
Top | Index | Bottom | Source ]

int var_read_variable(char *procname,char *varname,
                   short *ptr_type, char **ptr_value)
-----------------------------------------------------

 Read from memory the value of a variable belonging to
 a local process, allocating  the space for value.
 
 See Get_Value() (utillib.c) for reading variables
 of remote/local processes.

 point to the table of process "procname",
 point to its vars block,
 get the pointer to the segment related to "varname" 
 
 fill the output args  "ptr_type" and "ptr_value".
 

[
Top | Index | Bottom | Source ]

int var_get_datasegment(char *ptr,int var_number,
                        char *varname,struct data_pointer *dp)
--------------------------------------------------------------

Retrieve the memory segment related to the variable "varname";

starting at "ptr" (beginning of vars block),
loop on varibles until "varname" is found or up to "var_number",
fill the output "dp".


[
Top | Index | Bottom | Source ]

char *var_read_by_index(int proc_index, int var_index,  
                            struct data_values *d_val)
--------------------------------------------------------

 Read from shared memory the segment related 
   to "var_index"th variable of "proc_index"th process;

 point to the table of process "proc_index",
 point to its vars block,
 get the segment located at "var_index" position,
 fill the output arg "d_val" with the values from d_seg. 
 
 Return a value != NULL if the wanted variable has been found.

[
Top | Index | Bottom | Source ]

int var_get_indexsegment(char *ptr,int var_index,struct data_pointer *dp)
----------------------------------------------------------------------

Retrieve the memory segment related to the "var_index"th variable;

starting at "ptr" (beginning of vars block),
loop on vars until pointing to "var_index" variable;
fill the output "dp".


[
Top | Index | Bottom | Source ]

void var_fill_data_pointer(char *begin,struct data_pointer *dp)
---------------------------------------------------------------

Make the output "dp" point at the contents of 
     memory segment starting at "begin".


[
Top | Index | Bottom | Source ]

int vars_check_size()
---------------------

Called by Add_Entry_to_Table (when a new process subscribes)

Calculate the amount of space needed for all process vars;
do not forget the alignment to even address. 


[
Index ] [ Top ]
Created 25/06/97 16:40 by source2html v0.9