Main Page | Class List | File List | Class Members | File Members

demo_db Class Reference

#include <demo_db.h>

Collaboration diagram for demo_db:

Collaboration graph
[legend]
List of all members.

Detailed Description

Simple text-file based database demo-application.

Demonstrates interfacing with the PC_ethernet_driver. Also useful as test-database for the driver.

Definition at line 31 of file demo_db.h.

Public Member Functions

 demo_db ()
 Constructor.
 ~demo_db ()
 Destructor is empty.
bool Init (int argc, char *argv[])
 Set some defaults and process any commandline options.
void Execution ()
 Main loop.
void OpenDatabase (string name="")
 Opens the database, using its Load() function throws an error when DBFilename is empty (which should at least have a default value).
void StartSocket ()
 Connects to an PC_Ethernet_Driver using the ServerIP and ServerPort values, which default to the standard port on localhost.
void OpenFormatFiles ()
 Load the formatting files for the DS175 and PC2.

Protected Member Functions

TagType ExtractTag (string &input)
 If a complete tag (starttag, data and endtag) is found in input, the tag is returned and removed from input.
string ProcessRequest (struct TagType data)
 Process a Tag according to its name (currently only request).
string GetOption (string options, string item)
 Get the value of an option-item from the options-string.
string Database_Lookup (string key)
 Lookup an item in the database and return its value.
string FormatDS175 (string data)
 Replace names in the format string, indicated by {name}, with the corresponding data from the database.
string FormatPC2 (string data)
 Replace names in the format string, indicated by {name}, with the corresponding data from the database.
bool CommandParser ()
 Display a prompt (when neccesary) and handle commands given by the user.
bool ReadCommand ()
 NON-Blocking read from stdin OR: read from keyboard (win32).


Constructor & Destructor Documentation

demo_db::demo_db  ) 
 

Constructor.

Initializes strings, ints and bools; only to make sure they have an "empty" value.

Returns:
Definition at line 54 of file demo_db.cpp.

demo_db::~demo_db  ) 
 

Destructor is empty.

Returns:
Definition at line 71 of file demo_db.cpp.


Member Function Documentation

bool demo_db::CommandParser  )  [protected]
 

Display a prompt (when neccesary) and handle commands given by the user.

Commands:

  • help: display a helptext, defined in demo_header.h
    See also:
    this helptext (CMDHELPTEXT) for more info on the available commands.
    Returns:
    true when the quit command was given.
Definition at line 429 of file demo_db.cpp.

string demo_db::Database_Lookup string  key  )  [protected]
 

Lookup an item in the database and return its value.

Parameters:
key string to search for in database.
Returns:
reply from the database.
Definition at line 354 of file demo_db.cpp.

void demo_db::Execution  ) 
 

Main loop.

Process input from the PC_Ethernet_Driver, and manage the commandprompt. Extracts Tags from input with ExtractTag() and processes them with ProcessRequest(). Definition at line 198 of file demo_db.cpp.

struct TagType demo_db::ExtractTag string &  input  )  [protected]
 

If a complete tag (starttag, data and endtag) is found in input, the tag is returned and removed from input.

Data outside a tag is discarded.

Parameters:
input 
Returns:
The first complete tag.
Definition at line 264 of file demo_db.cpp.

string demo_db::FormatDS175 string  data  )  [protected]
 

Replace names in the format string, indicated by {name}, with the corresponding data from the database.

data contains lines of the format "name: value". The result is obtained by replacing "{name}" with "value" in the Format-string.

Parameters:
data data form the database.
Returns:
formatted string containing the items from data.
Definition at line 368 of file demo_db.cpp.

string demo_db::FormatPC2 string  data  )  [protected]
 

Replace names in the format string, indicated by {name}, with the corresponding data from the database.

data contains lines of the format "name: value". The result is obtained by replacing "{name}" with "value" in the Format-string.

Parameters:
data data form the database.
Returns:
formatted string containing the items from data.
Definition at line 399 of file demo_db.cpp.

string demo_db::GetOption string  options,
string  item
[protected]
 

Get the value of an option-item from the options-string.

The name and value of an item are separated by a '=' character.

Parameters:
options string containing one or more options separated by spaces.
item string: name of the item to be found in options.
Returns:
string: value of the item; empty string if not found.
Definition at line 330 of file demo_db.cpp.

bool demo_db::Init int  argc,
char *  argv[]
 

Set some defaults and process any commandline options.

The defaults for the databasefilename, the server-IP and server-PORT are defined in the demo_header.h file. The -h and -v options cause this function to return true; which can be used to terminate the app.

Parameters:
argc 
argv[] 
Returns:
bool (Exit)
Definition at line 83 of file demo_db.cpp.

void demo_db::OpenFormatFiles  ) 
 

Load the formatting files for the DS175 and PC2.

The filenames are defined in the demo_header.h file (DS175FILENAME & PC2FILENAME) Sends a warning to stderr when a file is not found, but continues execution. (results in unformatted data being send to PCxx's) These files use the string <ESC> to represent the escape character for the PCxx-devices (\x1b). Definition at line 153 of file demo_db.cpp.

string demo_db::ProcessRequest struct TagType  tag  )  [protected]
 

Process a Tag according to its name (currently only request).

The database is searched for the data from the tag (usually a barcode) The answer from the database is then inserted into the format-string, depending on the type found in the tag-options, using the FormatDS175() and FormatPC2() functions. The resulting formatted answer is then packaged into a tag(-string) and returned to the calling function.

Parameters:
tag TagType struct, containing the name, options and data of a tag.
Returns:
Definition at line 230 of file demo_db.cpp.

bool demo_db::ReadCommand  )  [protected]
 

NON-Blocking read from stdin OR: read from keyboard (win32).

Returns:
Definition at line 489 of file demo_db.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Jun 16 15:47:18 for pc_demo.kdevelop by doxygen 1.3.8