portcoreinputunit.h

来自「一个语言识别引擎」· C头文件 代码 · 共 92 行

H
92
字号
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

/*
 * Copyright (C) 2006 Paul Fitzpatrick
 * CopyPolicy: Released under the terms of the GNU GPL v2.0.
 *
 */

#ifndef _YARP2_PORTCOREINPUTUNIT_
#define _YARP2_PORTCOREINPUTUNIT_

#include <yarp/PortCore.h>
#include <yarp/PortCoreUnit.h>
#include <yarp/Logger.h>
#include <yarp/InputProtocol.h>

namespace yarp {
    class PortCoreInputUnit;
}

/**
 * Manager for a single input to a port.  Associated
 * with a PortCore object.
 */
class yarp::PortCoreInputUnit : public PortCoreUnit {
public:
    // specifically for managing input connections

    PortCoreInputUnit(PortCore& owner, InputProtocol *ip, 
                      bool autoHandshake) : 
        PortCoreUnit(owner), ip(ip), phase(1), autoHandshake(autoHandshake) {

        YARP_ASSERT(ip!=NULL);
        closing = false;
        finished = false;
        running = false;
        name = owner.getName();
        ReadableCreator *creator = owner.getReadCreator();
        localReader = NULL;
        if (creator!=NULL) {
            localReader = creator->create();
        }
    }

    virtual ~PortCoreInputUnit() {
        closeMain();
        if (localReader!=NULL) {
            delete localReader;
            localReader = NULL;
        }
    }

    virtual bool start();

    virtual void run();

    virtual bool isInput() {
        return true;
    }

    // just for testing
    virtual void runSimulation();

    virtual void close() {
        closeMain();
    }

    virtual bool isFinished() {
        return finished;
    }

    const String& getName() {
        return name;
    }

    virtual Route getRoute();


private:
    InputProtocol *ip;
    SemaphoreImpl phase;
    bool autoHandshake;
    bool closing, finished, running;
    String name;
    Readable *localReader;

    void closeMain();
};

#endif

⌨️ 快捷键说明

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