//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / ILMI protocol
//
//File: ilmiarstate_poll.cpp
//
//Version: $Revision: 1.3 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/07/09 13:09:07 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Timo Pärnänen
//
//Description:
//      See corresponding header file.
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History:

#include "pf/debug.h"
#include "ilmiarstate_poll.h"
#include "ilmiarstate_idle.h"
#include "ilmiarstate_prefix.h"

// Implementation of the singleton pattern

ilmiARState_Poll *ilmiARState_Poll::_only = 0;

ilmiARState_Poll *ilmiARState_Poll :: instance(void)
{
    if (_only == 0)
    {
        _only = new ilmiARState_Poll;
    }
    return _only;
}

ilmiARState_Poll :: ilmiARState_Poll(void)
{
    return;
}

ilmiARState_Poll :: ~ilmiARState_Poll(void)
{
    _only = 0;
    return;
}

void ilmiARState_Poll :: listPrefixes(ilmiAddressRegistration *protocol_,
                                      mgmtCommand &command_)
{
    debugUser("ilmiARState_Poll::listPrefixes");
    protocol_->storeLocalPrefixes(command_);
    protocol_->registerPrefixes();
    protocol_->changeState(ilmiARState_Prefix::instance());
    return;
}

void ilmiARState_Poll :: receiveGetResponse(
    ilmiAddressRegistration *protocol_,
    PDUInt &errorStatus_,
    AsnInt &errorIndex_,
    VarBindList &list_)
{
    debugUser("ilmiARState_Poll :: receiveGetResponse");
    if (errorStatus_ == PDUInt::noError)
    {
        protocol_->startPollTimer();
        protocol_->changeState(ilmiARState_Idle::instance());
    }
    else
    {
        start(protocol_);
    }
    return;
}

void ilmiARState_Poll :: ilmiARresponseTimeoutAct(
    ilmiAddressRegistration *protocol_)
{
    debugUser("ilmiARState_Poll::ilmiARresponseTimeoutAct");

    if (protocol_->isResending() != 0)
    {
        protocol_->sendGetNextRequest(firstNetworkPrefixTableEntry);
    }
    else
    {
        debugUser("ilmi connectivity lost, restart");
        start(protocol_);
    }
    return;
}



