record.hxx

来自「vovida的软交换」· HXX 代码 · 共 270 行

HXX
270
字号
/* ====================================================================
 * The Vovida Software License, Version 1.0 
 * 
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
 *    and "Vovida Open Communication Application Library (VOCAL)" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact vocal@vovida.org.
 *
 * 4. Products derived from this software may not be called "VOCAL", nor
 *    may "VOCAL" appear in their name, without prior written
 *    permission of Vovida Networks, Inc.
 * 
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 * 
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by Vovida
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
 * Inc.  For more information on Vovida Networks, Inc., please see
 * <http://www.vovida.org/>.
 *
 */

/**
 * Record.hxx - 11/03/03.
 *
 * Abstract Class used to define generic methods and fields that all Record
 * objects share. Sub-class this class to get a concrete class that can obtain, * modify and store that data that your client is interested in.
 *
 */

#ifndef RECORD_HXX
#define RECORD_HXX

//#include "cpLog.h"
#include "DBConnection.hxx"
#include "RecordTypes.h"

#include <ctime>

class Record
{
public:
  /**
   * Standard constructor
   */
  Record();
  
  /**
   * Standard deconstructor
   */
  virtual ~Record();

  /**
   * populates this object from the database.
   * key is the key used to retrieve information, dbcon is a connection  
   * to the database (provided by the DBManager)
   * @param key   The key to use to populate this record
   *        dbcon A valid connection to the database
   * @return bool true if it works, otherwise false
   */
  virtual bool populateRecord(KeyType key, DBConnection* dbcon) = 0; 
 
  /**
   * amends this object in the database, returns true if nothing 
   * goes wrong
   * @param dbcon A valid connection to the database
   * @return bool true if it works, otherwise false
   */
  virtual bool amendRecord(DBConnection* dbconn) = 0;
  
  /**
   * deletes this object from the database, 
   * returns true if nothing goes wrong
   * @param dbcon A valid connection to the database
   * @return bool true if it works, otherwise false
   */
  virtual bool deleteRecord(DBConnection* dbconn) = 0;

  /**
   * inserts this object in the database, 
   * returns true if nothing goes wrong
   * @param dbcon A valid connection to the database
   * @return bool true if it works, otherwise false
   */
  virtual bool insertRecord(DBConnection* dbconn) = 0;

  /**
   * This function queries the database and returns a 
   * list of all the relavent keys that could be used 
   * to retrieve records of this type
   * @param dbcon A valid connection to the database
   * @return bool true if it works, otherwise false
   */
  virtual KeyList getAllKeys(DBConnection* dbconn) = 0;
  
  /*
   * The following methods have default implementations 
   * in this class 
   */



  /**
   * Displays the records (for debug)
   */
  virtual void displayRecord() { 
    displayRecord("Record.cxx");
  }
  /**
   * Displays the records (for debug)
   * @param prefix String to use to prefix the output
   */
  void displayRecord(string prefix);

  /*
   * The rest of the public methods are not virtual 
   */

  /**
   * The following is a static member function of record 
   * that is used to produce the different types of concrete 
   * Record classes. 
   * @param rec The type of record to create
   * @return Record* A pointer to a concrete sub-class of record
   */
  static Record* createNewRecord(RecordType rec);

  /**
   * The following function provides an exact duplicate of the record 
   * in the provided memory space. The caching system requires this.
   * @return Record* An exact, distinct copy of the class
   */
  virtual Record* clone() = 0;
  
  /**
   * Standard get/set methods for the protected members
   */

  /**   
   * @return KeyType The key used to populate this record (or "") if the 
   * record hasn't been populated.
   */
  KeyType getKey() {return key;};

  /**
   * @return time_t The last time this record was accessed 
   */
  time_t getLastAccessed() {return lastAccessed;};

  /** 
   * @return RecordType The type of this record 
   */
  RecordType getRecordType() {return recordType;};

  /**
   * Converts a record type to a string 
   * @param rec The record type to use
   * @return string A string containing the name of that record type
   */
  static string stringRecordType(RecordType rec);
  /** 
   * Converts a string containing a record type name to a record type
   * @param s A string containing a record type 
   * @return RecordType The record type represented by string, or UNKNOWN_RECORD
   */
  static RecordType convertStrRType(string s);

  /**
   * @param newKey The new value for the key of this record
   */
  void setKey(KeyType newKey) {key = newKey;};
  /** 
   * @param newLastAccessed The time this record was last accessed 
   */
  void setLastAccessed(time_t newLastAccessed) {lastAccessed = newLastAccessed;};

protected:
  /**
   * The key used to construct this record
   */
  KeyType key;           
  /** 
   * Timestamp of last access
   */
  time_t lastAccessed;   
    
  /**
   * @param newRecordType The new record type for this record (set by
   * each child class;
   */
  void setRecordType(RecordType newRecordType) { recordType = newRecordType; };
  
  /** 
   * Copys the data from this class to the supplied class
   * @param rec Pointer to a record to copy the data two
   */
  void copyData(Record* rec);
    
    
private:
  /**
   * String name for test records 
   */
  static const string TEST_RECORD_STR;
  /**
   * String name for generic (unknown) records 
   */
  static const string GENERIC_RECORD_STR;
  /**
   * String name for update records 
   */
  static const string UPDATE_REG_INFO_RECORD_STR;
  /**
   * String name for account records 
   */
  static const string ACCOUNT_RECORD_STR;
  /**
   * String name for alias records 
   */
  static const string ALIAS_RECORD_STR;
  /**
   * String name for feature records 
   */
  static const string FEATURE_RECORD_STR;
  /**
   * String name for dial plan records 
   */
  static const string PLAN_RECORD_STR;

  /** 
   * The record type of this record, set in constructors 
   * used for type checking
   */
  RecordType recordType; 



};

#endif // RECORD_HXX

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?