Exemple #1
0
void Domain::checkTransports()
{
	// Now update topics with values from the transports and channels
	// Loop over all transports and for each topic, see if it needs parameters from the channel
	for (unsigned int i = 0; i < transports.size(); i++) {
		// Get channel
		Channel* channel = findChannel(transports[i]->channelID);
		if (channel == NULL) {
			throw ops::ConfigException(
				std::string("Non existing channelID: '") + transports[i]->channelID +
				std::string("' used in transport spcification."));
		} else {
			for (unsigned int j = 0; j < transports[i]->topics.size(); j++) {
				Topic* top = findTopic(transports[i]->topics[j]);
				if (top == NULL) {
					throw ops::ConfigException(
						std::string("Non existing topicID: '") + transports[i]->topics[j] +
						std::string("' used in transport spcification."));
				} else {
					channel->populateTopic(top);
				}
			}
		}
	}
}
void IOServiceLibEvent::send(const ChannelId& id,
		const std::list<mxcore::SharedPtr<mxcore::ByteBuffer> > messageList,
		int perMsgTimeout)
{
	ChannelContext* ctx = findChannel(id);

	MX_ASSERT(NULL != ctx);
	MX_ASSERT(ctx->isConnector());

	for (std::list<mxcore::SharedPtr<mxcore::ByteBuffer> >::const_iterator it =
			messageList.begin(); it != messageList.end(); it++)
	{
		MX_ASSERT((*it)->remaining() > 0);
	}

	ConnectorChannelContext* connectorCtx = (ConnectorChannelContext*) ctx;

	bool haveMessage = connectorCtx->haveMessageToWrite();

	connectorCtx->putWriteMessage(messageList, perMsgTimeout);

	if (!haveMessage)
	{
		connectorCtx->registWrite();
		connectorCtx->registWriteTimer(perMsgTimeout);
	}
}
Exemple #3
0
	BitmapTexture(Stream *stream, InstanceManager *manager)
	 : Texture2D(stream, manager) {
		m_filename = stream->readString();
		Log(EDebug, "Unserializing texture \"%s\"", m_filename.filename().string().c_str());
		m_filterType = (EMIPFilterType) stream->readUInt();
		m_wrapModeU = (ReconstructionFilter::EBoundaryCondition) stream->readUInt();
		m_wrapModeV = (ReconstructionFilter::EBoundaryCondition) stream->readUInt();
		m_gamma = stream->readFloat();
		m_maxAnisotropy = stream->readFloat();
		m_channel = stream->readString();

		size_t size = stream->readSize();
		ref<MemoryStream> mStream = new MemoryStream(size);
		stream->copyTo(mStream, size);
		mStream->seek(0);
		ref<Bitmap> bitmap = new Bitmap(Bitmap::EAuto, mStream);
		if (m_gamma != 0)
			bitmap->setGamma(m_gamma);

		/* Downsample using a 2-lobed Lanczos reconstruction filter */
		Properties rfilterProps("lanczos");
		rfilterProps.setInteger("lobes", 2);
		ref<ReconstructionFilter> rfilter = static_cast<ReconstructionFilter *> (
			PluginManager::getInstance()->createObject(
			MTS_CLASS(ReconstructionFilter), rfilterProps));
		rfilter->configure();

		Bitmap::EPixelFormat pixelFormat;
		if (!m_channel.empty()) {
			/* Create a texture from a certain channel of an image */
			pixelFormat = Bitmap::ELuminance;
			bitmap = bitmap->extractChannel(findChannel(bitmap, m_channel));
			if (m_channel == "a")
				bitmap->setGamma(1.0f);
		} else {
			switch (bitmap->getPixelFormat()) {
				case Bitmap::ELuminance:
				case Bitmap::ELuminanceAlpha:
					pixelFormat = Bitmap::ELuminance;
					break;
				case Bitmap::ERGB:
				case Bitmap::ERGBA:
					pixelFormat = Bitmap::ERGB;
					break;
				default:
					Log(EError, "The input image has an unsupported pixel format!");
					return;
			}
		}

		if (pixelFormat == Bitmap::ELuminance)
			m_mipmap1 = new MIPMap1(bitmap, pixelFormat, Bitmap::EFloat,
				rfilter, m_wrapModeU, m_wrapModeV, m_filterType, m_maxAnisotropy,
				fs::path(), 0);
		else
			m_mipmap3 = new MIPMap3(bitmap, pixelFormat, Bitmap::EFloat,
				rfilter, m_wrapModeU, m_wrapModeV, m_filterType, m_maxAnisotropy,
				fs::path(), 0);
	}
Exemple #4
0
void MorphController::addChannel(boost::shared_ptr<MorphChannel> ch)
{
	ChannelItem channel = findChannel(ch->getName());
	if(!channel)
		m_channels.push_back(ch);
	else
		ch.reset();
}
void SoundPool::setVolume(int channelID, float leftVolume, float rightVolume)
{
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setVolume(leftVolume, rightVolume);
    }
}
Exemple #6
0
void handle_TOPIC(char** params, int socket) {
  char *chanName = params[1];
  char *msg = params[10];
  char *colonflag = params[9];
  char msgbuf[512];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *userstruct;
  char *newtopic;
  int chandneflag = 0;
  
  //search for user by socket
  //printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  userstruct = (struct ClientData *)list_seek(&clientList, &socket);
  pthread_mutex_unlock(&listLock);
  user = userstruct->user;
  nick = userstruct->nick;

  //search for channel by name
  //printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);

  //if channel doesn't exist
  if(chan == NULL){
    chandneflag = 1;
  }

  //if user is not in channel
  //printf("checking if user is in channel\n");
  if(chandneflag || (isUserInChannel(socket, chan) == -1)){
    sprintf(msgbuf, ":%s 442 %s %s :You're not on that channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //check what the User wants to do, check the topic or change it?
  if(colonflag[0] == 'n'){
    if((chan->topic)[0] != '\0'){
      sprintf(msgbuf, ":%s 332 %s %s :%s\r\n", host, nick, chanName, chan->topic);
      sendMessage(msgbuf, socket);
    } else {
      sprintf(msgbuf, ":%s 331 %s %s :No topic is set\r\n", host, nick, chanName);
      sendMessage(msgbuf, socket);
    }
  } else {
    free(chan->topic);
    newtopic = strdup(msg);
    chan->topic = newtopic;
    sprintf(msgbuf, ":%s!%[email protected] TOPIC %s :%s\r\n", nick, user, chanName, chan->topic);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  }
  
  return;
}
void SoundPool::setRate(int channelID, float rate)
{
    ALOGV("setRate(%d, %f)", channelID, rate);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setRate(rate);
    }
}
void SoundPool::resume(int channelID)
{
    ALOGV("resume(%d)", channelID);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->resume();
    }
}
void SoundPool::setLoop(int channelID, int loop)
{
    ALOGV("setLoop(%d, %d)", channelID, loop);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setLoop(loop);
    }
}
void SoundPool::pause(int channelID)
{
    LOGV("pause(%d)", channelID);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->pause();
    }
}
void SoundPool::setPriority(int channelID, int priority)
{
    ALOGV("setPriority(%d, %d)", channelID, priority);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setPriority(priority);
    }
}
Exemple #12
0
//doesn't currently handle when user is already in channel
void handle_JOIN(char** params, int socket){
  char *chanName = params[1];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *beingAdded;
  char msgbuf[515];
  int ifnew = 0;
  
  //search for user by socket
  //printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  beingAdded = (struct ClientData *)list_seek(&clientList, &socket);
  printf("%s\n", beingAdded->nick);
  pthread_mutex_unlock(&listLock);
  user = beingAdded->user;
  nick = beingAdded->nick;
  
  //search for channel by name
  printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);

  //if it doesn't exist, create the channel
  if(chan == NULL){
    chan = createChannel(chanName, 0, 0, "", socket);
    pthread_mutex_lock(&chanListLock);
    list_append(&channelList, chan);
    pthread_mutex_unlock(&chanListLock);
    ifnew = 1;
  }
  
  //add user to that channel
  printf("adding user to channel\n");
  //start by checking if user is already joined
  if(isUserInChannel(socket, chan) != -1){
    //printf("user is already in channel\n");
    return;
  } else {
    pairUserWithChannel(beingAdded, chan, ifnew, socket);
  }
  //send out the message
  printf("sending message\n");
  sprintf(msgbuf, ":%s!%s@hostname JOIN %s\r\n", nick, user, chanName); //needs user address
  sendMessage(msgbuf, socket);
  messageAllUsers(msgbuf, chan, socket);
  if((chan->topic)[0] != '\0'){
    sprintf(msgbuf, ":%s 332 %s %s :%s\r\n", host, nick, chanName, chan->topic);
    sendMessage(msgbuf, socket);
  }
  sprintf(msgbuf, ":%s!%s@hostname 353 %s = %s :nicknames eventually go here\r\n", nick, user, nick, chanName);
  sendMessage(msgbuf, socket);
  sprintf(msgbuf, ":%s!%s@hostname 366 %s %s :End of NAMES list\r\n", nick, user, nick, chanName);
  sendMessage(msgbuf, socket);
  return;
}
Exemple #13
0
void handle_PART(char ** params, int socket) {
  char *chanName = params[1];
  char *msg = params[10];
  char msgbuf[512];
  channel *chan;
  char *user;
  char *nick;
  struct ClientData *userstruct;
  
  //printf("msg: %s\n", msg);

  //search for user by socket
  printf("searching for user\n");
  pthread_mutex_lock(&listLock);
  userstruct = (struct ClientData *)list_seek(&clientList, &socket);
  pthread_mutex_unlock(&listLock);
  user = userstruct->user;
  nick = userstruct->nick;
  
  //search for channel by name
  printf("searching for channel\n");
  chan = (channel *) findChannel(chanName);
  
  //if channel doesn't exist
  if(chan == NULL){
    sprintf(msgbuf, ":%s 403 %s %s :No such channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //if user is not in channel
  printf("checking if user is in channel\n");
  if(isUserInChannel(socket, chan) == -1){
    sprintf(msgbuf, ":%s 442 %s %s :You're not on that channel\r\n", host, nick, chanName);
    sendMessage(msgbuf, socket);
    return;
  }

  //check if they have a parting message
  if(msg[0] == '\0'){
    //msg = nick;
    sprintf(msgbuf, ":%s!%s@hostname PART %s\r\n", nick, user, chanName);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  } else {
    sprintf(msgbuf, ":%s!%s@hostname PART %s :%s\r\n", nick, user, chanName, msg);
    sendMessage(msgbuf, socket);
    messageAllUsers(msgbuf, chan, socket);
  }
  //do the deed
  printf("actually remvoing user\n");
  removeUser(socket, chan);
  
  return;
}
// Once channel details are known, complete the graph with details that depend upon the channel.
void LteRlcGraphDialog::completeGraph(bool may_be_empty)
{
    QCustomPlot *rp = ui->rlcPlot;

    // If no channel chosen already, try to use currently selected frame.
    findChannel(may_be_empty);

    // Set window title here.
    if (graph_.channelSet) {
        QString dlg_title = tr("LTE RLC Graph (UE=%1 chan=%2%3 %4 - %5)")
                                 .arg(graph_.ueid)
                                 .arg((graph_.channelType == CHANNEL_TYPE_SRB) ? "SRB" : "DRB")
                                 .arg(graph_.channelId)
                                 .arg((graph_.direction == DIRECTION_UPLINK) ? "UL" : "DL")
                                 .arg((graph_.rlcMode == RLC_UM_MODE) ? "UM" : "AM");
        setWindowTitle(dlg_title);
    }
    else {
        setWindowTitle(tr("LTE RLC Graph - no channel selected"));
    }

    // Set colours/styles for each of the traces on the graph.
    QCustomPlot *sp = ui->rlcPlot;
    base_graph_ = sp->addGraph(); // All: Selectable segments
    base_graph_->setPen(QPen(QBrush(Qt::black), 0.25));

    reseg_graph_ = sp->addGraph();
    reseg_graph_->setPen(QPen(QBrush(Qt::lightGray), 0.25));

    acks_graph_ = sp->addGraph();
    acks_graph_->setPen(QPen(QBrush(graph_color_ack), 1.0));

    nacks_graph_ = sp->addGraph();
    nacks_graph_->setPen(QPen(QBrush(graph_color_nack), 0.25));

    // Create tracer
    tracer_ = new QCPItemTracer(sp);
    sp->addItem(tracer_);
    tracer_->setVisible(false);
    toggleTracerStyle(true);

    // Change label on save/export button.
    QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save);
    save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS));

    connect(rp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphClicked(QMouseEvent*)));
    connect(rp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*)));
    connect(rp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*)));
    disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    this->setResult(QDialog::Accepted);

    // Extract the data that the graph can use.
    fillGraph();
}
Exemple #15
0
void handle_NOTICE(char** params, int socket)
{
  char msgbuf[512];
  int destsocket;
  channel *chan;
  struct ClientData *srcUser;
  
  //get the destination and message from the command
  char *dest = params[1];
  char *msg = params[10];

  srcUser = (struct ClientData *)list_seek(&clientList, &socket);
  
  if(dest[0] == '#'){//channel

    chan = (channel *) findChannel(dest);
    if(chan == NULL){
      //sprintf(msgbuf, ":%s 401 %s %s :No such nick/channel\r\n", host, srcUser->nick, dest);
      //sendMessage(msgbuf, socket);
      return;
    }

    //check if the user is in the channel
    if(isUserInChannel(socket, chan) == -1){
      //sprintf(msgbuf, ":%s 404 %s %s :Cannot send to channel\r\n", host, srcUser->user, dest);
      //sendMessage(msgbuf, socket);
      return;
    }

    sprintf(msgbuf, ":%s!%s@hostname NOTICE %s :%s\r\n", srcUser->nick, srcUser->user, dest, msg);
    printf("message was: %s\n", msgbuf);
    messageAllUsers(msgbuf, chan, socket);

  } else {    //user
  
    //find the information of the destination
    struct ClientData * destUser = findUser(dest, &clientList);
    if(destUser == NULL){
      return;
    }
    destsocket = destUser->ourSocket;
    
    //find the nick of the source
    struct ClientData *srcUser = (struct ClientData *)list_seek(&clientList, &socket);
    
    //send the message
    sprintf(msgbuf, ":%s!%s@sentuser NOTICE %s :%s\r\n", srcUser->nick, srcUser->user, dest, msg);
    sendMessage(msgbuf, destsocket);
    return;

  }
}
void* IOServiceLibEvent::setAttachment(const ChannelId& channelId,
		void* attachment)
{
	ChannelContext* ctx = findChannel(channelId);

	MX_ASSERT(NULL != ctx);

	void* oldAttachment = ctx->getAttachment();

	ctx->setAttachment(attachment);

	return oldAttachment;
}
void SoundPool::stop(int channelID)
{
    ALOGV("stop(%d)", channelID);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->stop();
    } else {
        channel = findNextChannel(channelID);
        if (channel)
            channel->clearNextEvent();
    }
}
Exemple #18
0
//****************************************************************************
//
//****************************************************************************
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
void MsgMgr::removeCommNodeFromChannel(const char * _channelName, CommNode * _commNode)
{
    {
        NWAutoCritSec critSec(mCritSecAddRemoveCommNodes);

        ChannelId channelId = findChannel(_channelName, false);

        if(channelId != InvalidChannelId)
        {
            removeCommNodeFromChannel(channelId, _commNode);
        }
    }
}
Exemple #19
0
void handle_LIST(char **params, int socket){
  printf("at the top of handle_list, plenty of time to fill the printf buffer and send a message\n");
  char msgbuf[512];
  char* nick;
  char *chanName = params[1];
  channel* chan;
  
  struct ClientData * ourCli = (struct ClientData *)list_seek(&clientList, &socket);
  nick = ourCli->nick;

  //printf("Ahfksadkfhkwelkheiowhrihfksadnfnkahseihiofhiohdsfaskdnfkneifhihdisjfkalsdklfjksdjfij\n");
  //printf("chan null is :%d\n", chanName == NULL);
  //printf("shfksadkfhkwelkheiowhrihfksadnfnkahseihiofhiohdsfaskdnfkneifhihdisjfkalsdklfjksdjfij\n");
  if(chanName != NULL){
    chan = (channel *) findChannel(chanName);

    //if channel doesn't exist
    if(chan == NULL){
      return;
    }

    sprintf(msgbuf, ":%s 322 %s %s %d :%s\r\n", host, nick, chanName, chan->nusers, chan->topic); //add stuff
    sendMessage(msgbuf, socket);
    sprintf(msgbuf, ":%s 323 %s :End of LIST\r\n", host, nick);
    sendMessage(msgbuf, socket);
    
  } else {
  
    pthread_mutex_lock(&chanListLock);
    if(list_iterator_start(&channelList) == 0){
      printf("could not iterate list\n");
      return;
    }
    printf("starting channel iterator\n");
    while(list_iterator_hasnext(&channelList)){
      chan = (channel *) list_iterator_next(&channelList);
      printf("sending channel info\n");
      sprintf(msgbuf, ":%s 322 %s %s %d :%s\r\n", host, nick, chan->name, chan->nusers, chan->topic); //add stuff
      sendMessage(msgbuf, socket);  
    }

    list_iterator_stop(&channelList);
    pthread_mutex_unlock(&chanListLock);

    sprintf(msgbuf, ":%s 323 %s :End of LIST\r\n", host, nick);
    sendMessage(msgbuf, socket);
  }
  
  
  return;
}
void IOServiceLibEvent::send(const ChannelId& id,
		mxcore::SharedPtr<mxcore::ByteBuffer> message, int timeout)
{
	ChannelContext* ctx = findChannel(id);

	MX_ASSERT(NULL != ctx);
	MX_ASSERT(ctx->isConnector());
	MX_ASSERT(message->remaining() > 0);

	ConnectorChannelContext* connectorCtx = (ConnectorChannelContext*) ctx;

	bool haveMessage = connectorCtx->haveMessageToWrite();

	connectorCtx->putWriteMessage(ChannelMessage(message, timeout, false));

	if (!haveMessage)
	{
		connectorCtx->registWrite();
		connectorCtx->registWriteTimer(timeout);
	}
}
Exemple #21
0
void IRCSession::processCommandJoin(shared_ptr<IRCCommandJoin> command)
{
	OS_ASSERT(command != nullptr);

	shared_ptr<IRCRoom> room;

	{
		OS_LOCK(m_dataCS);

		const std::string &channelName = command->getChannel();

		shared_ptr<IRCChannel> channel;

		Rooms::const_iterator i = m_rooms.find(channelName);
		
		if(isLocalUser(command->getNick()))
			channel = ensureChannel(channelName);
		else
			channel = findChannel(channelName);
		
		if(channel != nullptr)
		{
			room = ensureRoom(channel, false);
			OS_ASSERT(room != nullptr);

			std::string nickname;
			IRCUserType userType = ircUserTypeNormal;
			if(IRCParser::parseNickname(command->getNick(), nickname, userType))
			{
				shared_ptr<IRCRoom::UserDetails> userDetails = room->ensureUser(ensureUser(nickname));				
				OS_ASSERT(userDetails != nullptr);
				if(userDetails != nullptr)
					userDetails->setType(userType);
			}
		}		
	}

	if(room != nullptr)
		updateRoom(room, false);	
}
Exemple #22
0
//****************************************************************************
//
//****************************************************************************
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
ChannelId MsgMgr::addCommNodeSenderToChannel(const char * _channelName, CommNode * _commNode)
{
    ASSERT(_commNode);

    ChannelId channelId = InvalidChannelId; 
    
    {
        NWAutoCritSec critSec(mCritSecAddRemoveCommNodes);
        
        channelId = findChannel(_channelName);

        if(channelId == InvalidChannelId)
        {
            MsgChannel * channel = createChannel(_channelName);
            channelId = channel->getChannelId();
        }

        addCommNodeSenderToChannel(channelId, _commNode);
    }

    return channelId;
}
Exemple #23
0
void Logger::setLogLevel(const std::string &channel, LogLevel level) {
	uint idx = findChannel(channel);
	levels_[idx] = level;
}
Exemple #24
0
void IRCServer::lineReceivedEvent(char *line, int size) {
	printf("[%d] { %s }\n", size, line);

	// Process this line...!
	UserRef user;

	// Is there a prefix?
	if (line[0] == ':') {
		char nickBuf[512], identBuf[512], hostBuf[512];
		int nickPos = 0, identPos = 0, hostPos = 0;
		int phase = 0;

		++line; // skip colon

		while ((*line != ' ') && (*line != 0)) {
			if (phase == 0) {
				// Nick
				if (*line == '!')
					phase = 1;
				else if (*line == '@')
					phase = 2;
				else {
					if (nickPos < 511)
						nickBuf[nickPos++] = *line;
				}
			} else if (phase == 1) {
				// Ident
				if (*line == '@')
					phase = 2;
				else {
					if (identPos < 511)
						identBuf[identPos++] = *line;
				}
			} else if (phase == 2) {
				if (hostPos < 511)
					hostBuf[hostPos++] = *line;
			}

			++line;
		}

		if (*line == 0) {
			// Invalid line. Can't parse this.
			return;
		}

		++line; // skip the space

		nickBuf[nickPos] = 0;
		identBuf[identPos] = 0;
		hostBuf[hostPos] = 0;

		user.nick = nickBuf;
		user.ident = identBuf;
		user.hostmask = hostBuf;

		user.isValid = true;
		user.isSelf = (strcmp(nickBuf, currentNick) == 0);
	}

	// Get the command
	char cmdBuf[512];
	int cmdPos = 0;

	while ((*line != ' ') && (*line != 0)) {
		if (cmdPos < 511)
			cmdBuf[cmdPos++] = *line;
		++line;
	}
	cmdBuf[cmdPos] = 0;

	if (*line == 0) {
		// Invalid line.
		return;
	}

	++line; // skip the space

	// Skip the : if there is one
	if (*line == ':')
		++line;

	// Get the first param, or "target" in many cases
	char *allParams = line;
	char *paramsAfterFirst = line;

	char targetBuf[512];
	int targetPos = 0;

	while ((*paramsAfterFirst != ' ') && (*paramsAfterFirst != 0)) {
		if (targetPos < 511)
			targetBuf[targetPos++] = *paramsAfterFirst;
		++paramsAfterFirst;
	}

	targetBuf[targetPos] = 0;

	// If we didn't reach the end of the line, skip the space
	if (*paramsAfterFirst == ' ')
		++paramsAfterFirst;

	// And if the params begin with :, skip it
	if (*paramsAfterFirst == ':')
		++paramsAfterFirst;

	// Now figure out what to do with this...!

	if (strcmp(cmdBuf, "PING") == 0) {
		char out[512];
		snprintf(out, 512, "PONG :%s", allParams);
		sendLine(out);
		return;

	} else if (strcmp(cmdBuf, "JOIN") == 0) {
		Channel *c = findChannel(targetBuf, true);
		if (c) {
			c->handleJoin(user);
			return;
		}

	} else if (strcmp(cmdBuf, "PART") == 0) {
		Channel *c = findChannel(targetBuf, false);
		if (c) {
			c->handlePart(user, paramsAfterFirst);
			return;
		}

	} else if (strcmp(cmdBuf, "QUIT") == 0) {
		for (auto &i : channels)
			i.second->handleQuit(user, allParams);

		if (Query *q = findQuery(user.nick.c_str(), false))
			q->handleQuit(allParams);
		return;

	} else if (strcmp(cmdBuf, "KICK") == 0) {
		char *space = strchr(paramsAfterFirst, ' ');
		const char *kickMsg = "";

		if (space) {
			*space = 0;
			kickMsg = space + 1;

			if (*kickMsg == ':')
				++kickMsg;
		}

		Channel *c = findChannel(targetBuf, false);
		if (c) {
			c->handleKick(user, paramsAfterFirst, kickMsg);
			return;
		}

	} else if (strcmp(cmdBuf, "NICK") == 0) {
		if (user.isSelf) {
			strncpy(currentNick, allParams, sizeof(currentNick));
			currentNick[sizeof(currentNick) - 1] = 0;

			ircStringToLowercase(currentNick, currentNickLower, sizeof(currentNickLower));

			char buf[1024];
			snprintf(buf, 1024, "You are now known as %s", currentNick);
			status.pushMessage(buf);

			for (auto &it : queries)
				it.second->showNickChange(user, allParams);
		}

		if (Query *q = findQuery(user.nick.c_str(), false)) {
			if (!user.isSelf)
				q->showNickChange(user, allParams);

			// Should we *rename* the query window, or not?
			Query *check = findQuery(allParams, false);
			if (check) {
				// If we already have one with the destination
				// nick, we shouldn't replace it..
				// ...but we should still show a notification there.
				// Unless check and q are the same, which can happen
				// if a user changes their nick's case. 
				if ((!user.isSelf) && (check != q))
					check->showNickChange(user, allParams);

				// And if the name's case changed, we need to update
				// the title to match!
				if (check->partner != allParams)
					check->renamePartner(allParams);

			} else {
				// We didn't have one, so it's safe to move!
				char lowerName[512];

				// First, remove the old entry..
				ircStringToLowercase(user.nick.c_str(), lowerName, sizeof(lowerName));

				auto iter = queries.find(lowerName);
				queries.erase(iter);

				// ...and then add a new one
				ircStringToLowercase(allParams, lowerName, sizeof(lowerName));
				queries[lowerName] = q;

				q->renamePartner(allParams);
			}
		}

		for (auto &i : channels)
			i.second->handleNick(user, allParams);

		return;

	} else if (strcmp(cmdBuf, "MODE") == 0) {
		Channel *c = findChannel(targetBuf, false);
		if (c) {
			c->handleMode(user, paramsAfterFirst);
			return;
		}

	} else if (strcmp(cmdBuf, "TOPIC") == 0) {
		Channel *c = findChannel(targetBuf, false);
		if (c) {
			c->handleTopic(user, paramsAfterFirst);
			return;
		}

	} else if (strcmp(cmdBuf, "PRIVMSG") == 0) {

		int endPos = strlen(paramsAfterFirst) - 1;
		bool requireQueryWindow = true;
		const char *ctcpType = NULL, *ctcpParams = NULL;

		if ((endPos > 0) &&
			(paramsAfterFirst[0] == 1) &&
			(paramsAfterFirst[endPos] == 1))
		{
			// Try to parse a CTCP
			// Cut off the 01 char at the end
			paramsAfterFirst[endPos] = 0;

			// Split the string into type + params
			char *space = strchr(paramsAfterFirst, ' ');

			ctcpType = &paramsAfterFirst[1];

			if (space) {
				*space = 0;
				ctcpParams = space + 1;
			} else {
				ctcpParams = "";
			}

			if (strcmp(ctcpType, "ACTION") != 0)
				requireQueryWindow = false;

			// This needs to be extracted into a separate
			// method at some point
			if (strcmp(ctcpType, "VERSION") == 0) {
				char reply[1000];
				snprintf(reply, sizeof(reply),
					"NOTICE %s :\x01VERSION " VULPIRC_VERSION_STRING "\x01",
					user.nick.c_str());
				sendLine(reply);

			} else if (strcmp(ctcpType, "PING") == 0) {
				char reply[1000];
				snprintf(reply, sizeof(reply),
					"NOTICE %s :\x01PING %s\x01",
					user.nick.c_str(),
					ctcpParams);
				sendLine(reply);

			} else if (strcmp(ctcpType, "TIME") == 0) {
				char reply[1000], formatTime[200];
				time_t now = time(NULL);
				tm *nowtm = localtime(&now);

				strftime(formatTime, sizeof(formatTime),
					"%c", nowtm);

				snprintf(reply, sizeof(reply),
					"NOTICE %s :\x01TIME :%s\x01",
					user.nick.c_str(),
					formatTime);
				sendLine(reply);
			}
		}



		char targetBufLower[512];
		ircStringToLowercase(targetBuf, targetBufLower, 512);

		if (strcmp(targetBufLower, currentNickLower) == 0) {
			Query *q = findQuery(user.nick.c_str(), requireQueryWindow);
			if (q) {
				if (ctcpType)
					q->handleCtcp(user, ctcpType, ctcpParams);
				else
					q->handlePrivmsg(user, paramsAfterFirst);
				return;
			} else if (ctcpType) {
				// This CTCP didn't require a query window to be
				// open, and we don't already have one, so
				// dump a notification into the status window.
				char buf[1000];
				snprintf(buf, sizeof(buf),
					"CTCP from %s : %s %s",
					user.nick.c_str(),
					ctcpType,
					ctcpParams);
				status.pushMessage(buf);
				return;
			}
		} else {
			if (isValidChannelName(targetBuf)) {
				Channel *c = findChannel(targetBuf, true);
				if (c) {
					if (ctcpType)
						c->handleCtcp(user, ctcpType, ctcpParams);
					else
						c->handlePrivmsg(user, paramsAfterFirst);
					return;
				}
			} else {
				Query *q = findQuery(targetBuf, true);
				if (q) {
					if (ctcpType)
						q->handleCtcp(user, ctcpType, ctcpParams);
					else
						q->handlePrivmsg(user, paramsAfterFirst);
					return;
				}
			}
		}

	} else if (strcmp(cmdBuf, "001") == 0) {
		status.pushMessage("[debug: currentNick change detected]");

		strncpy(currentNick, targetBuf, sizeof(currentNick));
		currentNick[sizeof(currentNick) - 1] = 0;

		ircStringToLowercase(currentNick, currentNickLower, sizeof(currentNickLower));
	}

	int n = atoi(cmdBuf);
	if ((n > 0) && (n <= 999) && (strlen(cmdBuf) == 3)) {
		if (dispatchNumeric(n, paramsAfterFirst))
			return;
	}

	char tmpstr[2048];
	if (user.isValid)
		snprintf(tmpstr, sizeof(tmpstr),
			"[[Unhandled \"%s\" from %s!%s@%s]]",
			cmdBuf, user.nick.c_str(), user.ident.c_str(), user.hostmask.c_str());
	else
		snprintf(tmpstr, sizeof(tmpstr),
			"[[Unhandled \"%s\"]]",
			cmdBuf);

	status.pushMessage(tmpstr);
	status.pushMessage(line);
}
Exemple #25
0
Logger::Logger(const std::string &channel) : index_(findChannel(channel)) {}
Exemple #26
0
void Config::activateCanvas( Canvas* canvas )
{
    LBASSERT( canvas->isStopped( ));
    LBASSERT( lunchbox::find( getCanvases(), canvas ) != getCanvases().end( ));

    const Layouts& layouts = canvas->getLayouts();
    const Segments& segments = canvas->getSegments();

    for( Layouts::const_iterator i = layouts.begin();
         i != layouts.end(); ++i )
    {
        const Layout* layout = *i;
        if( !layout )
            continue;

        const Views& views = layout->getViews();
        for( Views::const_iterator j = views.begin();
             j != views.end(); ++j )
        {
            View* view = *j;

            for( Segments::const_iterator k = segments.begin();
                 k != segments.end(); ++k )
            {
                Segment* segment = *k;
                Viewport viewport = segment->getViewport();
                viewport.intersect( view->getViewport( ));

                if( !viewport.hasArea( ))
                {
                    LBLOG( LOG_VIEW )
                        << "View " << view->getName() << view->getViewport()
                        << " doesn't intersect " << segment->getName()
                        << segment->getViewport() << std::endl;

                    continue;
                }

                Channel* segmentChannel = segment->getChannel();
                if( !segmentChannel )
                {
                    LBWARN << "Segment " << segment->getName()
                           << " has no output channel" << std::endl;
                    continue;
                }

                if ( findChannel( segment, view ))
                    continue;

                // create and add new channel
                Channel* channel = new Channel( *segmentChannel );
                channel->init(); // not in ctor, virtual method
                channel->setOutput( view, segment );

                //----- compute channel viewport:
                // segment/view intersection in canvas space...
                Viewport contribution = viewport;
                // ... in segment space...
                contribution.transform( segment->getViewport( ));

                // segment output area
                if( segmentChannel->hasFixedViewport( ))
                {
                    Viewport subViewport = segmentChannel->getViewport();
                    LBASSERT( subViewport.isValid( ));
                    if( !subViewport.isValid( ))
                        subViewport = eq::fabric::Viewport::FULL;

                    // ...our part of it
                    subViewport.apply( contribution );
                    channel->setViewport( subViewport );
                    LBLOG( LOG_VIEW )
                        << "View @" << (void*)view << ' ' << view->getViewport()
                        << " intersects " << segment->getName()
                        << segment->getViewport() << " at " << subViewport
                        << " using channel @" << (void*)channel << std::endl;
                }
                else
                {
                    PixelViewport pvp = segmentChannel->getPixelViewport();
                    LBASSERT( pvp.isValid( ));
                    pvp.apply( contribution );
                    channel->setPixelViewport( pvp );
                    LBLOG( LOG_VIEW )
                        << "View @" << (void*)view << ' ' << view->getViewport()
                        << " intersects " << segment->getName()
                        << segment->getViewport() << " at " << pvp
                        << " using channel @" << (void*)channel << std::endl;
                }

                if( channel->getWindow()->isAttached( ))
                    // parent is already registered - register channel as well
                    getServer()->registerObject( channel );
            }
        }
    }
}
Exemple #27
0
bool ReadCell::buildChannels(
	Id compt,
	vector< string >& argv,
	double diameter,
	double length )
{
	bool isArgOK;
	int argStart;
	vector< Id > goodChannels;
	
	if ( doubleEndpointFlag_ ) {
		isArgOK = ( argv.size() % 2 ) == 1;
		argStart = 9;
	} else {
		isArgOK = ( argv.size() % 2 ) == 0;
		argStart = 6;
	}
	
	if ( !isArgOK ) {
		cerr << "Error: ReadCell: Bad number of arguments in channel list\n";
		cerr << "File: " << fileName_ << " Line: " << lineNum_ << endl;
		return 0;
	}
	
	for ( unsigned int j = argStart; j < argv.size(); j++ ) {
		// Here we explicitly set compt fields by scaling from the 
		// specific value applied here.
		string chan = argv[ j ];
		
		double value = atof( argv[ ++j ].c_str() );
		if ( chan == "RA" ) {
			double temp;
			if ( length == 0.0 ) // Spherical flag. Assume length = dia.
				temp = 8.0 * value / ( diameter * M_PI );
			else
				temp = 4.0 * value * length / ( diameter * diameter * M_PI );
			Field< double >::set( compt, "Ra", temp );
		} else if ( chan == "RM" ) {
			Field< double >::set( compt, "Rm", value * calcSurf( length, diameter ) );
		} else if ( chan == "CM" ) {
			Field< double >::set( compt, "Cm", value * calcSurf( length, diameter ) );
		} else if ( chan == "Rm" ) {
			Field< double >::set( compt, "Rm", value );
		} else if ( chan == "Ra" ) {
			Field< double >::set( compt, "Ra", value );
		} else if ( chan == "Cm" ) {
			Field< double >::set( compt, "Cm", value );
		} else if ( chan == "kinModel" ) {
			// Need 3 args here: 
			// lambda, name of proto, method
			// We already have lambda from value. Note it is in microns
			if ( j + 2 < argv.size() ) {
				string protoName = argv[ ++j ];
				string method = argv[ ++j ];
				//~ addKinModel( compt, value * 1.0e-6, protoName, method );
			} else {
				cerr << "Error: ReadCell: kinModel needs 3 args\n";
				cerr << "File: " << fileName_ << " Line: " << lineNum_ << endl;
				break;
			}
		} else if ( chan == "m2c" ) {
			// Need 5 args here: 
			// scale factor, mol, moloffset, chan, chanoffset
			// We already have scale factor from value.
			if ( j + 4 < argv.size() ) {
				//~ addM2C( compt, value, argv.begin() + j + 1 ); 
				j += 4;
			} else {
				cerr << "Error: ReadCell: m2c adaptor needs 5 args\n";
				cerr << "File: " << fileName_ << " Line: " << lineNum_ << endl;
				break;
			}
		} else if ( chan == "c2m" ) {
			// Need another 5 args here: 
			// scale factor, chan, chanoffset, mol, moloffset
			if ( j + 4 < argv.size() ) {
				//~ addC2M( compt, value, argv.begin() + j + 1 ); 
				j += 4;
			} else {
				cerr << "Error: ReadCell: c2m adaptor needs 5 args\n";
				cerr << "File: " << fileName_ << " Line: " << lineNum_ << endl;
				break;
			}
		} else {
			Id chanId = findChannel( chan );
			if ( chanId == Id() ) {
				cerr << "Error: ReadCell: Channel '" << chan <<
						"' not found\n";
				cerr << "File: " << fileName_ << " Line: " << lineNum_ << endl;
				continue;
			}
			
			Id copy = addChannel( compt, chanId, value, diameter, length );
			if ( copy != Id() ) {
				goodChannels.push_back( copy );
			} else {
				cerr << "Error: ReadCell: Could not add " << chan
                                     << " in " << compt.element()->getName() << ".";
				cerr << "File: " << fileName_ << " Line: " << lineNum_ << endl;
			}
		}
	}
	
	for ( unsigned int i = 0; i < goodChannels.size(); i++ )
		addChannelMessage( goodChannels[ i ] );
	
	return 1;
}
Exemple #28
0
void MorphController::pushTargets(const MorphTargetList& targets, const std::string& channel) 
{
	ChannelItem ch = findChannel(channel);
	if(ch)
		ch->pushTargets(targets);
} 
Exemple #29
0
void MorphController::pushTarget(MorphTarget* pTrg, const std::string& channel) 
{
	ChannelItem ch = findChannel(channel);
	if(ch)
		ch->pushTarget(pTrg);
}
Exemple #30
0
void MorphController::clearChannel(const std::string& channel) 
{
	ChannelItem ch = findChannel(channel);
	if(ch)
		ch->clear();
}