⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datasource.c

📁 数据挖掘经典的hierarchial clustering algorithm
💻 C
📖 第 1 页 / 共 2 页
字号:
  ========================================================================
  DEVise Data Visualization Software
  (c) Copyright 1992-1996
  By the DEVise Development Group
  Madison, Wisconsin
  All Rights Reserved.
  ========================================================================

  Under no circumstances is this software to be copied, distributed,
  or altered in any way without prior permission from the DEVise
  Development Group.
*/

/*
  Implementation of DataSource class.
 */

/*
  $Id: DataSource.c,v 1.8 1996/12/13 21:34:20 jussi Exp $

  $Log: DataSource.c,v $
  Revision 1.8  1996/12/13 21:34:20  jussi
  Added checking of available semaphores.

  Revision 1.7  1996/12/03 20:36:02  jussi
  Added support for concurrent I/O.

  Revision 1.6  1996/08/04 21:23:22  beyer
  DataSource's are now reference counted.
  Added Version() which TData now check to see if the DataSource has changed,
    and if it has, it rebuilds its index and invalidates the cache.
  DataSourceFixedBuf is a DataSourceBuf that allocates and destoyes its
    own buffer.
  DerivedDataSource functionality is now in the TData constructor.
  Added some defaults for virtual methods.

  Revision 1.5  1996/07/01 19:31:30  jussi
  Added an asynchronous I/O interface to the data source classes.
  Added a third parameter (char *param) to data sources because
  the DataSegment template requires that all data sources have the
  same constructor (DataSourceWeb requires the third parameter).

  Revision 1.4  1996/05/22 17:51:55  wenger
  Extended DataSource subclasses to handle tape data; changed TDataAscii
  and TDataBinary classes to use new DataSource subclasses to hide the
  differences between tape and disk files.

  Revision 1.3  1996/05/07 22:28:14  jussi
  Reverted the changes made in the previous check-in because I
  found a better way to fix the problem where only the tail
  part of a schema file name is returned when a session is saved.

  Revision 1.2  1996/05/07 22:13:44  jussi
  Added virtual method getName() to DataSourceFile which returns
  the filename, not the regular name or alias. The filename is
  needed when a session file is saved.

  Revision 1.1  1996/05/07 16:04:17  wenger
  Added final version of code for reading schemas from session files;
  added an error-reporting class to improve error info.
 */

#define _DataSource_c_

//#define DEBUG

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include <unistd.h>

#include "DataSource.h"
#include "Util.h"
#include "DevError.h"
#include "tapedrive.h"


#if !defined(lint) && defined(RCSID)
static char     rcsid[] = "$RCSfile: DataSource.c,v $ $Revision: 1.8 $ $State: Exp $";
#endif

static char *   srcFile = __FILE__;

/*------------------------------------------------------------------------------
 * function: DataSource::DataSource
 * DataSource constructor.
 */
DataSource::DataSource(char *label, ViewGraph* controlling_view)
{
    DO_DEBUG(printf("DataSource::DataSource(%s)\n",
                    (label != NULL) ? label : "<null>"));

    _ref_count = 0;
    _label = NULL;
    if (label != NULL)
        _label = strdup(label);

    _version = 0;
    _controlling_view = NULL;

    _child = -1;
}

/*------------------------------------------------------------------------------
 * function: DataSource::~DataSource
 * DataSource destructor.
 */
DataSource::~DataSource()
{
    DO_DEBUG(printf("DataSource::~DataSource(%s)\n",
                    (_label != NULL) ? _label : "<null>"));

    DOASSERT(_ref_count == 0,
             "Deleting datasource with dangling references");

    if (_label != NULL) {
        delete [] _label;
    }
}


//---------------------------------------------------------------------------
void DataSource::AddRef()
{
    DO_DEBUG(printf("DataSource::AddRef(%s) refs=%d\n",
                    (_label != NULL) ? _label : "<null>", _ref_count));
    _ref_count++;
}


//---------------------------------------------------------------------------
// returns true if the caller should delete this object
bool DataSource::DeleteRef()
{
    DO_DEBUG(printf("DataSource::DeleteRef(%s) refs=%d\n",
                    (_label != NULL) ? _label : "<null>", _ref_count));
    _ref_count--;
    DOASSERT(_ref_count >= 0, "invalid datasource ref_count");
    // this could delete itself, but other old code still does that...
    // also, this could be statically allocated...
    return _ref_count == 0;
}



/*------------------------------------------------------------------------------
 * function: DataSource::getLabel
 * Get the label of a DataSource object.
 */
char *
DataSource::getLabel()
{
        DO_DEBUG(printf("DataSource::getLabel()\n"));

        return _label;
}

/*------------------------------------------------------------------------------
 * function: DataSource::Fgets
 * This is a dummy function to catch calls to Fgets() for derived classes
 * that don't implement it.
 */
char *
DataSource::Fgets(char *buffer, int size)
{
        DO_DEBUG(printf("DataSource::Fgets()\n"));

        fprintf(stderr, "Fgets method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return NULL;
}

/*------------------------------------------------------------------------------
 * function: DataSource::Fread
 * This is a dummy function to catch calls to Fread() for derived classes
 * that don't implement it.
 */
size_t
DataSource::Fread(char *buf, size_t size, size_t itemCount)
{
        DO_DEBUG(printf("DataSource::Fread()\n"));

        fprintf(stderr, "Fread method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return 0;
}

/*------------------------------------------------------------------------------
 * function: DataSource::Read
 * This is a dummy function to catch calls to Read() for derived classes
 * that don't implement it.
 */
size_t
DataSource::Read(char *buf, int byteCount)
{
        DO_DEBUG(printf("DataSource::Read()\n"));

        fprintf(stderr, "Read method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return 0;
}

/*------------------------------------------------------------------------------
 * function: DataSource::Fwrite
 * This is a dummy function to catch calls to Fwrite() for derived classes
 * that don't implement it.
 */
size_t
DataSource::Fwrite(const char *buf, size_t size, size_t itemCount)
{
        DO_DEBUG(printf("DataSource::Fwrite()\n"));

        fprintf(stderr, "Fwrite method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return 0;
}

/*------------------------------------------------------------------------------
 * function: DataSource::Write
 * This is a dummy function to catch calls to Write() for derived classes
 * that don't implement it.
 */
size_t
DataSource::Write(const char *buf, size_t byteCount)
{
        DO_DEBUG(printf("DataSource::Write()\n"));

        fprintf(stderr, "Write method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return 0;
}

/*------------------------------------------------------------------------------
 * function: DataSource::append
 * This is a dummy function to catch calls to append() for derived classes
 * that don't implement it.
 */
int
DataSource::append(void *buf, int recSize)
{
        DO_DEBUG(printf("DataSource::append()\n"));

        fprintf(stderr, "append method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return -1;
}

/*--------------------------------------------------------------------------*/
int DataSource::GetModTime()
{
  return -1;
}


/*--------------------------------------------------------------------------*/
Boolean DataSource::isFile()
{
  return false;
}


/*--------------------------------------------------------------------------*/
Boolean DataSource::isBuf()
{
  return false;
}


/*--------------------------------------------------------------------------*/
Boolean DataSource::isTape()
{
  return false;
}


/*------------------------------------------------------------------------------
 * function: DataSource::printStats
 * This is a dummy function to catch calls to printStats() for derived classes
 * that don't implement it.
 */
void
DataSource::printStats()
{
        DO_DEBUG(printf("DataSource::printStats()\n"));

        fprintf(stderr, "printStats method not implemented for class %s\n",
                objectType());
        DOASSERT(false, "");

        return;
}

/*============================================================================*/

//
// Kick off data source as a separate process
//

int DataSource::InitializeProc()
{
    if (_child >= 0) {
        fprintf(stderr, "Child process/thread exists already\n");
        return 0;
    }

    if (SemaphoreV::numAvailable() < 4) {
        // One semaphore needed for DataSource, and 3 more for DataPipe.
        return -1;
    }

    int status;
    _mutex = new SemaphoreV(Semaphore::newKey(), status, 1);
    if (!_mutex || status < 0) {
        fprintf(stderr, "Cannot create semaphore\n");
        return -1;
    }
    _mutex->setValue(1);

    if (pipe(_reqFd) < 0) {
        perror("pipe");
        return -1;
    }
#ifdef SOLARIS
    // Pipes are bi-directional in Solaris
    _replyFd[0] = _reqFd[1];
    _replyFd[1] = _reqFd[0];

⌨️ 快捷键说明

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