示例#1
0
/**
 * Add a new interface to this dlep instance
 * @param interf pointer to interface
 * @param ifname name of interface
 * @param l2_origin layer2 originator that shall be used
 * @param log_src logging source that shall be used
 * @param radio true if it is a radio interface, false for router
 * @return -1 if an error happened, 0 otherwise
 */
int
dlep_if_add(struct dlep_if *interf, const char *ifname,
    uint32_t l2_origin, enum oonf_log_source log_src, bool radio) {
  struct dlep_extension *ext;

  /* initialize key */
  strscpy(interf->l2_ifname, ifname,
      sizeof(interf->l2_ifname));
  interf->_node.key = interf->l2_ifname;

  if (abuf_init(&interf->udp_out)) {
    return -1;
  }

  /* add dlep prefix to buffer */
  abuf_memcpy(&interf->udp_out,
      _DLEP_PREFIX, sizeof(_DLEP_PREFIX) - 1);

  if (dlep_session_add(&interf->session,
      interf->l2_ifname, l2_origin,
      &interf->udp_out,
      radio, log_src)) {
    abuf_free(&interf->udp_out);
    return -1;
  }

  /* initialize stream list */
  avl_init(&interf->session_tree, avl_comp_netaddr_socket, false);

  /* initialize discovery socket */
  interf->udp.config.user = interf;
  interf->udp.config.receive_data = _cb_receive_udp;
  oonf_packet_add_managed(&interf->udp);

  /* initialize session */
  interf->session.cb_send_buffer = _cb_send_multicast;
  interf->session.cb_end_session = NULL;
  interf->session.restrict_signal =
      radio ? DLEP_PEER_DISCOVERY : DLEP_PEER_OFFER;
  interf->session.writer.out = &interf->udp_out;

  /* inform all extension */
  avl_for_each_element(dlep_extension_get_tree(), ext, _node) {
    if (radio) {
      if (ext->cb_session_init_radio) {
        ext->cb_session_init_radio(&interf->session);
      }
    }
    else {
      if (ext->cb_session_init_router) {
        ext->cb_session_init_router(&interf->session);
      }
    }
  }
  return 0;
}
示例#2
0
/**
 * Remove a packet socket from the global scheduler
 * @param pktsocket pointer to packet socket
 * @param force true if the socket should be removed instantly,
 *   false if it should be removed after the last packet in queue is sent
 */
void
oonf_packet_remove(struct oonf_packet_socket *pktsocket,
    bool force __attribute__((unused))) {
  // TODO: implement non-force behavior for UDP sockets
  if (list_is_node_added(&pktsocket->node)) {
    oonf_socket_remove(&pktsocket->scheduler_entry);
    os_fd_close(&pktsocket->scheduler_entry.fd);
    abuf_free(&pktsocket->out);

    list_remove(&pktsocket->node);
  }
}
示例#3
0
/**
 * destructor - called at unload
 */
#ifdef _WRS_KERNEL
void
olsrd_dotdraw_exit(void)
#else /* _WRS_KERNEL */
void
olsr_plugin_exit(void)
#endif /* _WRS_KERNEL */
{
  if (writetimer_entry) {
    close(outbuffer_socket);
    abuf_free(&outbuffer);
    olsr_stop_timer(writetimer_entry);
  }
  if (ipc_socket != -1) {
    CLOSE(ipc_socket);
  }
}
示例#4
0
void game_free(game_t *game)
{
	int i;

	printf("Game freeing!\n");

	// Free structures
	if(game->lv != NULL) level_free(game->lv);

	// Free action buffers
	if(game->ab_local != NULL)
		abuf_free(game->ab_local);
	for(i = 0; i < TEAM_MAX; i++)
		if(game->ab_teams[i] != NULL)
			abuf_free(game->ab_teams[i]);

	// Free AIs
	for(i = 0; i < TEAM_MAX; i++)
		if(game->ai_teams[i] != NULL)
			ai_free(game->ai_teams[i]);

	// Free
	free(game);
}
示例#5
0
int olsrd_write_cnf(struct olsrd_config *cnf, const char *fname) {
  FILE *fd;
  struct autobuf abuf;

  fd = fopen(fname, "w");

  if (fd == NULL) {
    fprintf(stderr, "Could not open file %s for writing\n%s\n", fname, strerror(errno));
    return -1;
  }

  printf("Writing config to file \"%s\".... ", fname);
  abuf_init(&abuf, 1024);
  olsrd_write_cnf_autobuf(&abuf, cnf);
  if (fwrite(abuf.buf, abuf.len, 1, fd) < (size_t)abuf.len) {
    fprintf(stderr, "Error, could not write the complete config file.\n");
  }
  abuf_free(&abuf);
  fclose(fd);

  printf("DONE\n");

  return 1;
}
示例#6
0
void
storageTask(
	void *param
)
{
	int ret;
	storageMsg_t msgData;
	storageMsg_t *msg = &msgData;
	unsigned int msg_prio;
	//int is_finish =0;
	printf("\nStorage thread enter ...\n\n");

	while (1) {
		ret = mq_receive(storageMsgQ, (char *) msg, sizeof(storageMsg_t), &msg_prio);
		if (ret < 0) {
			printf("[%s:%d], storage receive msg fail.\n", __FUNCTION__, __LINE__);
			continue;
		}

		//printf("receive storage msg %d, 0x%x\n", msg->cmd, msg->handle);
		if(msg->cmd == STORAGE_CMD_WRITE || msg->cmd == STORAGE_CMD_WRITE_AUDIO) {
			streamInfo_t *streamHandle = (streamInfo_t *) msg->handle;
			storageHandle_t *storageHandle = (storageHandle_t*) streamHandle->storageHandle;
			gpMuxPkt_t MuxPkt;
			
			int isAudio = (msg->cmd == STORAGE_CMD_WRITE_AUDIO) ? 1: 0;

			if (storageHandle && storageHandle->hdMux) {
				ret = 0;
				if (isAudio)
				{
					MuxPkt.data = (UINT8*)((audio_buffer_t*)(msg->buffer))->frame->pAddr;
					MuxPkt.size = msg->nBytes;
					MuxPkt.pts = msg->pts;//AUDIO_BUFFER_TIME;
					//printf("audio time =%d\n",msg->pts);
					if(storageHandle->hdMux)
						ret = g_save_Mux->pack(storageHandle->hdMux, &MuxPkt, GP_ES_TYPE_AUDIO);
						
					abuf_free((audio_buffer_t*)(msg->buffer));
				}
				else
				{
					IPC_Video_Frame_s* frame = ((video_buffer_t*)(msg->buffer))->frame;
					if (frame->thumb && storageHandle->hdMux)
					{
						MuxPkt.data = frame->thumb;
						MuxPkt.size = frame->thumb_size;
						ret = g_save_Mux->pack(storageHandle->hdMux, &MuxPkt, GP_ES_TYPE_THUMB);
					}
					MuxPkt.data = frame->pFrameAddr;
					MuxPkt.size = msg->nBytes;
					
					if (!storageHandle->time_lapse && (storageHandle->last_pts > 0) && (msg->pts > storageHandle->last_pts))
						MuxPkt.pts = msg->pts - storageHandle->last_pts;
					else
						MuxPkt.pts = 1000/storageHandle->framerate;
						
					if (MuxPkt.pts > 3600*1000) //avoid unexpected frame time 
					{
						printf("unexpected large frame time %u\n", MuxPkt.pts);
						MuxPkt.pts = 1000/storageHandle->framerate;
					}
					
					storageHandle->last_pts = msg->pts;
					MuxPkt.frameType = msg->frameType;
					if(storageHandle->hdMux)
						ret = g_save_Mux->pack(storageHandle->hdMux, &MuxPkt, GP_ES_TYPE_VIDEO);
						
					vbuf_free((video_buffer_t*)(msg->buffer));
				}
				
				if (ret != 0)
				{
					if (ret == MUX_MEM_FULL)
					{
						printf("[dvr] disk is full, stop recording.\n");
						streamHandle->status = STATUS_DISK_FULL;
					}
					else if (ret == MUX_FILE_SIZE_REACH)
					{
						printf("[dvr] reach maximum file size (2G), stop recording.\n");
						streamHandle->status = STATUS_FILE_SIZE_LIMIT;
					}
					else
					{
						printf("[dvr] unknown file error. stop recording.\n");
						streamHandle->status = STATUS_DISK_ERROR;
					}
					g_save_Mux->close(storageHandle->hdMux);
					storageHandle->hdMux = 0;
					if(storageHandle->file)
						fclose(storageHandle->file);
					free(storageHandle);
					streamHandle->storageHandle = NULL;
					sync();
				}
			}
			else
			{
				if (isAudio)
					abuf_free((audio_buffer_t*)(msg->buffer));
				else
					vbuf_free((video_buffer_t*)(msg->buffer));
			}
		}
		else if (msg->cmd == STORAGE_CMD_LOCK) {
			streamInfo_t *streamHandle = (streamInfo_t *) msg->handle;
			storageHandle_t *storageHandle = (storageHandle_t*) streamHandle->storageHandle;
			
			if(storageHandle->hdMux)
				g_save_Mux->set(storageHandle->hdMux, MUX_LOCK_FILE, 0);
		}
		else if (msg->cmd == STORAGE_CMD_FINISH) {
			streamInfo_t *streamHandle = (streamInfo_t *) msg->handle;
			storageHandle_t *storageHandle = (storageHandle_t*) streamHandle->storageHandle;
			//is_finish =1;
			if (storageHandle){
				if (storageHandle->hdMux) {
					g_save_Mux->close(storageHandle->hdMux);
					storageHandle->hdMux = 0;
				}
				if(storageHandle->file)
					fclose(storageHandle->file);
            	
				free(storageHandle);
				streamHandle->storageHandle = NULL;
				sync(); 
			}
		}
		else if (msg->cmd == STORAGE_CMD_CLOSE) {
			mq_close(storageMsgQ);
			break;
		}
	}
	printf("\nStorage thread exit ...\n\n");
}