Barry::Mode::Desktop Class Reference

#include <m_desktop.h>

List of all members.


Detailed Description

The main interface class to the device databases.

To use this class, use the following steps:

Definition at line 53 of file m_desktop.h.

Public Types

enum  CommandType

Public Member Functions

 Desktop (Controller &con)
 ~Desktop ()
void Open (const char *password=0)
 Select device mode.
void RetryPassword (const char *password)
 Retry a failed password attempt from the first call to Open().
const DatabaseDatabaseGetDBDB () const
 Returns DatabaseDatabase object for this connection.
unsigned int GetDBID (const std::string &name) const
 Get numeric database ID by name.
unsigned int GetDBCommand (CommandType ct)
 Get database command from command table.
void GetRecordStateTable (unsigned int dbId, RecordStateTable &result)
 Retrieve the record state table from the handheld device, using the given database ID.
void AddRecord (unsigned int dbId, Builder &build)
 Adds a record to the specified database.
void GetRecord (unsigned int dbId, unsigned int stateTableIndex, Parser &parser)
 Retrieves a specific record from the specified database.
void SetRecord (unsigned int dbId, unsigned int stateTableIndex, Builder &build)
 Overwrites a specific record in the device as identified by the stateTableIndex.
void ClearDirty (unsigned int dbId, unsigned int stateTableIndex)
 Clears the dirty flag on the specified record in the specified database.
void DeleteRecord (unsigned int dbId, unsigned int stateTableIndex)
 Deletes the specified record in the specified database.
void LoadDatabase (unsigned int dbId, Parser &parser)
 Retrieve a database from the handheld device, using the given parser to parse the resulting data, and optionally store it.
void SaveDatabase (unsigned int dbId, Builder &builder)
template<class RecordT, class StorageT>
void LoadDatabaseByType (StorageT &store)
template<class RecordT, class StorageT>
void SaveDatabaseByType (StorageT &store)
template<class StorageT>
void LoadDatabaseByName (const std::string &name, StorageT &store)
template<class StorageT>
void SaveDatabaseByName (const std::string &name, StorageT &store)
template<class RecordT>
void AddRecordByType (uint32_t recordId, const RecordT &rec)

Protected Member Functions

void LoadCommandTable ()
void LoadDBDB ()


Member Function Documentation

void Barry::Mode::Desktop::Open ( const char *  password = 0  ) 

Select device mode.

This is required before using any other mode-based operations, such as GetDBDB() and LoadDatabase().

This function opens a socket to the device for communicating in Desktop mode. If the device requires it, specify the password with a const char* string in password. The password will not be stored in memory inside this class, only a hash will be generated from it. After using the hash, the hash memory will be set to 0. The application is responsible for safely handling the raw password data.

You can retry the password by catching Barry::BadPassword and calling RetryPassword() with the new password.

Exceptions:
Barry::Error Thrown on protocol error.
std::logic_error() Thrown if unsupported mode is requested, or if socket already open.
Barry::BadPassword Thrown when password is invalid or if not enough retries left in the device.

Definition at line 140 of file m_desktop.cc.

References RetryPassword(), and Barry::Controller::SelectMode().

Referenced by main().

void Barry::Mode::Desktop::RetryPassword ( const char *  password  ) 

Retry a failed password attempt from the first call to Open().

Only call this function in response to Barry::BadPassword exceptions that are thrown from Open().

Exceptions:
Barry::Error Thrown on protocol error.
std::logic_error() Thrown if in unsupported mode, or if socket already open.
Barry::BadPassword Thrown when password is invalid or if not enough retries left in the device.

Definition at line 169 of file m_desktop.cc.

References LoadCommandTable(), LoadDBDB(), Barry::Controller::m_zero, and Barry::SocketZero::Open().

Referenced by Open().

const DatabaseDatabase& Barry::Mode::Desktop::GetDBDB (  )  const [inline]

Returns DatabaseDatabase object for this connection.

Must call Open() first, which loads the DBDB.

Definition at line 88 of file m_desktop.h.

Referenced by main().

unsigned int Barry::Mode::Desktop::GetDBID ( const std::string &  name  )  const

Get numeric database ID by name.

Parameters:
[in] name Name of database, which matches one of the names listed in GetDBDB()
Exceptions:
Barry::Error Thrown if name not found.

Definition at line 192 of file m_desktop.cc.

References Barry::DatabaseDatabase::GetDBNumber().

Referenced by AddRecordByType(), LoadDatabaseByType(), main(), and SaveDatabaseByType().

unsigned int Barry::Mode::Desktop::GetDBCommand ( CommandType  ct  ) 

Get database command from command table.

Must call Open() before this.

Definition at line 208 of file m_desktop.cc.

References Barry::CommandTable::GetCommand().

Referenced by Barry::DBPacket::ClearDatabase(), Barry::DBPacket::DeleteRecordByIndex(), Barry::DBPacket::GetDBDB(), Barry::DBPacket::GetRecordByIndex(), Barry::DBPacket::GetRecords(), Barry::DBPacket::GetRecordStateTable(), Barry::DBPacket::SetRecord(), Barry::DBPacket::SetRecordByIndex(), and Barry::DBPacket::SetRecordFlags().

void Barry::Mode::Desktop::GetRecordStateTable ( unsigned int  dbId,
RecordStateTable result 
)

Retrieve the record state table from the handheld device, using the given database ID.

Results will be stored in result, which will be cleared before adding.

Definition at line 239 of file m_desktop.cc.

References Barry::RecordStateTable::Clear(), Barry::Packet::Command(), Barry::DBPacket::GetRecordStateTable(), Barry::RecordStateTable::Parse(), and SB_COMMAND_DB_DONE.

Referenced by main().

void Barry::Mode::Desktop::AddRecord ( unsigned int  dbId,
Builder build 
)

Adds a record to the specified database.

RecordId is retrieved from build, and duplicate IDs are allowed by the device (i.e. you can have two records with the same ID) but *not* recommended!

Definition at line 266 of file m_desktop.cc.

References SB_COMMAND_DB_DONE, and Barry::DBPacket::SetRecord().

Referenced by AddRecordByType().

void Barry::Mode::Desktop::GetRecord ( unsigned int  dbId,
unsigned int  stateTableIndex,
Parser parser 
)

Retrieves a specific record from the specified database.

The stateTableIndex comes from the GetRecordStateTable() function. GetRecord() does not clear the dirty flag.

Definition at line 302 of file m_desktop.cc.

References Barry::Packet::Command(), Barry::DBPacket::GetRecordByIndex(), Barry::Data::GetSize(), Barry::DBPacket::Parse(), SB_COMMAND_DB_DATA, SB_COMMAND_DB_DONE, and SB_PACKET_RESPONSE_HEADER_SIZE.

Referenced by main().

void Barry::Mode::Desktop::SetRecord ( unsigned int  dbId,
unsigned int  stateTableIndex,
Builder build 
)

Overwrites a specific record in the device as identified by the stateTableIndex.

Definition at line 350 of file m_desktop.cc.

References Barry::Packet::Command(), Barry::DBPacket::ReturnCode(), SB_COMMAND_DB_DONE, and Barry::DBPacket::SetRecordByIndex().

void Barry::Mode::Desktop::ClearDirty ( unsigned int  dbId,
unsigned int  stateTableIndex 
)

Clears the dirty flag on the specified record in the specified database.

Definition at line 387 of file m_desktop.cc.

References Barry::Packet::Command(), SB_COMMAND_DB_DONE, and Barry::DBPacket::SetRecordFlags().

Referenced by main().

void Barry::Mode::Desktop::DeleteRecord ( unsigned int  dbId,
unsigned int  stateTableIndex 
)

Deletes the specified record in the specified database.

Definition at line 407 of file m_desktop.cc.

References Barry::Packet::Command(), Barry::DBPacket::DeleteRecordByIndex(), and SB_COMMAND_DB_DONE.

Referenced by main().

void Barry::Mode::Desktop::LoadDatabase ( unsigned int  dbId,
Parser parser 
)

Retrieve a database from the handheld device, using the given parser to parse the resulting data, and optionally store it.

See the RecordParser<> template to create a parser object. The RecordParser<> template allows custom storage based on the type of database record retrieved. The database ID and the parser Record type must match.

Parameters:
[in] dbId Database Database ID - use GetDBID()
[out] parser Parser object which parses the resulting protocol data, and optionally stores it in a custom fashion. See the RecordParser<> template.
Exceptions:
Barry::Error Thrown on protocol error.
std::logic_error Thrown if not in Desktop mode.

Definition at line 445 of file m_desktop.cc.

References Barry::Packet::Command(), Barry::DBPacket::GetRecords(), Barry::DBPacket::Parse(), SB_COMMAND_DB_DATA, and SB_COMMAND_DB_DONE.

Referenced by LoadDatabaseByType(), and main().


The documentation for this class was generated from the following files:
Generated on Wed Sep 24 21:27:33 2008 for Barry by  doxygen 1.5.1