Exemple #1
0
int
srvUstat (Connection * c)
{
  uint8_t tag;
  DListE *e;
  PgmState *p = c->p;
  RecTask *rt = &p->recorder_task;

  ipcSndS (c->sockfd, SRV_NOERR);
  /*
     first iterate thru all connections
     and send their rec. status
     can I find the address of the socket?
     getpeername... getsockname..
   */
  e = dlistFirst (&p->conn_active);
  while (e)
  {
    Connection *c2 = (Connection *) e;
    struct sockaddr a;
    socklen_t len;
    tag = 0xff;
    ipcSndS (c->sockfd, tag);
    memset (&a, 0, sizeof (a));
    len = sizeof (a);
    getpeername (c2->sockfd, &a, &len);
    ipcSndS (c->sockfd, a.sa_family);
    ioBlkWr (c->sockfd, a.sa_data, sizeof (a.sa_data)); //here, 14 bytes
    ipcSndS (c->sockfd, c2->super);
    ipcSndS (c->sockfd, c2->active);
    ipcSndS (c->sockfd, c2->pnr);
    e = dlistENext (e);
  }
  recTaskLock (rt);
  if (dlistFirst (&rt->active))
  {
    tag = 2;
    ipcSndS (c->sockfd, tag);   //done, recorder active
  }
  else
  {
    tag = 1;
    ipcSndS (c->sockfd, tag);   //done, recorder idle
  }
  recTaskUnlock (rt);

  return 0;
}
Exemple #2
0
void *dlockqueue_pop(void *q)
{
    dlockqueue *lqueue = q;
    dlistNode *node;
    void *value;
        
    if (lqueue == NULL || lqueue->l == NULL) {
        return NULL;
    }
    
    pthread_mutex_lock(&lqueue->lmutex);
    
    node = dlistFirst(lqueue->l);
    if (node == NULL) {
        pthread_mutex_unlock(&lqueue->lmutex);
        return NULL;
    }

    value = dlistNodeValue(node);

    dlistDelNode(lqueue->l, node);

    pthread_mutex_unlock(&lqueue->lmutex);

    return value;
}
Exemple #3
0
void
swdmxClear (SwDmx * dmx)
{
  SvcOut *o = NULL;
  while ((o = (SvcOut *) dlistFirst (&dmx->outputs)))
  {                             //release all outputs
    svtOutRmv (o);
  }
  selectorClear (&dmx->s);
  memset (dmx, 0, sizeof (*dmx));
}
Exemple #4
0
void *dlistPop(dlist *list) {
    dlistNode *node;
    void *value;
    
    node = dlistFirst(list);
    if (node == NULL) {
        return NULL;
    }

    value = dlistNodeValue(node);
    dlistDelNode(list, node);

    if (list->free) return NULL;
    
    return value;
}
Exemple #5
0
long long dlockqueue_push(void *q, void *value)
{
    dlockqueue *lqueue = q;
    dlist *list;
    long long length;
    
    pthread_mutex_lock(&lqueue->lmutex);
    length = (long long)dlistLength(lqueue->l);
    if (lqueue->maxlen >0 && length >= lqueue->maxlen) {
        if (lqueue->maxlen_policy == MAX_LENGTH_POLICY_REJECT) {
            length = -1;
        } else if (lqueue->maxlen_policy == MAX_LENGTH_POLICY_EVICT_HEAD) {
            while (length >= lqueue->maxlen) {
                dlistNode *ln = dlistFirst(lqueue->l);
                dlistDelNode(lqueue->l,ln);
                length = (long long)dlistLength(lqueue->l);
            }
            list = dlistAddNodeTail(lqueue->l, value);
            length ++;
        } else if (lqueue->maxlen_policy == MAX_LENGTH_POLICY_EVICT_END) {
            while (length >= lqueue->maxlen) {
                dlistNode *ln = dlistLast(lqueue->l);
                dlistDelNode(lqueue->l,ln);
                length = (long long)dlistLength(lqueue->l);
            }
            list = dlistAddNodeTail(lqueue->l, value);
            length ++;
        }
    } else {
        list = dlistAddNodeTail(lqueue->l, value);
        length ++;
    }
    pthread_mutex_unlock(&lqueue->lmutex);

    if (list == NULL) {
        return -1;
    }

    return length;
}
Exemple #6
0
int bitSWrite(BitStream *bs,char * file)
{
	FILE * fp;
	int nw,i;
	DListE *e;
	fp=fopen(file,"wt");
	assert(fp);
	
	assert(0==bs->nu);
	byte_write(fp,bs->nu);
	
	assert(bs->pe==0xb7);
	byte_write(fp,bs->pe);
	
	assert(get_cr(28)==0);//reserved==0
	for(i=0;i<4;i++)
	{
		byte_write(fp,bs->cregs[i]);
	}
//	byte_write(fp,bs->idunno);
	
	nw=dlistCount(&bs->windows);
	byte_write(fp,(nw>>8)&0x0ff);
	byte_write(fp,nw&0x0ff);
	e=dlistFirst(&bs->windows);
	while(e)
	{
		BitSWindow * w=(BitSWindow *)e;
		window_write(fp,w);
		e=dlistENext(e);
	}
	
	assert(bs->po==0xe7);
	byte_write(fp,bs->po);
	fclose(fp);
	return 0;
}
Exemple #7
0
int
srvRstat (Connection * c)
{
  uint8_t tag;
  DListE *e;
  PgmState *p = c->p;
  RecTask *rt = &p->recorder_task;

  ipcSndS (c->sockfd, SRV_NOERR);
  /*
     first iterate thru all connections
     and send their rec. status
     can I find the address of the socket?
     getpeername... getsockname..
   */
  e = dlistFirst (&p->conn_active);
  while (e)
  {
    Connection *c2 = (Connection *) e;
    if (recorderActive (&c2->quickrec))
    {
      RState rs;
      struct sockaddr a;
      socklen_t len;
      tag = 0xff;
      ipcSndS (c->sockfd, tag);
      memset (&a, 0, sizeof (a));
      len = sizeof (a);
      getpeername (c2->sockfd, &a, &len);
      //FIXXME: is it in net or host order?
      ipcSndS (c->sockfd, a.sa_family);
      ioBlkWr (c->sockfd, a.sa_data, sizeof (a.sa_data));       //here, 14 bytes
      ipcSndS (c->sockfd, c2->super);
      recorderGetState (&c2->quickrec, &rs);    //TODO: make sure recorder is not stopped asynch.. not properly synchronized?
      ipcSndS (c->sockfd, c2->quickrec.pnr);
      ipcSndS (c->sockfd, rs.time);
      ipcSndS (c->sockfd, rs.size);
    }
    e = dlistENext (e);
  }
  tag = 0;
  ipcSndS (c->sockfd, tag);     //start of scheduled recordings
  recTaskLock (rt);
  e = dlistFirst (&rt->active);
  while (e)
  {
    EitRec *er = dlistEPayload (e);
    taskLock (&er->t);
    tag = 0xfc;
    ipcSndS (c->sockfd, tag);
    rsSndEntry (er->e, c->sockfd);
    tag = er->eit_state;
    ipcSndS (c->sockfd, tag);
    ipcSndS (c->sockfd, er->start);
    ipcSndS (c->sockfd, er->last_eit_seen);
    ipcSndS (c->sockfd, er->last_id_seen);
    if (recorderActive (&er->rec))      //active, recording
    {
      RState rs;
      tag = 0xfd;
      ipcSndS (c->sockfd, tag); //active, running
      recorderGetState (&er->rec, &rs);
      ipcSndS (c->sockfd, er->rec.pnr);
      ipcSndS (c->sockfd, rs.time);
      ipcSndS (c->sockfd, rs.size);
    }
    else
    {
      tag = 0xfe;
      ipcSndS (c->sockfd, tag); //active, not running
    }
    taskUnlock (&er->t);
    e = dlistENext (e);
  }
  recTaskUnlock (rt);
  tag = 1;
  ipcSndS (c->sockfd, tag);     //done

  return 0;
}