/****************************************************************************/
/* Copyright (c) 2015 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  : Power Buoy Data Logger generic file-based data source class   */
/* Filename : fileSource.hpp                                                */
/* Author   : Henthorn                                                      */
/* Project  : Power Buoy                                                    */
/* Version  : 1.0                                                           */
/* Created  : 04/13/2015                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
/*                                                                          */
/* This is a generic class for file-based data sources. If the source can   */
/* be read through a file descriptor, then create a class based on this.    */
/*                                                                          */
/****************************************************************************/

#ifndef _FILESOURCE_
#define _FILESOURCE_

typedef char SourceID;
const SourceID BuoyConID  = 0x0;
const SourceID PneumConID = 0x1;
const SourceID BoostConID = 0x2;
const SourceID CrossbowID = 0x3;

class FileSource {

public:

   // Open a connection to the data source.
   //
   FileSource(const char *name) : _name(NULL), _fd(-1)
   { _name = strdup(name); }

   virtual ~FileSource()
   { if (_name) delete _name; }

   virtual int get_fd() { return _fd; }

   // Return 0 if full record was read
   // Otherwise, return the number of bytes still needed for
   // a full record.
   // Return < 0 on error.
   //
   virtual int read_data() { return 0; }

   // Return the latest full data record in the buffer supplied by the caller.
   // Return the number of bytes written to the buffer (0 or more).
   // Return < 0 on error.
   //
   virtual int get_record(const char *buffer) { return 0; }

protected:

   char *_name;
   int   _fd;

};

#endif
