Esempio n. 1
0
int main(int argc,char** argv)
{
	LList* l = new LList();
	l->add(1)->p()->add(2)->p()->add(4)->p()->add(10)->p()->add(80)->p();
	l->reverse()->p();
	l->remove(44)->p()->remove(2)->p()->remove(10)->p()->remove(80)->p()->remove(1)->p()->remove(4)->p()->remove(99)->p();


	StackL* s = new StackL();
	s->push(1)->p()->push(2)->p()->push(5)->p()->push(3)->p();
	s->pop();
	s->p();
	s->pop();
	s->p();
	s->pop();
	s->p();
	s->pop();
	s->p();

	QueueL* q = new QueueL();
	q->enq(1)->p()->enq(2)->p()->enq(5)->p();
	q->dq()->p()->dq()->p()->dq()->p();

	return 0;
}
Esempio n. 2
0
LList<uint16> *  GroupTagSubscription::getTags (void)
{
    if (_ui16Tags.getCount() <= 0) {
        return NULL;
    }
    LList<uint16> *pRet = new LList<uint16>();
    for (UInt32Hashtable<TagInfo>::Iterator i = _ui16Tags.getAllElements(); !i.end(); i.nextElement()) {
        pRet->add (i.getKey());
    }
    return pRet;
}
Esempio n. 3
0
void PositionUpdater::run (void)
{
    const char *pszMethodName = "PositionUpdater::run";
    setName (pszMethodName);

    started();

    BufferWriter bw;
    do {
        _m.lock();
        if (!_bMessageRequested) {
            _cv.wait (DSPro::DEFAULT_UPDATE_TIMEOUT);
        }

        if (pTopoLog != nullptr) {
            if ((_pDSPro != nullptr) && (_pDSPro->_pTopology != nullptr)) {
                logTopology (pszMethodName, Logger::L_Info, "\n==== TOPOLOGY ===\n");
                _pDSPro->_pTopology->display (pTopoLog->getLogFileHandle());
                logTopology (pszMethodName, Logger::L_Info, "\n=================\n");
            }
        }

        LList<MsgIdWrapper> msgToRequestCpy;
        int64 i64Now = getTimeInMilliseconds();
        for (MsgIdWrapper *pMsgIdWr = _msgToRequest.getFirst(); pMsgIdWr != nullptr; pMsgIdWr = _msgToRequest.getNext()) {
            msgToRequestCpy.add (*pMsgIdWr); // copy the IDs of the message to request
            pMsgIdWr->ui64LatestRequestTime = i64Now;
        }
        _msgToRequest.removeAll();

        StringHashtable<LList<String> > *pMsgToNotify = _pMsgToNotify;
        _pMsgToNotify = new StringHashtable<LList<String> >(true, true, true, true);

        _m.unlock();

        MsgIdWrapper msgIdWr;
        for (int rc = msgToRequestCpy.getFirst (msgIdWr); rc == 1; rc = msgToRequestCpy.getNext (msgIdWr)) {
            int64 i64Elapsed = i64Now - msgIdWr.ui64LatestRequestTime;
            if (msgIdWr.ui64LatestRequestTime == 0U || (i64Elapsed > DSPro::DEFAULT_UPDATE_TIMEOUT)) {
                Targets **ppTargets;
                if (msgIdWr.senderId.length() <= 0) {
                    ppTargets = _pDSPro->_pTopology->getNeighborsAsTargets();
                }
                else {
                    ppTargets = _pDSPro->_pTopology->getForwardingTargets (_pDSPro->getNodeId(), msgIdWr.senderId);
                }
                if ((ppTargets != nullptr) && (ppTargets[0] != nullptr)) {
                    int rc = 0;
                    String publisher (msgIdWr.publisherId.length() <= 0 ? _pDSPro->getNodeId() : msgIdWr.publisherId.c_str());
                    if (isOnDemandDataID (msgIdWr.msgId)) {
                        rc = _pDSPro->_adaptMgr.sendChunkRequestMessage (msgIdWr.msgId, &(msgIdWr.locallyCachedChunkIds),
                                                                         publisher, ppTargets);
                    }
                    else {
                        rc = _pDSPro->_adaptMgr.sendMessageRequestMessage (msgIdWr.msgId, publisher, ppTargets);
                    }
                    if (rc == 0) {
                        checkAndLogMsg (pszMethodName, Logger::L_Info, "Requested request "
                                        "message with id: <%s>.\n", msgIdWr.msgId.c_str());
                    }
                    else {
                        checkAndLogMsg (pszMethodName, Logger::L_Warning, "Can not request message with "
                                        "id = <%s> failed. Returned %d\n", msgIdWr.msgId.c_str(), rc);
                    }
                }
                Targets::deallocateTargets (ppTargets);
            }
        }

        doMetadataArrived (pMsgToNotify);
        delete pMsgToNotify;

        _m.lock();
        _bMessageRequested = false;
        int64 i64Tmp = _i64TimeStamp;
        _m.unlock();

        if ((getTimeInMilliseconds() - i64Tmp) > DSPro::DEFAULT_UPDATE_TIMEOUT) {

            if (_pNodeContexMgr->getActivePeerNumber() == 0) {
                continue;
            }

            bw.reset();
            int rc = _pNodeContexMgr->updatePosition (&bw);
            if (rc < 0) {
                checkAndLogMsg (pszMethodName, Logger::L_MildError, "Could not write "
                                "the way point message. Error code %d.\n", rc);
                continue;
            }

            _m.lock();
            _i64TimeStamp = getTimeInMilliseconds();
            _m.unlock();

            _pDSPro->sendWaypointMessage (bw.getBuffer(), bw.getBufferLength());
        }

        if (_pDSPro->_bEnableTopologyExchange && _bTopologyHasChanged) {
            _bTopologyHasChanged = false;
            BufferWriter bw (1024, 1024);
            if (_pDSPro->_pTopology->write (&bw, 0) == 0) {
                Targets **ppTargets = _pDSPro->_pTopology->getNeighborsAsTargets();
                if ((ppTargets != nullptr) && (ppTargets[0] != nullptr)) {
                    int rc = _pDSPro->_adaptMgr.sendTopologyReplyMessage (bw.getBuffer(), bw.getBufferLength(), ppTargets);
                    if (rc != 0) {
                        checkAndLogMsg (pszMethodName, Logger::L_Warning, "Can not send "
                                        "topology reply message. Returned %d\n", rc);
                    }
                    else {
                        checkAndLogMsg (pszMethodName, Logger::L_Info,
                                        "sent topology reply.\n");
                    }
                }
                Targets::deallocateTargets (ppTargets);
            }
        }

    } while (!terminationRequested());

    terminating();
}