Exemplo n.º 1
0
Server::Server(int snum, QObject *p) : QThread(p) {
	bValid = true;
	iServerNum = snum;
#ifdef USE_BONJOUR
	bsRegistration = NULL;
#endif

#ifdef Q_OS_UNIX
	aiNotify[0] = aiNotify[1] = -1;
#else
	hNotify = NULL;
#endif
	qtTimeout = new QTimer(this);

	iCodecAlpha = iCodecBeta = 0;
	bPreferAlpha = false;

	qnamNetwork = NULL;

	readParams();
	initialize();

	foreach(const QHostAddress &qha, qlBind) {
		SslServer *ss = new SslServer(this);

		connect(ss, SIGNAL(newConnection()), this, SLOT(newClient()), Qt::QueuedConnection);

		if (! ss->listen(qha, usPort)) {
			log(QString("Server: TCP Listen on %1 failed: %2").arg(addressToString(qha,usPort), ss->errorString()));
			bValid = false;
		} else {
			log(QString("Server listening on %1").arg(addressToString(qha,usPort)));
		}
		qlServer << ss;
	}
Exemplo n.º 2
0
void SearchBoxOverlay::init() {
  QPainterOverlay::init();

  // First, just find out how big the search box is
  search_box_font_ = QFont("Lucida Grande");
  search_box_font_.setBold(true);
  search_box_font_.setPointSize(30);

  updateDrawnRegion();

  // Create the search box material
  QPainterOverlay::initMaterial(ceil(static_cast<float>(kSearchBoxPadding +
                                        search_box_highlight_around_text_rect_.width())),
                ceil(static_cast<float>(kSearchBoxPadding +
                                        search_box_highlight_around_text_rect_.height())));
  Ogre::String address = addressToString(this);
  panel_ = static_cast<Ogre::PanelOverlayElement*> (Ogre::OverlayManager::getSingleton().createOverlayElement("Panel",
                                                                                                              "SearchBoxOverlayPanel" +  // NOLINT
                                                                                                              address));  // NOLINT
  panel_->setMetricsMode(Ogre::GMM_PIXELS);
  panel_->setPosition(0, 0);
  panel_->setDimensions(width(), height());
  panel_->setMaterialName(utf8(material_->name()));

  QPainterOverlay::initOverlay("SearchOverlay" + address);
  overlay_->add2D(panel_);
  overlay_->hide();
}
Exemplo n.º 3
0
void QPainterMaterial::initWithSize(size_t width, size_t height, int num_mip_maps, bool use_texture_filtering) {
  width_of_drawn_region_ = width;
  height_of_drawn_region_ = height;
  num_mip_maps_ = num_mip_maps;

  width = Math::nearestPowerOf2(width);
  height = Math::nearestPowerOf2(height);

  texture_ = Ogre::TextureManager::getSingleton().createManual(addressToString(this),
                                                               Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                               Ogre::TEX_TYPE_2D,
                                                               width,
                                                               height,
                                                               num_mip_maps_,  // number of mipmaps
                                                               Ogre::PF_A8R8G8B8,
                                                               Ogre::TU_DYNAMIC);

  material_ = Ogre::MaterialManager::getSingleton().create(addressToString(this),
                                                           Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

  Ogre::Pass *texture_pass = material_->getTechnique(0)->getPass(0);

  texture_pass->createTextureUnitState(addressToString(this));

  texture_pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
  if (use_texture_filtering) {
    texture_pass->getTextureUnitState(0)->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
  } else {
    texture_pass->getTextureUnitState(0)->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);
  }
  texture_pass->setDepthCheckEnabled(false);

  image_buffer_ = new uchar[4*width*height];
  qimage_ = new QImage(image_buffer_, width, height, 4*width,
                       QImage::Format_ARGB32);

  qpainter_ = new QPainter();

  pixelbox_ = new Ogre::PixelBox(width, height, 1, Ogre::PF_A8R8G8B8, image_buffer_);
}
Exemplo n.º 4
0
/**
 * Presents the result to the caller of this program and print an appropriate
 * error message if necessary.
 * @param result
 *  The result to present.
 * @param err
 *  If the result is invalid, this is the argument that caused the failure.
 * @param includeNetmask
 *  If TRUE, the netmask is included in the output, otherwise it is left out.
 * @return
 *  The exit code of the application.
 */
static int
makeResult(struct Address const *result, char const *err, BOOL includeNetmask)
{
    if (result->type < 0) {
        switch (result->type) {
        case ERR_INVALID_ADDRESS :
            fprintf(stderr, "invalid address '%s'\n", err);
            break;
        case ERR_INVALID_NETBITMASK :
            /* ugly hack in order to access the netbitmask */
            fprintf(stderr, "invalid CIDR netmask '%s'\n", err + strlen(err) + 1);
            break;
        case ERR_INVALID_NETMASK :
            fprintf(stderr, "invalid netmask '%s'\n", err);
            break;
        case ERR_COMBINATION_FAILED :
            fprintf(stderr, "address combination failed due to overlapping\n");
            break;
        default :
            fprintf(stderr, "unknown error %d in '%s'\n", result->type, err);
            break;
        }
        return -result->type + 1;
    }
    else {
        char *str = addressToString(result);
        if (str) {
            if (includeNetmask) {
                printf("%s/%u\n", str, result->netmaskbits);
            }
            else {
                printf("%s\n", str);
            }
            free(str);
            return 0;
        }
        else {
            fprintf(stderr, "address conversion failed for '%s'\n", err);
            return -ERR_CONVERSION_FAILED + 1;
        }
    }
}
Exemplo n.º 5
0
std::vector<Message::Shared> ENetServer::poll()
{
    std::vector<Message::Shared> msgs;
    ENetEvent event;
    while (true) {
        // poll with a zero timeout
        int32_t res = enet_host_service(host_, &event, 0);
        if (res > 0) {
            // event occured
            if (event.type == ENET_EVENT_TYPE_RECEIVE) {
                // received a packet
                // LOG_DEBUG("A packet of length "
                //     << event.packet->dataLength
                //     << " containing `"
                //     << event.packet->data
                //     << "` was received from client_"
                //     << event.peer->incomingPeerID);

                auto stream = StreamBuffer::alloc(
                    event.packet->data,
                    event.packet->dataLength);

                // deserialize message
                auto msg = Message::alloc(event.peer->incomingPeerID);
                msg->deserialize(stream);
                msgs.push_back(msg);

                // handle requests
                if (msg->type() == MessageType::DATA_REQUEST) {
                    handleRequest(
                        event.peer->incomingPeerID,
                        msg->requestId(),
                        msg->stream());
                }

                // destroy packet payload
                enet_packet_destroy(event.packet);

            } else if (event.type == ENET_EVENT_TYPE_CONNECT) {
                // client connected
                LOG_DEBUG("Client has connected from "
                    << addressToString(&event.peer->address)
                    << ", "
                    << numClients()
                    << " connected clients");
                // add msg
                auto msg = Message::alloc(
                    event.peer->incomingPeerID,
                    MessageType::CONNECT);
                msgs.push_back(msg);
                clients_[event.peer->incomingPeerID] = event.peer;

            } else if (event.type == ENET_EVENT_TYPE_DISCONNECT) {
                // client disconnected
                LOG_DEBUG("Client has disconnected from "
                    << addressToString(&event.peer->address)
                    << ", "
                    << numClients()
                    << " clients remaining");
                // add msg
                auto msg = Message::alloc(
                    event.peer->incomingPeerID,
                    MessageType::DISCONNECT);
                msgs.push_back(msg);
                clients_.erase(event.peer->incomingPeerID);
            }
        } else if (res < 0) {
            // error occured
            LOG_ERROR("Encountered error while polling");
            break;
        } else {
            // no event
            break;
        }
    }
    return msgs;
}
Exemplo n.º 6
0
void io_callback(LoopHandle loop, CBHandle w, int revents)
{
	gIoPerSecond->Update();
	LWDP_LOG_PRINT( "TSFRONTEND", LWDP_LOG_MGR::DEBUG, 
					"Io Callback Watcher(%x)!", w);

	Cx_Interface<Ix_EventMgr> (iEventMgr)(CLSID_EventMgr); 
	if((iEventMgr).IsNull()) 
	{ 
		LWDP_LOG_PRINT("TSFRONTEND", LWDP_LOG_MGR::ERR, 
					   "Can't Get Module(%s) Pointer!(%s, %d)", 
					   "EventMgr", __FILE__, __LINE__);
		return; 
	}

	SOCKET* vfd = (SOCKET *)iEventMgr->GetCallBackData(w, LWEV::WATCHER_IO, LWEV::WATCHER_IO_FD);
	if(!vfd)
	{
		LWDP_LOG_PRINT("TSFRONTEND", LWDP_LOG_MGR::ERR, 
					   "Get io_callback CallBack fd Error");
		return;
	}

	SOCKET fd = *vfd;
#ifdef LWDP_PLATFORM_DEF_WIN32
	fd = _get_osfhandle (*(SOCKET*)vfd);
#endif

    struct sockaddr_in addr;
    socklen_t addr_size = sizeof(addr);
	int* accept_conn = (int*)malloc(sizeof(int));
	while ((*accept_conn = accept(fd, (struct sockaddr *)&addr, &addr_size)) < 0)
	{
		if (errno == EAGAIN) 
		{
			//these are transient, so don't log anything.
			continue; 
		}
		else
		{
			LWDP_LOG_PRINT("TSFRONTEND", LWDP_LOG_MGR::ERR, 
						   "Accept Error.");
			return;
		}
	}

    std::string r = addressToString(&addr);
	LWDP_LOG_PRINT("TSFRONTEND", LWDP_LOG_MGR::DEBUG, 
				   "ACCEPT Clinet IP(%s)", r.c_str());

	//Api_TaskDelay(10);
	pthread_t t;
	int result;

	result = pthread_create(&t, NULL, thread_callback, accept_conn);
	if(result != 0){
		LWDP_LOG_PRINT("TSFRONTEND", LWDP_LOG_MGR::ERR, 
					   "Can't Create Thread Ret: %d\n", result);
		return;
	}

	result = pthread_detach(t);
	if(result != 0){
		LWDP_LOG_PRINT("TSFRONTEND", LWDP_LOG_MGR::ERR, 
					   "Can't Detach Thread Ret: %d\n", result);
		return;
	}
	
}
Exemplo n.º 7
0
SearchBoxOverlay::~SearchBoxOverlay() {
  Ogre::OverlayManager::getSingleton().destroyOverlayElement("SearchBoxOverlayPanel" + addressToString(this));
}