/**
 * Return features as configured for the channel class given by the Channel::immutableProperties()
 * of \a proxy.
 *
 * \param proxy The Channel proxy to determine the features for.
 * \return A list of Feature objects.
 */
Features ChannelFactory::featuresFor(const DBusProxyPtr &proxy) const
{
    ChannelPtr chan = ChannelPtr::qObjectCast(proxy);
    Q_ASSERT(!chan.isNull());

    return featuresFor(ChannelClassSpec(chan->immutableProperties()));
}
void SimpleCallObserver::onChannelInvalidated(const ChannelPtr &channel,
        const QString &errorName, const QString &errorMessage)
{
    if (channel->channelType() == TP_QT_IFACE_CHANNEL_TYPE_CALL) {
        CallChannelPtr callChannel = CallChannelPtr::qObjectCast(channel);
        if (!callChannel) {
            warning() << "Channel received to observe is not a subclass of "
                "CallChannel. ChannelFactory set on this observer's account must "
                "construct CallChannel subclasses for channels of type Call. "
                "Ignoring channel";
            return;
        }

        emit callEnded(callChannel, errorName, errorMessage);
    } else if (channel->channelType() == TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
        StreamedMediaChannelPtr smChannel = StreamedMediaChannelPtr::qObjectCast(channel);
        if (!smChannel) {
            warning() << "Channel received to observe is not a subclass of "
                "StreamedMediaChannel. ChannelFactory set on this observer's account must "
                "construct StreamedMediaChannel subclasses for channels of type StreamedMedia. "
                "Ignoring channel";
            return;
        }

        emit streamedMediaCallEnded(smChannel, errorName, errorMessage);
    } else {
        warning() << "Channel received to observe is not of type Call or StreamedMedia, "
                "service confused. Ignoring channel";
    }
}
Beispiel #3
0
/**
 * Destroys a channel. This will send LCH messages to all channel participants if the channel exists.
 * @param string channel name
 * @returns Nothing.
 */
int LuaChannel::destroyChannel(lua_State* L) {
    luaL_checkany(L, 1);

    string name = luaL_checkstring(L, 1);
    lua_pop(L, 1);

    ChannelPtr chan = ServerState::getChannel(name);
    if (chan) {
        const ChannelType type = chan->getType();
        const char* channame = chan->getName().c_str();
        const chconlist_t particpants = chan->getParticipants();
        for (chconlist_t::const_iterator i = particpants.begin(); i != particpants.end(); ++i) {
            json_t* root = json_object();
            json_object_set_new_nocheck(root, "channel",
                    json_string_nocheck(channame)
                    );
            json_object_set_new_nocheck(root, "character",
                    json_string_nocheck((*i)->characterName.c_str())
                    );
            const char* leavestr = json_dumps(root, JSON_COMPACT);
            string msg = "LCH ";
            msg += leavestr;
            free((void*) leavestr);
            json_decref(root);
            MessagePtr outMessage(MessageBuffer::fromString(msg));
            (*i)->send(outMessage);
            chan->part((*i));
        }
        ServerState::removeChannel(name);
        if (type == CT_PUBLIC)
            ServerState::rebuildChannelOpList();
    }
    return 0;
}
Beispiel #4
0
static void logMsg(Log&& msg)
{
	ChannelPtr channelLogCopy = channelLog;
	if (!channelLogCopy) return;

	msg.file("mccom");

	channelLogCopy->send(msg);
}
Beispiel #5
0
sf::Error Datagram::sendTo (ChannelPtr channel) const {
	if (channel->error()) return channel->error();

	sf::ByteArrayPtr chunk = encode ();
	if (!chunk) return error::TooMuch;

	Error err = channel->write (chunk);
	return err;
}
Beispiel #6
0
/**
 * Fetches a channel object by name.
 * @param string Channel name.
 * @returns [bool] found, [LUD] channel object
 */
int LuaChannel::getChannel(lua_State* L) {
    luaL_checkany(L, 1);

    string channame = luaL_checkstring(L, 1);
    lua_pop(L, 1);
    ChannelPtr chan = ServerState::getChannel(channame);
    if (chan == 0) {
        lua_pushboolean(L, false);
        return 1;
    }
    lua_pushboolean(L, true);
    lua_pushlightuserdata(L, chan.get());
    return 2;
}
Beispiel #7
0
void ServerState::rebuildChannelOpList() {
    channelOpList.clear();
    const chanptrmap_t chans = getChannels();
    for (chanptrmap_t::const_iterator i = chans.begin(); i != chans.end(); ++i) {
        if (i->second->getType() == CT_PUBLIC) {
            ChannelPtr chan = i->second;
            const chmodmap_t mods = chan->getModRecords();
            for (chmodmap_t::const_iterator m = mods.begin(); m != mods.end(); ++m) {
                if (m->first != "") {
                    channelOpList.insert(m->first);
                }
            }
        }
    }
}
Beispiel #8
0
int LuaTesting::killChannel(lua_State* L) {
    luaL_checkany(L, 1);

    string chanName = luaL_checkstring(L, 1);
    lua_pop(L, 1);
    ChannelPtr chan = ServerState::getChannel(chanName);
    if (chan) {
        const chconlist_t particpants = chan->getParticipants();
        for (chconlist_t::const_iterator i = particpants.begin(); i != particpants.end(); ++i) {
            chan->part(*i);
        }
        ServerState::removeChannel(chanName);
    }

    return 0;
}
Beispiel #9
0
void pvaDriver::channelCreated (const Status& status,
        ChannelPtr const & channel)
{
    asynPrint(pasynUserSelf, ASYN_TRACE_FLOW,
            "%s::%s: %s created\n",
            driverName, "channelCreated", channel->getChannelName().c_str());
}
Beispiel #10
0
void test4GetStatus(ChannelPtr& c)
{
	const std::string jobHandle = "H:localhost.localdomain:4";
	GearmanTaskPtr task(new GearmanTask);
	task->request = GearmanMessage::createGetStatusMessage(jobHandle);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
Beispiel #11
0
ChannelFuturePtr ClientBootstrap::connect(const InetAddress& remote,
        const InetAddress& local) {
    if (!remote) {
        LOG_INFO << "the remote address is invalidated, then return a failed future.";
        return NullChannel::instance()->newFailedFuture(
                   ChannelException("Failed to initialize a pipeline."));
    }

    ChannelPtr ch = newChannel();

    if (!ch) {
        LOG_INFO << "failed to create a new channel, then return a failed future.";
        return NullChannel::instance()->newFailedFuture(
                   ChannelException("Failed to create a new channel."));
    }

    if (!initializer()) {
        LOG_INFO << "has not set channel pipeline initializer.";
        return NullChannel::instance()->newFailedFuture(
                   ChannelException("has not set channel pipeline initializer."));
    }

    ch->setInitializer(initializer());
    ch->open();

    ch->closeFuture()->addListener(boost::bind(
        &ClientBootstrap::closeChannelBeforeDestruct,
        this,
        _1,
        ch));

    // Set the options.
    ch->config().setOptions(options());

    insertChannel(ch->id(), ch);

    // Bind.
    if (localAddress()) {
        LOG_INFO << "bind the channel to local address" << local.toString();
        ChannelFuturePtr future = ch->bind(local);
        future->awaitUninterruptibly();
    }

//     ch->closeFuture()->addListener(
//         boost::bind(&ClientBootstrap::onChannelClosed,
//                     this,
//                     _1));

    // Connect.
    return ch->connect(remote);
}
Beispiel #12
0
void ServerState::saveChannels() {
    DLOG(INFO) << "Saving channels.";
    json_t* root = json_object();
    json_t* publicarray = json_array();
    json_t* privatearray = json_array();
    for (chanptrmap_t::const_iterator i = channelMap.begin(); i != channelMap.end(); ++i) {
        ChannelPtr chan = i->second;
        if (chan->getType() == CT_PUBLIC) {
            json_array_append_new(publicarray, chan->saveChannel());
        } else if (chan->getType() == CT_PUBPRIVATE) {
            json_array_append_new(privatearray, chan->saveChannel());
        }
    }
    json_object_set_new_nocheck(root, "public", publicarray);
    json_object_set_new_nocheck(root, "private", privatearray);
    const char* chanstr = json_dumps(root, JSON_INDENT(4));
    string contents = chanstr;
    free((void*) chanstr);
    json_decref(root);
    fsaveFile("./channels.json", contents);
}
Beispiel #13
0
void test4Echo(ChannelPtr& c)
{
	GearmanTaskPtr task(new GearmanTask);
	ChannelBufferPtr buffer = Unpooled::buffer(1024, 64);
	for (int i = 0; i < 20; ++i) {
		buffer->writeByte('0');
	}
	
	task->request = GearmanMessage::createEchoReqMessage(buffer);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
Beispiel #14
0
void test4OptionReq(ChannelPtr& c)
{
	const std::string option = "exception";
	GearmanTaskPtr task(new GearmanTask);
	ChannelBufferPtr payload = Unpooled::buffer(1024, 64);
	for (int i = 0; i < 10; ++i) {
		payload->writeByte('0');
	}
	task->request = GearmanMessage::createOptionReqMessage(option);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
Beispiel #15
0
void test4submitJobHighBG(ChannelPtr& c)
{
	const std::string functionName = "hello";
	const std::string uniqueId = "123456";
	GearmanTaskPtr task(new GearmanTask);
	ChannelBufferPtr payload = Unpooled::buffer(1024, 64);
	for (int i = 0; i < 10; ++i) {
		payload->writeByte('0');
	}
	task->request = GearmanMessage::createsubmitJobHighBGMessage(functionName,uniqueId,payload);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
Beispiel #16
0
void pvaDriver::channelStateChange (ChannelPtr const & channel,
        Channel::ConnectionState state)
{
    const char *functionName = "channelStateChange";

    lock();
    asynPrint(pasynUserSelf, ASYN_TRACE_FLOW,
            "%s::%s %s: %s\n",
            driverName, functionName, channel->getChannelName().c_str(),
            Channel::ConnectionStateNames[state]);
    setIntegerParam(PVAPvConnectionStatus, state == Channel::CONNECTED);
    callParamCallbacks();
    unlock();
}
Beispiel #17
0
/*const std::vector<const std::string&> params;
	params.push_back()*/
int main(int argc, char* argv[]) {
    // Print usage if no argument is specified.

    // Parse options.
    std::string host = "192.168.1.112";
    int port = 4730;
    int ioThreadCount = 1;

    // Configure the client.
    ClientBootstrap bootstrap(new AsioClientSocketChannelFactory(ioThreadCount));

    bootstrap.setPipelineFactory(new GearmanPipelineFactory);

    // Start the connection attempt.
    std::vector<Channel*> clientChannels;

    ChannelFuturePtr future = bootstrap.connect(host, port);
    future->awaitUninterruptibly();

	ChannelPtr c = future->channel();

	//test4Echo(c);
	test4submitJob(c);
	test4submitJobBG(c);
	//Sleep(5000);
 	//test4GetStatus(c);
	//test4submitJobBG(c);

    system("PAUSE");
    c->closeFuture()->awaitUninterruptibly();

    // Shut down thread pools to exit.
    bootstrap.shutdown();

    return 0;
}
Beispiel #18
0
int  EPoll::update(int operation, const ChannelPtr& channel)
{

	for(ChannelMap::iterator it=channelMap_.begin();it!=channelMap_.end();it++){
		std::cout<<"it :"<<it->first<<"\n";
	
	}	
  ChannelMap::iterator it = channelMap_.find(channel->get_fd());
  if (it == channelMap_.end()) 
  {
		std::cout<<"no find\n";
		return -2;
	}
  channelMap_[channel->get_fd()] = channel;
  struct epoll_event event;
  bzero(&event, sizeof event);
  event.events = channel->get_events();//要监听的事件,读,写等
  event.data.ptr =  static_cast<void*>( channel.get());//这样写返回时,直接获取channel,
  if (::epoll_ctl(epollfd_, operation,channel->get_fd(), &event) < 0)//EPOLL_CTL_ADD, EPOLL_CTL_MOD,EPOLL_CTL_DEL
  {
	
	std::cout<<epollfd_<<":"<<channel->get_fd()<<std::endl;
	std::cout<<"epoll_ctl error \n";
	std::cout<<strerror(errno)<<std::endl;
	exit(0);
    if (operation == EPOLL_CTL_DEL)
    {
    	;
    }
    else
    {
  	;
    }
    return 1;
  }
  return 0;
}
Beispiel #19
0
	void onActive(const ChannelPtr& channel_ptr) override {
		DEBUG << "............. onActive .............";
		char request[] = "Response ....\n";
		channel_ptr->getChain()->send(channel_ptr, request, strlen(request));
	}
Beispiel #20
0
/**
 * A simple HTTP client that prints out the content of the HTTP response to
 * {@link System#out} to test {@link HttpServer}.
 *
 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
 * @author Andy Taylor ([email protected])
 * @author <a href="http://gleamynode.net/">Trustin Lee</a>
 *
 * @version $Rev: 2226 $, $Date: 2010-03-31 11:26:51 +0900 (Wed, 31 Mar 2010) $
 */
int main(int argc, const char* argv[]) {
    if (argc != 2) {
        printf("Usage: SnoopClient <URL>");
        return -1;
    }

    URI uri(argv[1]);
    std::string scheme = uri.getScheme().empty() ? "http" : uri.getScheme();
    std::string host = uri.getHost().empty() ? "localhost" : uri.getHost();
    int port = uri.getPort();

    if (port == -1) {
        if (scheme == "http") {
            port = 80;
        }
        else if (scheme == "https") {
            port = 443;
        }
    }

    if ((scheme != "http") && (scheme != "https")) {
        printf("Only HTTP(S) is supported.");
        return -1;
    }

    bool ssl = scheme == "https";

    // Configure the client.
    ClientBootstrap bootstrap(
        ChannelFactoryPtr(new AsioClientSocketChannelFactory(1)));

    // Set up the event pipeline factory.
    bootstrap.setPipeline(getPipeline(ssl));

    // Start the connection attempt.
    ChannelFuturePtr future = bootstrap.connect(InetAddress(host, port));

    // Wait until the connection attempt succeeds or fails.
    ChannelPtr channel = future->awaitUninterruptibly()->channel();

    if (!future->isSuccess()) {
        bootstrap.shutdown();
        return -1;
    }

    // Prepare the HTTP request.
    HttpRequestPtr request =
        HttpRequestPtr(new HttpRequest(HttpVersion::HTTP_1_1,
                       HttpMethod::GET,
                       uri.toString()));

    request->setHeader(HttpHeaders::Names::HOST, host);
    request->setHeader(HttpHeaders::Names::CONNECTION, HttpHeaders::Values::CLOSE);
    request->setHeader(HttpHeaders::Names::ACCEPT_ENCODING, HttpHeaders::Values::GZIP);

    // Set some example cookies.
    //CookieEncoder httpCookieEncoder = new CookieEncoder(false);
    //httpCookieEncoder.addCookie("my-cookie", "foo");
    //httpCookieEncoder.addCookie("another-cookie", "bar");
    //request->setHeader(HttpHeaders::Names::COOKIE, httpCookieEncoder.encode());

    // Send the HTTP request.
    channel->write(request);

    // Wait for the server to close the connection.
    channel->closeFuture()->awaitUninterruptibly();

    // Shut down executor threads to exit.
    bootstrap.shutdown();

    return 0;
};
Beispiel #21
0
	void ChannelMgr::Attach( ChannelPtr& ptr )
	{
		channels_.push_back(ptr);
		ptr->Bind( boost::bind(&ChannelMgr::OnChannelStateChange, this, _1) );
	}
void oleaClient::channelCreated (const Status& status,
        ChannelPtr const & channel)
{
    cout << "Channel created " <<  channel->getChannelName().c_str() << endl;
}
Beispiel #23
0
	void close() override
	{
		channelLog.reset();

		BlockingChannel::close();
	}
Beispiel #24
0
	void onInactive(const ChannelPtr& channel_ptr) override {
		channel_ptr->getChain()->close(channel_ptr);
	}
Beispiel #25
0
void PeerAdmin::attach(ChannelPtr channel, GenericPtr attachement) {
	channel->registerTo(m_selector, SelectionKey::OP_READ, attachement);
}