示例#1
0
int			receive_clients(int fd)
{
  t_fd			fds;
  int			ret;
  t_all			all;

  init_buffer(&(all.buf));
  all.fds = &fds;
  all.channel = NULL;
  all.fds->fd_s = fd;
  all.actual = NULL;
  new_channel(&all, "toto");
  new_channel(&all, "titi");
  if ((add_fd(&all, SERVER_ID, fd, &serv_ptr)) == -1)
    return (-1);
  while (1)
    {
      all.fds->max_fd = set_fds(&all, &(all.fds->fd_read));
      FD_ZERO(&(all.fds->fd_write));
      if ((ret = select(all.fds->max_fd + 1, &(all.fds->fd_read),
			&(all.fds->fd_write),
			NULL, NULL)) == -1)
	return (1);
      check_fd(&all);
    }
  return (0);
}
示例#2
0
static gboolean
example_csh_room_manager_request (ExampleCSHRoomManager *self,
                                  gpointer request_token,
                                  GHashTable *request_properties,
                                  gboolean require_new)
{
  TpHandle handle;
  ExampleCSHRoomChannel *chan;
  GError *error = NULL;

  if (tp_strdiff (tp_asv_get_string (request_properties,
          TP_PROP_CHANNEL_CHANNEL_TYPE),
      TP_IFACE_CHANNEL_TYPE_TEXT))
    {
      return FALSE;
    }

  if (tp_asv_get_uint32 (request_properties,
      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, NULL) != TP_HANDLE_TYPE_ROOM)
    {
      return FALSE;
    }

  handle = tp_asv_get_uint32 (request_properties,
      TP_PROP_CHANNEL_TARGET_HANDLE, NULL);
  g_assert (handle != 0);

  if (tp_channel_manager_asv_has_unknown_properties (request_properties,
        fixed_properties, allowed_properties, &error))
    {
      goto error;
    }

  chan = g_hash_table_lookup (self->priv->channels, GUINT_TO_POINTER (handle));

  if (chan == NULL)
    {
      new_channel (self, handle, self->priv->conn->self_handle,
          request_token);
    }
  else if (require_new)
    {
      g_set_error (&error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
          "A Text channel for room #%u already exists", handle);
      goto error;
    }
  else
    {
      tp_channel_manager_emit_request_already_satisfied (self,
          request_token, TP_EXPORTABLE_CHANNEL (chan));
    }

  return TRUE;

error:
  tp_channel_manager_emit_request_failed (self, request_token,
      error->domain, error->code, error->message);
  g_error_free (error);
  return TRUE;
}
示例#3
0
static int join_hook(int argc, char *argv[])
{
	assert(argc == 2);
	/**********************************************
	 * allow something like:
	 *  /join #channel1 #channel2
	 **********************************************/
	if (strstr(argv[1], " ")) {
		int i;
		char **tmp_argv;
		int tmp_argc;
		char *orig = argv[1];
		make_argv(&tmp_argc, &tmp_argv, argv[1]);
		for (i = 0; i < tmp_argc; i++) {
			argv[1] = tmp_argv[i];
			join_hook(argc, argv);
		}
		free_argv(tmp_argc, tmp_argv);
		argv[1] = orig;
		return 0;
	}

	channel_t *tmp;

	tmp = find_channel(argv[1], irc_pick_server());

	if (tmp == NULL)
		tmp = new_channel(argv[1], irc_pick_server());

	tmp->set_window(tmp, active_window <= window_max
			&& active_window > 0 ? active_window : 0);
	tmp->join(tmp);
	return 0;
}
示例#4
0
void set_global() {
    if (packets[pnum].cmds.size() < NCHANNELS) {
        for (int i=0; i<NCHANNELS; i++) {
            if (!isChannelIncluded(packets[pnum], i)) {
                new_channel(i);
            }
        }
    }
    for (int i=0; i<NCHANNELS; i++) {
        if (debug_) printf("global: enabling channel %d\n", i);
        packets[pnum].cmds[i].ena = true; 
        packets[pnum].cmds[i].upd = true; 
    }
    flag_global = true;
}
示例#5
0
文件: carbon_gui.cpp 项目: dyne/MuSE
bool CARBON_GUI::new_channel() 
{
	int i;
	lock();
	for (i=0;i<MAX_CHANNELS;i++) {
		if(channel[i] == NULL) {
			if(new_channel(i)) {
				unlock();
				return true;
			}
		}
	}
	unlock();
	msg->warning("Actually MuSE doesn't support more than %d parallel input channels",MAX_CHANNELS);
	return false;
}
示例#6
0
static int end_of_names_hook(int argc, char *argv[])
{
	const char **nicks = users_in_channel(argv[3]);
	channel_t *ch = find_channel(argv[3], irc_pick_server());
	int del_chn = 0;
	if(ch == NULL) {
		ch = new_channel(argv[3], irc_pick_server());
		del_chn = 1;
	}
	int j;

	/**************************************
	 * find the longest nick
	 **************************************/
	int longest = 0;
	for(j = 0; nicks[j] != NULL; j++) {
		if(strlen(nicks[j]) > longest)
			longest = strlen(nicks[j]);
	}

	int sizex = io_get_width();
	int times = sizex / (longest + 4);

	/**************************************
	 * show the nicks
	 **************************************/
	wio_colored_out(ch->win, USER_BLUE, " [%s]\n", argv[3]);
	if(nicks[1] != NULL) {
		for(j = 0; nicks[j] != NULL; j++) {
			if(j && j % times == 0)
				wio_out(ch->win, "\n");
			wio_colored_out(ch->win, USER_RED, " [");
			wio_colored_out(ch->win, USER_WHITE, "%-*s", longest, nicks[j]);
			wio_colored_out(ch->win, USER_RED, "] ");
		}
		wio_out(ch->win, "\n");
	}

	free(nicks);

	if(del_chn)
		delete_channel(ch);
	return 0;

}
示例#7
0
bool set_channel(std::vector<uint8_t> data) {
    int num = decode_be(data);
    if (num <= NCHANNELS) {
        if (debug_) printf("set channel number=%d\n", num);
        if (num == 0) {
            flag_global = true;
            chan = num;
            set_global();
        } else {
            flag_global = false;
            chan = num - 1;
            if (!isChannelIncluded(packets[pnum], num)) 
                new_channel(chan);
        }
        return true;
    }
    if (debug_) printf("failed to set channel number=%d\n", num);
    return false;
}
示例#8
0
static gboolean
simulate_incoming_call_cb (gpointer p)
{
  ExampleCallManager *self = p;
  TpHandleRepoIface *contact_repo;
  TpHandle caller;

  /* do nothing if we've been disconnected while waiting for the contact to
   * call us */
  if (self->priv->available_id == 0)
    return FALSE;

  /* We're called by someone whose ID on the IM service is "caller" */
  contact_repo = tp_base_connection_get_handles (self->priv->conn,
      TP_HANDLE_TYPE_CONTACT);
  caller = tp_handle_ensure (contact_repo, "caller", NULL, NULL);

  new_channel (self, caller, caller, NULL, TRUE, FALSE);

  return FALSE;
}
示例#9
0
void create_channel(ServiceRecord *sc){
	ChannelState * state = new_channel();
	if (state == NULL) return;
	state->remote_addr = sc->remote_addr;
	state->ccb.client_process = home_channel_state.ccb.client_process;
	state->ccb.callback = home_channel_state.ccb.callback;
	state->rate = home_channel_state.rate;
	DataPayload *new_dp = &(state->packet);
	clean_packet(new_dp);

	ConnectMsg *cm = (ConnectMsg *)new_dp->data;
	strcpy(cm->name, controller_name);
	cm->rate = uip_htons(state->rate);
	new_dp->hdr.dst_chan_num = 0;
	new_dp->hdr.src_chan_num = state->chan_num;
    (new_dp)->hdr.cmd = CONNECT; 
    (new_dp)->dhdr.tlen = uip_htons(sizeof(ConnectMsg));
	send_on_knot_channel(state,new_dp);
	state->state = STATE_CONNECT;
	state->ticks = 10;
}
示例#10
0
文件: net.c 项目: loudambiance/rirc
static server*
new_server(char *host, char *port)
{
	server *s;

	if ((s = calloc(1, sizeof(*s))) == NULL)
		fatal("calloc");

	/* Set non-zero default fields */
	s->soc = -1;
	s->iptr = s->input;
	s->nptr = config.nicks;
	s->host = strdup(host);
	s->port = strdup(port);

	auto_nick(&(s->nptr), s->nick);

	s->channel = ccur = new_channel(host, s, NULL, BUFFER_SERVER);

	DLL_ADD(server_head, s);

	return s;
}
示例#11
0
文件: audio.c 项目: eriser/synth-3
static Chunk *new_chunk(Song *song, size_t nb_channels)
{
    Chunk *chunk;
    song->nb_chunks++;
    if(song->chunks_l)
    {
        song->chunks_l->next = malloc(sizeof(Chunk));
        song->chunks_l = song->chunks_l->next;
    }
    else
        song->chunks_f = song->chunks_l = malloc(sizeof(Chunk));
    chunk = song->chunks_l;
    chunk->next = NULL;

    chunk->nb_channels = nb_channels;
    chunk->pos = 0;
    chunk->channels = malloc(sizeof(Channel*) * nb_channels);

    if(g_debug)
        fprintf(stderr, "Creating channel 0\n");
    chunk->channels[0] = new_channel();
    return chunk;
}
servercontroller::servercontroller( QWidget*, const char* name )
    : KMainWindow( 0, name )
{
  we_are_exiting = false;
  m_notificationCount = 0;

  m_ncm = new nickColourMaker();

  MenuBar = menuBar();
  KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );

  s_self = this;

  switch (ksopts->displayMode)
  {
    case KSOptions::SDI:
        displayMgr = new DisplayMgrSDI();
        break;
    case KSOptions::MDI:
        displayMgr = new DisplayMgrMDI();
        break;
  }

  sci = new scInside(this, QCString(name) + "_mainview");
  setCentralWidget(sci);

  sci->setFrameStyle(QFrame::Box | QFrame::Raised);
  ConnectionTree = sci->ConnectionTree;

  connect(ConnectionTree, SIGNAL(clicked( QListViewItem * )),
	  this, SLOT(WindowSelected(QListViewItem *)));

  setFrameBorderWidth(5);

  QPopupMenu *file = new QPopupMenu(this, QCString(name) + "_menu_file");
  KStdAction::quit(this, SLOT(endksirc()), actionCollection())->plug(file);
#ifndef NDEBUG
  file->insertItem(i18n("Dump Object Tree"), this, SLOT(dump_obj()));
  file->insertItem(i18n("Server Debug Window"), this, SLOT(server_debug()));
#endif
  MenuBar->insertItem(i18n("&File"), file);

  connections = new QPopupMenu(this, QCString(name) + "_menu_connections");

  server_id = connections->insertItem(i18n("&New Server..."), this, SLOT(new_connection()), Key_F2 );
  join_id = connections->insertItem(i18n("&Join Channel..."), this, SLOT(new_channel()), Key_F3 );
  connections->insertSeparator();
  connections->insertItem(i18n("&Do Autoconnect..."), this, SLOT(start_autoconnect_check()));
  connections->setItemEnabled(join_id, FALSE);
  MenuBar->insertItem(i18n("&Connections"), connections);

  options = new QPopupMenu(this, QCString(name) + "_menu_options");
  options->setCheckable(TRUE);

  options->insertItem(SmallIcon( "filter" ), i18n("&Filter Rule Editor..."),
		      this, SLOT(filter_rule_editor()));
  options->insertSeparator();
  KStdAction::configureNotifications(this, SLOT(notification_prefs()), actionCollection())->plug(options);

  KStdAction::preferences(this, SLOT(general_prefs()), actionCollection())->plug(options);

  MenuBar->insertItem(i18n("&Settings"), options);

  KHelpMenu *help = new KHelpMenu( this, kapp->aboutData() );
  MenuBar->insertItem( KStdGuiItem::help().text(), help->menu() );

  m_kga = new KGlobalAccel(this, "globalAccess");
  m_kga->insert("New Server", i18n("New Server"),
		i18n("This action allows you to open a new server more easily "
		     "when in docked mode, since you don't need to click on the "
		     "dock icon."),
		ALT+CTRL+Key_C, KKey::QtWIN+CTRL+Key_C, this,
		SLOT(new_connection()));

  open_toplevels = 0;

  pic_server = UserIcon("server");
  pic_gf = UserIcon("ksirc_a");
  pic_run = UserIcon("mini-run");
  pic_ppl = UserIcon("channels");
  pic_icon = UserIcon("ksirc_b");

  setCaption( i18n("Server Control") );
  KWin::setIcons(winId(), pic_icon, pic_server);

  resize( 450,200 );

  dockWidget = new dockServerController(this, 0x0, "servercontroller_dock");
  KWin::setSystemTrayWindowFor( dockWidget->winId(), winId() );

  m_kga->readSettings();
  m_kga->updateConnections();

  checkDocking();
}
示例#13
0
/* load the predefined channels */
void load_channels(void)
{
    char    path[_POSIX_PATH_MAX], *name, *slimit, *slevel, *topic, *ptr;
    char    realname[256];
    int     fd;
    int     limit, level, line = 0;
    CHANNEL *chan;
    int     version = 0;

    snprintf(path, sizeof(path), "%s/channels", global.varDir);

    if((fd = open(path, O_RDONLY))==-1)
    {
        if(errno != ENOENT)
            logerr("load_channels", path);
        return;
    }
    if(fake_fgets(Buf, sizeof(Buf), fd) == NULL)
    {
        close(fd);
        return;
    }
    if(!strncmp(":version 1", Buf, 10))
        version = 1;
    else
        lseek(fd, 0, SEEK_SET);

    while (fake_fgets(Buf, sizeof(Buf), fd))
    {
        line++;
        ptr = Buf;
        while (ISSPACE(*ptr))
            ptr++;
        if(*ptr == 0 || (version == 0 && *ptr == '#'))
            continue;       /* blank or comment line */
        name = next_arg(&ptr);
        slimit = next_arg(&ptr);
        slevel = next_arg(&ptr);
        topic = next_arg(&ptr);
        if(!name || !slimit || !slevel || !topic)
        {
            log_message_level(LOG_LEVEL_ERROR, "load_channels: %s:%d: too few parameters", path, line);
            continue;
        }
        /* force new channel name restrictions */
        if(option(ON_IRC_CHANNELS) && *name != '#' && *name != '&')
        {
            snprintf(realname, sizeof(realname), "#%s", name);
            name = realname;
        }
        if(invalid_channel(name))
        {
            log_message_level(LOG_LEVEL_ERROR, "load_channels: %s:%d: %s: invalid channel name", name);
            continue;
        }
        level = get_level(slevel);
        if(level == -1)
        {
            log_message_level(LOG_LEVEL_ERROR, "load_channels: %s:%d: %s: invalid level", path, line, slevel);
            continue;
        }
        limit = atoi(slimit);
        if(limit < 0 || limit > 65535)
        {
            log_message_level(LOG_LEVEL_ERROR, "load_channels: %s:%d: %d: invalid limit", path, line, limit);
            continue;
        }
        chan = hash_lookup(global.channelHash, name);
        if(chan)
        {
            log_message_level(LOG_LEVEL_ERROR, "load_channels: %s:%d: %s is already defined", path, line, name);
            continue;
        }
        chan = new_channel();
        if(chan)
        {
            chan->name = STRDUP(name);
            chan->topic = STRDUP(topic);
            chan->limit = limit;
            chan->level = level;
            chan->flags = ON_CHANNEL_REGISTERED;
            chan->timestamp = global.current_time;
        }
        if(hash_add(global.channelHash, chan->name, chan))
            free_channel(chan);
    }
    close(fd);
}
示例#14
0
文件: carbon_gui.cpp 项目: dyne/MuSE
/* Constructor for CARBON_GUI class. */
CARBON_GUI::CARBON_GUI(int argc, char **argv, Stream_mixer *mix) 
 : GUI(argc,argv,mix) 
{
	/* initialization stuff */
  	jmix = mix;
	memset(myLcd,0,sizeof(myLcd));
	memset(myPos,0,sizeof(myPos));
	vumeter=0;
	vuband=0;
	selectedChannel=NULL;
	memset(channel,0,sizeof(channel));
	playlistManager=new PlaylistManager();
	msgList=new Linklist();
	
	/* init mutex used when accessing the statusbox buffer ...
	 * this is needed because other threads can try to write status messages concurrently
	 */
	if(pthread_mutex_init(&_statusLock,NULL) == -1) {
		error("error initializing POSIX thread mutex creating a new CarbonChannel");
		QuitApplicationEventLoop();
	}
	
	// Create a Nib reference 
    err = CreateNibReference(CFSTR("main"), &nibRef);
	if(err != noErr) error("Can't get NIB reference to obtain gui controls!!");
    
	// Create the MainWindow using nib resource file
    err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window);
	if(err != noErr) {
		error("Can't create MainWindow!!");
		QuitApplicationEventLoop();
	}
	else {
		msg = new CarbonMessage(nibRef);
		/* make the main window also the frontmost one */
		BringToFront(window);
		init_controls();
		
		/* now create the menu to use for the menubar ... it's stored in nib */
		err=CreateMenuFromNib(nibRef,CFSTR("MenuBar"),&mainMenu);
		if(err!=noErr) {
			msg->error("Can't create main menu (%d)!!",err);
		}
		
		/* install vumeter controls */
		setupVumeters();
		/* and the status box */
		setupStatusWindow();
		
		bufferInspector = new BufferInspector(window,nibRef,jmix);
		
		/* now we have to group windows together so if all are visible they will also be layered together */
		err=CreateWindowGroup(kWindowGroupAttrLayerTogether,&mainGroup);
		err=SetWindowGroup(window,mainGroup);
		err=SetWindowGroup(vumeterWindow,mainGroup);
		err=SetWindowGroup(statusWindow,mainGroup);
		err=SetWindowGroup(bufferInspector->window,mainGroup);
		SetWindowGroupOwner(mainGroup,window);
		/* let's create a channel window for each active input channel */
		unsigned int i;
		bool cc=false;
		for (i=0;i<MAX_CHANNELS;i++) {
			strcpy(ch_lcd[i],"00:00:00");
			if(jmix->chan[i]) { 
					CarbonChannel *newChan = new CarbonChannel(jmix,this,nibRef,i);
					channel[i] = newChan;
				/*	
					if(i > 0) {
						RepositionWindow(channel[i]->window,channel[i-1]->window,kWindowCascadeOnParentWindow);
					}
					else {
						RepositionWindow(channel[i],window,kWindowCascadeOnParentWindow);
					}
				*/
					cc=true;
			}
			else {
				channel[i] = NULL;
			}
		}
		/* Ok, once MainWindow has been created and we have instantiated all acrive input channels,
		* we need an instance of CarbonStream to control the stream option window */
		streamHandler = new CarbonStream(jmix,window,nibRef);
		/* by default we want at leat one active channel */
		if(!cc) new_channel();
	
		aboutWindow = new AboutWindow(window,nibRef);
		
		// The window was created hidden so show it.
		ShowWindow( window );
	}
}
示例#15
0
文件: audio.c 项目: eriser/synth-3
static Song *read_song(FILE *file)
{
    Command command;
    Song *song = malloc(sizeof(Song));
    Chunk *chunk = NULL;
    song->ended = 0;
    song->nb_chunks = 0;
    song->chunks_f = song->chunks_l = NULL;
    if(g_debug)
        fprintf(stderr, "Starting parsing of song file...\n");
    while(read_line(file, &command) != -1)
    {
        switch(command.command)
        {
        case '\0':
            break;
        case 'p':
            {
                if(g_debug)
                    fprintf(stderr, "New chunk (%d channels)\n",
                            command.number.param);
                if(command.number.param < 1)
                    return NULL;
                if(chunk)
                    chunk->pos = 0;
                chunk = new_chunk(song, command.number.param);
            }
            break;
        case 'v':
            {
                /* select channel from chunk
                 * a new chunk may be allocated */
                Channel *channel = find_channel(song, &chunk);

                /* set the volume */
                channel->volume = command.number.param;
            }
            break;
        case 'i':
            {
                /* select channel from chunk
                 * a new chunk may be allocated */
                Channel *channel = find_channel(song, &chunk);

                /* set the instrument */
                channel->instrument = command.number.param;
            }
            break;
        case 'n':
            {
                size_t i;
                /* select channel from chunk
                 * a new chunk may be allocated */
                Channel *channel = find_channel(song, &chunk);

                /* fill it with notes! */
                channel->length = strlen(command.string.param);
                channel->notes = malloc(sizeof(float) * channel->length);
                for(i = 0; i < channel->length; i++)
                    channel->notes[i] = note2freq(command.string.param[i]);
                if(g_debug)
                    fprintf(stderr, "%u notes read into channel %u\n",
                        channel->length, chunk->pos);

                /* to next channel */
                chunk->pos++;
                if(chunk->pos < chunk->nb_channels)
                    chunk->channels[chunk->pos] = new_channel();
            }
            break;
        case 'l':
        case 'j':
            fprintf(stderr, "Warning: '%c' is currently unimplemented\n",
                command.command);
            break;
        }
    }
    if(chunk->pos != chunk->nb_channels)
    {
        fprintf(stderr, "Missing %d channels in chunk\n",
                chunk->nb_channels - chunk->pos);
        return NULL;
    }
    chunk->pos = 0;
    if(g_debug)
        fprintf(stderr, "Song file parsed\n");
    return song;
}
示例#16
0
ConnInterface::ConnInterface()
{
	channel = new_channel();
    //ROS_ASSERT_MSG(channel >= 0, "channel allocation failure");
}