Example #1
0
// ------------------------------------------
void PCPStream::readChanAtoms(AtomStream &atom, int numc, BroadcastState &bcs) {
/*	Channel *ch=NULL;
	ChanHitList *chl=NULL;
	ChanInfo newInfo;

	ch = chanMgr->findChannelByID(bcs.chanID);
	chl = chanMgr->findHitListByID(bcs.chanID);

	if (ch)
		newInfo = ch->info;
	else if (chl)
		newInfo = chl->info;*/

    Channel *ch = NULL;
    ChanHitList *chl = NULL;
    ChanInfo newInfo, chaInfo;

    ch = this->parent;
    if (ch) {
        newInfo = ch->info;
        chaInfo = ch->info;
    }

    for (int i = 0; i < numc; i++) {

        int c, d;
        ID4 id = atom.read(c, d);

        if ((id == PCP_CHAN_PKT) && (ch)) {
            readPktAtoms(ch, atom, c, bcs);
        } else if (id == PCP_CHAN_INFO) {
            newInfo.readInfoAtoms(atom, c);

        } else if (id == PCP_CHAN_TRACK) {
            newInfo.readTrackAtoms(atom, c);

        } else if (id == PCP_CHAN_BCID) {
            atom.readBytes(newInfo.bcID.id, 16);

        } else if (id == PCP_CHAN_KEY)            // depreciated
        {
            atom.readBytes(newInfo.bcID.id, 16);
            newInfo.bcID.id[0] = 0;                // clear flags

        } else if (id == PCP_CHAN_ID) {
            atom.readBytes(newInfo.id.id, 16);

            ch = chanMgr->findChannelByID(newInfo.id);
            chl = chanMgr->findHitListByID(newInfo.id);

        } else {
            LOG_DEBUG("PCP skip: %s,%d,%d", id.getString().str(), c, d);
            atom.skip(c, d);
        }
    }

    chl = chanMgr->findHitList(newInfo);

    if (!chl)
        chl = chanMgr->addHitList(newInfo);

    if (chl) {
        chl->info.update(newInfo);

        if (!servMgr->chanLog.isEmpty()) {
            //if (chl->numListeners())
            {
                try {
                    FileStream file;
                    file.openWriteAppend(servMgr->chanLog.cstr());

                    XML::Node *rn = new XML::Node("update time=\"%d\"", sys->getTime());
                    XML::Node *n = chl->info.createChannelXML();
                    n->add(chl->createXML(false));
                    n->add(chl->info.createTrackXML());
                    rn->add(n);

                    rn->write(file, 0);
                    delete rn;
                    file.close();
                } catch (StreamException &e) {
                    LOG_ERROR("Unable to update channel log: %s", e.msg);
                }
            }
        }

    }

    if (ch && !ch->isBroadcasting())
        ch->updateInfo(newInfo);


}