viennacl::backend::mem_handle const & handle(viennacl::matrix_expression<LHS, RHS, OP> const & obj)
 {
   return handle(obj.lhs());
 }
Exemple #2
0
/*
 * Return a table like following:
 * {
 *    -- a line entry
 *    1 = {
 *       1 = {word="This", x0=377, y0=4857, x1=2427, y1=5089},
 *       2 = {word="is", x0=377, y0=4857, x1=2427, y1=5089},
 *       3 = {word="Word", x0=377, y0=4857, x1=2427, y1=5089},
 *       4 = {word="List", x0=377, y0=4857, x1=2427, y1=5089},
 *       x0 = 377, y0 = 4857, x1 = 2427, y1 = 5089,
 *    },
 *
 *    -- an other line entry
 *    2 = {
 *       1 = {word="This", x0=377, y0=4857, x1=2427, y1=5089},
 *       2 = {word="is", x0=377, y0=4857, x1=2427, y1=5089},
 *       x0 = 377, y0 = 4857, x1 = 2427, y1 = 5089,
 *    },
 * }
 */
static int getPageText(lua_State *L) {
	DjvuDocument *doc = (DjvuDocument*) luaL_checkudata(L, 1, "djvudocument");
	int pageno = luaL_checkint(L, 2);

	/* get page height for coordinates transform */
	ddjvu_pageinfo_t info;
	ddjvu_status_t r;
	while ((r=ddjvu_document_get_pageinfo(
				   doc->doc_ref, pageno-1, &info))<DDJVU_JOB_OK) {
		handle(L, doc->context, TRUE);
	}
	if (r>=DDJVU_JOB_FAILED)
		return luaL_error(L, "cannot get page #%d information", pageno);

	/* start retrieving page text */
	miniexp_t sexp, se_line, se_word;
	int i = 1, j = 1, counter_l = 1, counter_w=1,
		nr_line = 0, nr_word = 0;
	const char *word = NULL;

	while ((sexp = ddjvu_document_get_pagetext(doc->doc_ref, pageno-1, "word"))
				== miniexp_dummy) {
		handle(L, doc->context, True);
	}

	/* throuw page info and obtain lines info, after this, sexp's entries
	 * are lines. */
	sexp = miniexp_cdr(sexp);
	/* get number of lines in a page */
	nr_line = miniexp_length(sexp);
	/* table that contains all the lines */
	lua_newtable(L);

	counter_l = 1;
	for(i = 1; i <= nr_line; i++) {
		/* retrive one line entry */
		se_line = miniexp_nth(i, sexp);
		nr_word = miniexp_length(se_line);
		if (nr_word == 0) {
			continue;
		}

		/* subtable that contains words in a line */
		lua_pushnumber(L, counter_l);
		lua_newtable(L);
		counter_l++;

		/* set line position */
		lua_pushstring(L, "x0");
		lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_line)));
		lua_settable(L, -3);

		lua_pushstring(L, "y1");
		lua_pushnumber(L,
				info.height - miniexp_to_int(miniexp_nth(2, se_line)));
		lua_settable(L, -3);

		lua_pushstring(L, "x1");
		lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_line)));
		lua_settable(L, -3);

		lua_pushstring(L, "y0");
		lua_pushnumber(L,
				info.height - miniexp_to_int(miniexp_nth(4, se_line)));
		lua_settable(L, -3);

		/* now loop through each word in the line */
		counter_w = 1;
		for(j = 1; j <= nr_word; j++) {
			/* retrive one word entry */
			se_word = miniexp_nth(j, se_line);
			/* check to see whether the entry is empty */
			word = miniexp_to_str(miniexp_nth(5, se_word));
			if (!word) {
				continue;
			}

			/* create table that contains info for a word */
			lua_pushnumber(L, counter_w);
			lua_newtable(L);
			counter_w++;

			/* set word info */
			lua_pushstring(L, "x0");
			lua_pushnumber(L, miniexp_to_int(miniexp_nth(1, se_word)));
			lua_settable(L, -3);

			lua_pushstring(L, "y1");
			lua_pushnumber(L,
					info.height - miniexp_to_int(miniexp_nth(2, se_word)));
			lua_settable(L, -3);

			lua_pushstring(L, "x1");
			lua_pushnumber(L, miniexp_to_int(miniexp_nth(3, se_word)));
			lua_settable(L, -3);

			lua_pushstring(L, "y0");
			lua_pushnumber(L,
					info.height - miniexp_to_int(miniexp_nth(4, se_word)));
			lua_settable(L, -3);

			lua_pushstring(L, "word");
			lua_pushstring(L, word);
			lua_settable(L, -3);

			/* set word entry to line subtable */
			lua_settable(L, -3);
		} /* end of for (j) */

		/* set line entry to page text table */
		lua_settable(L, -3);
	} /* end of for (i) */

	return 1;
}
Exemple #3
0
bool LoadPrefs()
{
    if (prefLoaded) // already attempted loading
        return true;

    char filepath[MAXPATHLEN];
    sprintf(filepath, "%s/%s", MPLAYER_DATADIR, PREF_FILE_NAME);

    TiXmlDocument doc;

    bool loadOkay = doc.LoadFile(filepath);
    if (loadOkay) {
        FixInvalidSettings();
        TiXmlHandle docu(&doc);
        TiXmlElement* settings = docu.FirstChildElement().Element();
        if (settings == NULL) {
            goto noheader;
        }
        TiXmlHandle handle(0);
        TiXmlElement* elem;
        handle = TiXmlHandle(settings);
        elem = handle.FirstChild("global").FirstChild().Element();
        for (elem; elem; elem = elem->NextSiblingElement()) {
            const char* elemName = elem->Value();
            if (strcmp(elemName, "exit") == 0) {
                XMPlayerCfg.exit_action = atoi(elem->Attribute("value"));
            } else if (strcmp(elemName, "language") == 0) {
                XMPlayerCfg.language = atoi(elem->Attribute("value"));
            }
        }
        elem = handle.FirstChild("filebrowser").FirstChild().Element();
        for (elem; elem; elem = elem->NextSiblingElement()) {
            const char* elemName = elem->Value();
            if (strcmp(elemName, "sort") == 0) {
                XMPlayerCfg.sort_order = atoi(elem->Attribute("value"));
            }
        }
        elem = handle.FirstChild("audio").FirstChild().Element();
        for (elem; elem; elem = elem->NextSiblingElement()) {
            const char* elemName = elem->Value();
            if (strcmp(elemName, "language") == 0) {
                sprintf(XMPlayerCfg.alang, elem->Attribute("value"));
                sprintf(XMPlayerCfg.alang_desc, elem->Attribute("desc"));
            } else if (strcmp(elemName, "volume") == 0) {
                XMPlayerCfg.volume = atoi(elem->Attribute("value"));
            } else if (strcmp(elemName, "softvol") == 0) {
                XMPlayerCfg.softvol = atoi(elem->Attribute("value"));
            }
        }
        elem = handle.FirstChild("video").FirstChild().Element();
        for (elem; elem; elem = elem->NextSiblingElement()) {
            const char* elemName = elem->Value();
            if (strcmp(elemName, "framedrop") == 0) {
                XMPlayerCfg.framedrop = atoi(elem->Attribute("value"));
            } else if (strcmp(elemName, "vsync") == 0) {
                XMPlayerCfg.vsync = atoi(elem->Attribute("value"));
            }
        }
        elem = handle.FirstChild("subtitles").FirstChild().Element();
        for (elem; elem; elem = elem->NextSiblingElement()) {
            const char* elemName = elem->Value();
            if (strcmp(elemName, "sub_color") == 0) {
                elem->Attribute("value", &XMPlayerCfg.subcolor);
            } else if (strcmp(elemName, "border_color") == 0) {
                elem->Attribute("value", &XMPlayerCfg.border_color);
            } else if (strcmp(elemName, "codepage") == 0) {
                sprintf(XMPlayerCfg.subcp, elem->Attribute("value"));
                sprintf(XMPlayerCfg.subcp_desc, elem->Attribute("desc"));
            } else if (strcmp(elemName, "language") == 0) {
                sprintf(XMPlayerCfg.sublang, elem->Attribute("value"));
                sprintf(XMPlayerCfg.sublang_desc, elem->Attribute("desc"));
            }
        }
        doc.Clear();
        prefLoaded = true;

        printf("[Preferences] Sucessfully loaded xmplayer.xml \n");
        return true;

    } else {
noheader:
        DefaultSettings();
        printf("[Preferences] Failed to load xmplayer.xml - Loading default settings \n");
        return false;
    }

}
Exemple #4
0
int main(void) {

    int i;
    int ifd;
    int len;
    int client_sock;
    struct online_user *user;
    Client client;
    struct sockaddr_in client_name;
    int client_name_len = sizeof(client_name);
#define MAX_BUFSIZE	0x100000
    char buf[MAX_BUFSIZE];
    struct format *package = (struct format *)buf;

    tcp_server_sock = tcp_startup(SERVER_TCP_PORT);

    init_mysql();
    register_ctrl_c();

    kdpfd = epoll_create(MAXEPOLLSIZE);

    /* 设置要监听的事件。EPOLLIN 表示可读,EPOLLET则指定电平触发 */
    ev.events = EPOLLIN;
    ev.data.fd = tcp_server_sock;

    if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, tcp_server_sock, &ev) < 0)
        /* 把 tcp sock 加入监听集合,以便接收连接请求 */
        error_die("tcp epoll_ctl\n");

    /* 记录监听的文件数,同时他也是 epoll_wait 的第三个参数。
       因为内核需要知道 events 数组的有效数据有多长 */
    curfds = 1;

    for (;;) {

        memset(buf,0,sizeof(buf));
        printf("waiting...\n");

        /* 等待有事件发生。该函数的返回值存放在 nfds 和 events 内 */
        nfds = epoll_wait(kdpfd, events, curfds, -1);

        if (nfds < 0)
            error_die("epoll_wait");

        for (i = 0; i < nfds; i++) {

            ifd = events[i].data.fd;

            if (ifd == tcp_server_sock) {
                //新的 TCP 连接请求到来

                if (!(events[i].events & EPOLLIN))
                    error_die("failed to event is not EPOLLIN\n");

                client_sock = accept(tcp_server_sock,(struct sockaddr *)&client_name,&client_name_len);
                setnonblocking(client_sock);

                ev.events  = EPOLLIN;
                ev.data.fd = client_sock;
                if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, client_sock, &ev) < 0)
                    error_die("epoll_ctl");

                curfds++;

                client = alloc_client(client_sock);
                add_client(client);

            } else if ((events[i].events & EPOLLIN)) {
                /* 客户端有数据发来(POLLIN)或者发生 POLLHUP/POLLERR(这两个事件系统会自动监听) */

                client = find_client(ifd);

                if (client != NULL && client->handler != NULL) {
                    //已经有了处理函数,直接调用这个函数来处理
                    client->handler(ifd,client->private);
                } else {
                    //默认的处理方法

                    //读入数据包头部。
                    len = read(ifd,package,(sizeof(struct format)-sizeof(package->data)));

                    if (len <= 0) {
                        //对方断线。
                        close_connect(ifd);
                        continue;
                    }

                    if (package->length >= MAX_BUFSIZE || package->length <= 0) {

                        while(read(ifd,package->data,4) > 0);
                        continue;
                    }

                    if ((len = read(ifd,package->data,package->length) <= 0)) {
                        //读入数据包内容

                        close_connect(ifd);
                        continue;
                    }

                    // 处理数据
                    if (handle(ifd,package) == NEED_WRITE) {

                        ev.events = EPOLLOUT;
                        ev.data.fd = ifd;
                        epoll_ctl(kdpfd,EPOLL_CTL_MOD,ifd,&ev);
                    }
                }

            } else if(events[i].events & EPOLLOUT) {
Exemple #5
0
int main()
{
#ifdef WIN32
	acl::acl_cpp_init();
#endif

	acl::aio_handle handle(acl::ENGINE_SELECT);
	acl::http_service* service = new acl::http_service();

	// 使消息服务器监听 127.0.0.1 的地址
	if (service->open(&handle) == false)
	{
		printf(">>open message service error!\n");
		printf(">>enter any key to quit\n");
		getchar();
		return (1);
	}


	// 创建 HTTP 请求过程
	acl::string domain;
	domain = "www.hexun.com";
	//domain = "192.168.1.229";
	//domain = "www.renwou.net";
	http_request* req = new http_request(domain.c_str(), 80, &handle);
	req->set_url("/index.html");
	//req->set_url("/download/banmau_install.exe");
	req->set_host(domain);
	req->set_keep_alive(false);
	req->set_method(acl::HTTP_METHOD_GET);
	req->add_cookie("x-cookie-name", "cookie-value");
	//req->set_redirect(1); // 设置自动重定向的次数限制

	// 通知异步消息服务器处理该 HTTP 请求过程

	//////////////////////////////////////////////////////////////////////////
	//acl::string buf;
	//req->build_request(buf);
	//printf("-----------------------------------------------\n");
	//printf("%s", buf.c_str());
	//printf("-----------------------------------------------\n");
	//////////////////////////////////////////////////////////////////////////

	service->do_request(req);

	while (true)
	{
		if (handle.check() == false)
		{
			printf(">>quit aio process\n");
			break;
		}
	}

	printf("delete http service now\r\n");
	delete service;

	printf("delete delay aio stream\r\n");
	handle.check();

	printf(">>enter any key to exist\n");
	getchar();
	return (0);
}
Exemple #6
0
 int ErrorRecord::field ( uint index ) const
 {
     return (::MsiRecordGetInteger(handle(),index));
 }
Exemple #7
0
void Styles::LoadSkinFile(const wxString& filePath) {
  TiXmlDocument doc(filePath.mb_str());
  doc.LoadFile();

  TiXmlElement* root = doc.FirstChildElement("Skin");
  if (!root) {
    WLOG(_T("Styles::LoadSkinFile: Could not load XML. No Skin element found: %s"), filePath);
    return;
  }

  SkinMetadata skinMetadata;
  Styles::GetSkinMetadata(root, skinMetadata);

  if (!Styles::IsSkinVersionCompatible(skinMetadata.CompatibleVersion)) {
    MessageBoxes::ShowError(wxString::Format(_("This skin is not compatible with the current version of %s."), APPLICATION_NAME));
    return;
  }

  // *****************************************************************
  // Set default values
  // *****************************************************************
  Styles::OptionButton.IconColor = wxColour(255,255,255);
  Styles::ArrowButton.ColorDown = wxNullColour;
  Styles::ArrowButton.ColorOver = wxNullColour;
  Styles::Icon.LabelGap = 10;
  Styles::Font.Color = wxColor(0,0,0);
  Styles::Font.Face = _T("Arial");
  Styles::Font.Size = 8;
  Styles::Font.Weight = wxBOLD;
  Styles::Font.ShadowColor = wxColor(255,255,255);
  Styles::Font.ShadowAlpha = 0.2;
  Styles::Font.ShadowOffset = 1;
  
  // *****************************************************************
  // Load the XML
  // *****************************************************************
  for (TiXmlElement* element = root->FirstChildElement(); element; element = element->NextSiblingElement()) {
    wxString elementName = wxString(element->Value(), wxConvUTF8);
    TiXmlHandle handle(element);
    wxRect resultRect;

    if (elementName == _T("ArrowButton")) {
      XmlUtil::ReadElementTextAsRect(handle, "Rectangle", Styles::ArrowButton.SourceRectangle);
      XmlUtil::ReadElementTextAsColor(handle, "ColorOver", Styles::ArrowButton.ColorOver);
      XmlUtil::ReadElementTextAsColor(handle, "ColorDown", Styles::ArrowButton.ColorDown);
    }

    if (elementName == _T("BrowseButton")) {
      XmlUtil::ReadElementTextAsColor(handle, "ColorOver", Styles::BrowseButton.ColorOver);
      XmlUtil::ReadElementTextAsColor(handle, "ColorDown", Styles::BrowseButton.ColorDown);
    }

    if (elementName == _T("OptionPanel")) {
      XmlUtil::ReadElementTextAsRect(handle, "Rectangle", Styles::OptionPanel.SourceRectangle);
      XmlUtil::ReadElementTextAsRect(handle, "Padding", resultRect);
      Styles::OptionPanel.Padding.FromRect(resultRect);
      Styles::OptionPanel.ButtonHGap = XmlUtil::ReadElementTextAsInt(handle, "HGap");
      Styles::OptionPanel.ButtonVGap = XmlUtil::ReadElementTextAsInt(handle, "VGap");
    }

    if (elementName == _T("MainPanel")) {
      XmlUtil::ReadElementTextAsRect(handle, "Rectangle", Styles::MainPanel.SourceRectangle);
    }

    if (elementName == _T("IconPanel")) {
      XmlUtil::ReadElementTextAsRect(handle, "Rectangle", Styles::InnerPanel.SourceRectangle);
      XmlUtil::ReadElementTextAsRect(handle, "Padding", resultRect);
      Styles::InnerPanel.Padding.FromRect(resultRect);
    }

    if (elementName == _T("Icon")) {
      XmlUtil::ReadElementTextAsRect(handle, "Padding", resultRect);
      Styles::Icon.Padding.FromRect(resultRect);
    }

    if (elementName == _T("IconLabelFont")) {
      XmlUtil::ReadElementTextAsColor(handle, "Color", Styles::Font.Color);
      XmlUtil::ReadElementTextAsColor(handle, "ShadowColor", Styles::Font.ShadowColor);
      Styles::Font.Face = XmlUtil::ReadElementText(handle, "Face", _T("Arial"));
      Styles::Font.ShadowOffset = XmlUtil::ReadElementTextAsInt(handle, "ShadowOffset", 1);
      int shadowAlpha = XmlUtil::ReadElementTextAsInt(handle, "ShadowAlpha", 20);
      Styles::Font.ShadowAlpha = (float)shadowAlpha / 100.0;
      Styles::Font.Size = XmlUtil::ReadElementTextAsInt(handle, "Size", 8);
      wxString weight = XmlUtil::ReadElementText(handle, "Weight", _T("Normal"));
      Styles::Font.Weight = weight == _T("Bold") ? wxBOLD : wxNORMAL;
    }

    if (elementName == _T("OptionButton")) {
      XmlUtil::ReadElementTextAsColor(handle, "ColorOver", Styles::OptionButton.ColorOver);
      XmlUtil::ReadElementTextAsColor(handle, "ColorDown", Styles::OptionButton.ColorDown);
      XmlUtil::ReadElementTextAsPoint(handle, "DownIconOffset", Styles::OptionButton.DownIconOffset);
      XmlUtil::ReadElementTextAsColor(handle, "IconColor", Styles::OptionButton.IconColor);
    }
  }

}
Exemple #8
0
int OggFile::rate()
{
    return ov_info(handle(), -1)->rate;
}
Exemple #9
0
void OggFile::rewind()
{
    ov_raw_seek(handle(), 0);
}
ZLNetworkXMLParserData::~ZLNetworkXMLParserData() {
	if (handle() != 0) {
		myReader->shutdown();
	}
}
void default_garbage_collector::commit_object(object &constructed)
{
    object_handle handle(remove_storage(
                             reinterpret_cast<char *>(&constructed)));
    m_objects.push_back(std::move(handle));
}
void RangeWidget::paint_view(QPainter *painter, const QRectF &rect) {
    QPen pen;
    pen.setColor(QColor("#F28585"));
    pen.setWidth(10);
    painter->setPen(pen);

    painter->setRenderHint(QPainter::Antialiasing);
    painter->setRenderHint(QPainter::HighQualityAntialiasing);

    QRectF handle(this->boundingRect().center().x() - 5,
                  this->boundingRect().center().y() - 5, 10, 10);
    QRectF borderRect(boundingRect().x() + 24, boundingRect().y() + 24,
                      boundingRect().width() - 48, boundingRect().height() - 48);

    painter->save();
    QPen pen_border;
    pen_border.setColor(QColor("#F0F0F0"));
    pen_border.setWidth(4);
    painter->setPen(pen_border);

    // painter->drawEllipse(borderRect);

    painter->drawLine(
        QPointF(0.0, this->boundingRect().height() / 2),
        QPointF(this->boundingRect().width(), this->boundingRect().height() / 2));
    painter->restore();

    /*
    QPainterPath clockInisde;
    clockInisde.addEllipse(QRectF(borderRect.x() + 2, borderRect.y() + 2,
    borderRect.width() - 4 , borderRect.height() - 4));

    //painter->fillPath(clockInisde, QColor("#F28585"));
    painter->fillPath(clockInisde, QColor(Qt::white));

    QFont font = painter->font();
    font.setBold(true);
    font.setPixelSize(32);
    painter->save();
    painter->setFont(font);
    // painter->drawText(borderRect, Qt::AlignCenter,
    d->convertAngleToTimeString(d->mAngle));
    painter->restore();

    painter->save();
    QTransform xform;
    QPointF transPos = this->boundingRect().center();
    xform.translate(transPos.x(), transPos.y());
    xform.rotate(d->mAngle);
    xform.translate(-transPos.x(), -transPos.y());

    painter->setTransform(xform);

    QLineF line(handle.center(), QPointF(boundingRect().width() - 48,
    (boundingRect().height() / 2) - 48));
    //
    QRectF ctrRect(line.x2(), line.y2(), 10, 10);
    QRectF ctrFrameRect(line.x2(), line.y2(), 32, 32);
    QPainterPath path;
    path.addEllipse(ctrFrameRect);
    painter->fillPath(path, QColor(Qt::white));
    painter->fillPath(path, QColor("#F28585"));

    QPen whitePen;
    whitePen.setColor(Qt::white);
    painter->setPen(whitePen);
    painter->drawText(ctrFrameRect, Qt::AlignCenter,
    QString("%1").arg((int)d->mProgressValue));

    painter->restore();
    */
}
Exemple #13
0
static int swReactorPoll_wait(swReactor *reactor, struct timeval *timeo)
{
	swReactorPoll *object = reactor->object;
	swDataHead event;
	swReactor_handle handle;
	int ret;
	int i;

	while (swoole_running > 0)
	{
		ret = poll(object->events, object->fd_num, timeo->tv_sec * 1000 + timeo->tv_usec / 1000);
		if (ret < 0)
		{
			if (swReactor_error(reactor) < 0)
			{
				swWarn("poll error. Errno=%d\n", errno);
			}
			continue;
		}
		else if (ret == 0)
		{
			if(reactor->onTimeout != NULL)
			{
				reactor->onTimeout(reactor);
			}
			continue;
		}
		else
		{
			for (i = 0; i < object->fd_num; i++)
			{
				event.fd = object->events[i].fd;
				event.from_id = reactor->id;
				event.type = object->fds[i].fdtype;
				//in
				if (object->events[i].revents & POLLIN)
				{
					handle = swReactor_getHandle(reactor, SW_EVENT_READ, event.type);
					swTrace("Event:Handle=%p|fd=%d|from_id=%d|type=%d\n",
							reactor->handle[event.type], event.fd, reactor->id, object->fds[i].fdtype);
					ret = handle(reactor, &event);
					if (ret < 0)
					{
						swWarn("poll[POLLIN] handler fail. fd=%d|errno=%d.Error: %s[%d]", event.fd, errno, strerror(errno), errno);
					}
				}
				//error
				if (object->events[i].revents & (POLLHUP | POLLERR))
				{
					handle = swReactor_getHandle(reactor, SW_EVENT_READ, event.type);
					swTrace("Event:Handle=%p|fd=%d|from_id=%d|type=%d\n",
							reactor->handle[event.type], event.fd, reactor->id, object->fds[i].fdtype);
					ret = handle(reactor, &event);
					if (ret < 0)
					{
						swWarn("poll[POLLERR] handler fail. fd=%d|errno=%d.Error: %s[%d]", event.fd, errno, strerror(errno), errno);
					}
				}
				//out
				if (object->events[i].revents & POLLOUT)
				{
					handle = swReactor_getHandle(reactor, SW_EVENT_WRITE, event.type);
					swTrace("Event:Handle=%p|fd=%d|from_id=%d|type=%d\n",
							handle, event.fd, reactor->id, object->fds[i].fdtype);
					ret = handle(reactor, &event);
					if (ret < 0)
					{
						swWarn("poll[POLLOUT] handler fail. fd=%d|errno=%d.Error: %s[%d]", event.fd, errno, strerror(errno), errno);
					}
				}
			}
			if (object->fd_num < 1)
			{
				swWarn("poll exception");
			}
			if(reactor->onFinish != NULL)
			{
				reactor->onFinish(reactor);
			}
		}
	}
	return SW_OK;
}
Exemple #14
0
 viennacl::memory_types active_handle_id(T const & obj)
 {
   return handle(obj).get_active_handle_id();
 }
Exemple #15
0
 void Tooltip::popup ()
 {
     ::SendMessageW(handle(),TTM_POPUP,0,0);
 }
Exemple #16
0
 long read(void * out, size_t len)
 {
     int bitstream = -1;
     long result = ov_read(handle(), static_cast<char*>(out), len, 0, 2, 1, &bitstream);
     return result;
 }
Exemple #17
0
 void Tooltip::deactivate ()
 {
     ::SendMessageW(handle(),TTM_ACTIVATE,static_cast<::WPARAM>(FALSE),0);
 }
int Fl_ImageViewer::prochandle( int event )
{
    return handle( event );
}
// Map an already open file
void *FXMemMap::map(FXlong off,FXival len){
  if(isOpen()){

    // Get file size
    FXlong filesize=size();
    if(0<=filesize){

#ifdef WIN32

      // Map whole file
      if(len==-1) len=filesize-off;

      // Set access flags
      DWORD prot=0;
      if(access&ReadOnly){ prot=PAGE_READONLY; }
      if(access&WriteOnly){ prot=PAGE_READWRITE; }

      DWORD flag=0;
      if(access&ReadOnly){ flag=FILE_MAP_READ; }
      if(access&WriteOnly){ flag=FILE_MAP_WRITE; }

      // Now map it
      FXInputHandle hnd=::CreateFileMapping(handle(),NULL,prot,0,len,NULL);
      if(hnd!=NULL){
        FXuchar* ptr=(FXuchar*)::MapViewOfFile(hnd,flag,0,off,len);
        if(ptr!=NULL){
          maphandle=hnd;
          mapbase=ptr;
          maplength=len;
          mapoffset=off;
          mapposition=off;
          return mapbase;
          }
        ::CloseHandle(hnd);
        }
#else

      // Map whole file
      if(len==-1) len=filesize-off;

      // Trying to map region larger than the file
      if(filesize<off+len){
        if(access&WriteOnly){
          truncate(off+len);            // Extends the file if writing
          }
        else{
          len=filesize-off;             // Map smaller region when reading
          }
        }

      // Set access flags
      FXint prot=PROT_NONE;
      if(access&ReadOnly){ prot|=PROT_READ; }
      if(access&WriteOnly){ prot|=PROT_WRITE|PROT_READ; }
      if(access&Executable){ prot|=PROT_EXEC; }

      // Now map it
      FXuchar* ptr=(FXuchar*)::mmap(NULL,len,prot,MAP_SHARED,handle(),off);
      if(ptr!=MAP_FAILED){
        mapbase=ptr;
        maplength=len;
        mapoffset=off;
        mapposition=off;
        return mapbase;
        }
#endif
      }
    }
  return NULL;
  }
Exemple #20
0
void EdgeQM::get_edge_evaluations( PatchData& pd, 
                                   std::vector<size_t>& handles,
                                   bool free_vertices_only, 
                                   bool single_pass_evaluate,
                                   MsqError& err )
{
  std::vector<EdgeData> vtx_edges;
  size_t n_verts = free_vertices_only ? pd.num_free_vertices() : pd.num_nodes();
  size_t n_cutoff = single_pass_evaluate ? pd.num_nodes() : n_verts;
  handles.clear();

  for (size_t i = 0; i < n_verts; ++i) {
    if (pd.vertex_by_index(i).is_flag_set( MsqVertex::MSQ_PATCH_FIXED ))
      continue;

    vtx_edges.clear();

    size_t n_elems;
    const size_t* elems;
    elems = pd.get_vertex_element_adjacencies( i, n_elems, err );
    MSQ_ERRRTN(err);

    for (size_t j = 0; j < n_elems; ++j) {
      MsqMeshEntity& elem = pd.element_by_index(elems[j]);
      unsigned n_edges = TopologyInfo::edges( elem.get_element_type() );
      for (unsigned k = 0; k < n_edges; ++k) {
        const unsigned* edge = TopologyInfo::edge_vertices( elem.get_element_type(), k, err );
        MSQ_ERRRTN(err);

        size_t vtx1 = elem.get_vertex_index_array()[edge[0]];
        size_t vtx2 = elem.get_vertex_index_array()[edge[1]];
        size_t other;
        if (vtx1 == i)
          other = vtx2;
        else if (vtx2 == i)
          other = vtx1;
        else
          continue;
        
          // If !free_vertices_only, we'll visit every edge twice.  
          // The first check below ensures that we only add each edge
          // once.  The second check is never true unless free_vertices_only
          // is true and single_pass_evaluate is false.  In that case, it 
          // serves as an exception to the first rule for those cases in which 
          // we visit an edge only once.  For single_pass_evaluate (e.g.
          // BCD initialization or QualityAssessor) we want to avoid visiting
          // and edge more than once for every patch rather than just within
          // this patch.
        if (other > i || other > n_cutoff) {
          EdgeData d = { other, elems[j], k };
          vtx_edges.push_back(d);
        }
      } // end for each edge in element
    } // end for each element adjacent to vertex
    
    std::sort( vtx_edges.begin(), vtx_edges.end() );
    std::vector<EdgeData>::iterator it, end;
    end = std::unique( vtx_edges.begin(), vtx_edges.end() );
    for (it = vtx_edges.begin(); it != end; ++it) 
      handles.push_back( handle( it->elemEdge, it->adjElem ) );
  } // end for each (free) vertex
}
Exemple #21
0
HDC QWindowsWindow::getDC()
{
    if (!m_hdc)
        m_hdc = GetDC(handle());
    return m_hdc;
}
Exemple #22
0
int
main(int argc, char **argv)
{
  /* Parse options */
  int i;
  for (i=1; i<argc; i++)
    {
      char *s = argv[i];
      if (s[0] == '-' && s[1] != 0)
        {
          char buf[32];
          const char *opt = s;
          const char *arg = strchr(opt, '=');
          if (*opt == '-')
            opt += 1;
          if (*opt == '-')
            opt += 1;
          if (arg)
            {
              int l = arg - opt;
              if (l > (int)sizeof(buf) - 1)
                l = sizeof(buf) - 1;
              strncpy(buf, opt, l);
              buf[l] = 0;
              opt = buf;
              arg += 1;
            }
          
          if (!strcmp(opt,"page") || 
              !strcmp(opt,"pages") )
            {
              if (!arg && i<argc)
                arg = argv[i++];
              if (!arg)
                die(i18n("option %s needs an argument."), s);
              if (pagespec)
                fprintf(stderr,i18n("warning: duplicate option --page=...\n"));
              pagespec = arg;
            }
          else if (!strcmp(opt, "detail"))
            {
              if (!arg)
                arg = "char";
              if (detail)
                fprintf(stderr,i18n("warning: duplicate option --detail.\n"));
              detail = arg;
            }
          else if (!strcmp(opt, "escape") && !arg)
            escape = 1;
          else
            die(i18n("unrecognized option %s."), s);
        }
      else if (!inputfilename)
        inputfilename = s;
      else if (! outputfilename)
        outputfilename = s;
      else
        usage();
    }
  
  /* Defaults */
  if (! inputfilename)
    usage();
  if (outputfilename)
    if (! freopen(outputfilename, "w", stdout))
      die(i18n("cannot open output file %s."), outputfilename);
  if (! pagespec)
    pagespec = "1-$";
  
  /* Create context and document */
  if (! (ctx = ddjvu_context_create(argv[0])))
    die(i18n("Cannot create djvu context."));
  if (! (doc = ddjvu_document_create_by_filename(ctx, inputfilename, TRUE)))
    die(i18n("Cannot open djvu document '%s'."), inputfilename);
  while (! ddjvu_document_decoding_done(doc))
    handle(TRUE);
  
  /* Process all pages */
  i = ddjvu_document_get_pagenum(doc);
  parse_pagespec(pagespec, i, dopage);
  
  /* Close */
  if (doc)
    ddjvu_document_release(doc);
  if (ctx)
    ddjvu_context_release(ctx);

  /* Return */
  minilisp_finish();  
  return 0;
}
Exemple #23
0
void HttpRequest::_on_request_read(uv_stream_t*, ssize_t nread, uv_buf_t buf) {
  if (nread > 0) {
    //std::cerr << nread << " bytes read\n";
    if (_ignoreNewData) {
      // Do nothing
    } else if (_protocol == HTTP) {
      int parsed = http_parser_execute(&_parser, &request_settings(), buf.base, nread);
      if (_parser.upgrade) {
        char* pData = buf.base + parsed;
        ssize_t pDataLen = nread - parsed;

        if (_headers.find("upgrade") != _headers.end() &&
            _headers["upgrade"] == std::string("websocket") &&
            _headers.find("sec-websocket-key") != _headers.end()) {

          // Freed in on_response_written
          HttpResponse* pResp = new HttpResponse(this, 101, "Switching Protocols",
            NULL);
          pResp->addHeader("Upgrade", "websocket");
          pResp->addHeader("Connection", "Upgrade");
          pResp->addHeader(
            "Sec-WebSocket-Accept",
            createHandshakeResponse(_headers["sec-websocket-key"]));
          // TODO: Consult app about supported WS protocol
          //pResp->addHeader("Sec-WebSocket-Protocol", "");

          pResp->writeResponse();

          _protocol = WebSockets;
          _pWebApplication->onWSOpen(this);

          read(pData, pDataLen);
        }

        if (_protocol != WebSockets) {
          // TODO: Write failure
          close();
        }
      } else if (parsed < nread) {
        if (!_ignoreNewData) {
          fatal_error("on_request_read", "parse error");
          uv_read_stop((uv_stream_t*)handle());
          close();
        }
      }
    } else if (_protocol == WebSockets) {
      read(buf.base, nread);
    }
  } else if (nread < 0) {
    uv_err_t err = uv_last_error(_pLoop);
    if (err.code == UV_EOF /*|| err.code == UV_ECONNRESET*/) {
    } else {
      fatal_error("on_request_read", uv_strerror(err));
    }
    close();
  } else {
    // It's normal for nread == 0, it's when uv requests a buffer then
    // decides it doesn't need it after all
  }

  free(buf.base);
}
inline handle& handle::operator=(handle const& other)
{
    handle(other).swap(*this);
    return *this;
}
Exemple #25
0
static int swReactorKqueue_wait(swReactor *reactor, struct timeval *timeo)
{
	swEvent event;
	swFd fd_;
	swReactorKqueue *this = reactor->object;
	swReactor_handle handle;

	int i, n, ret;
    struct timespec t;

    t.tv_sec = timeo->tv_sec;
    t.tv_nsec = timeo->tv_usec;

	while (SwooleG.running > 0)
	{
		n = kevent(this->epfd, NULL, 0, this->events, this->event_max, &t);

		if (n < 0)
		{
			//swTrace("kqueue error.EP=%d | Errno=%d\n", this->epfd, errno);
			if(swReactor_error(reactor) < 0)
			{
				swWarn("Kqueue[#%d] Error: %s[%d]", reactor->id, strerror(errno), errno);
				return SW_ERR;
			}
			else
			{
				continue;
			}
		}
		else if (n == 0)
		{
			if(reactor->onTimeout != NULL)
			{
				reactor->onTimeout(reactor);
			}
			continue;
		}
		for (i = 0; i < n; i++)
		{
			if (this->events[i].udata)
			{
				memcpy(&fd_, &(this->events[i].udata), sizeof(fd_));
				event.fd = fd_.fd;
				event.from_id = reactor->id;
				event.type = fd_.fdtype;
				//read
				if (this->events[i].filter == EVFILT_READ)
				{
					handle = swReactor_getHandle(reactor, SW_EVENT_READ, event.type);
					ret = handle(reactor, &event);
					if (ret < 0)
					{
						swWarn("kqueue event handler fail. fd=%d|errno=%d.Error: %s[%d]", event.fd, errno, strerror(errno), errno);
					}
				}
				//write
				else if (this->events[i].filter == EVFILT_WRITE)
				{
					handle = swReactor_getHandle(reactor, SW_EVENT_WRITE, event.type);
					ret = handle(reactor, &event);
					if (ret < 0)
					{
						swWarn("kqueue event handler fail. fd=%d|errno=%d.Error: %s[%d]", event.fd, errno, strerror(errno), errno);
					}
				}
				else
				{
					swWarn("kqueue event unknow filter=%d", this->events[i].filter);
				}
			}

		}
		if(reactor->onFinish != NULL)
		{
			reactor->onFinish(reactor);
		}
	}
	return 0;
}
Exemple #26
0
 hid_t handleOrDefault () const {
   if (!isValid ())
     return H5P_DEFAULT;
   return handle ();
 }
Exemple #27
0
/* Casts libmagic on the file <lpfile> to determine its type and
 * tries to find and run a handler for that type of files.
 */
int runmime (wchar_t *logfile, LPSHELLEXECUTEINFOW einfo, wchar_t *lpfile, wchar_t *lpdirectory)
{
  magic_t magicmimetype = NULL, magicmimeencoding = NULL, magicapple = NULL, magicname = NULL;
  char *mimetype, *mimeencoding, *apple, *name;
  char *argv1 = NULL;
  MimeResults mres;
  int ret = 0;

  logtofilew (logfile, L">runmime\n");

  magicname = load (NULL, MAGIC_NONE);
  magicmimetype = load (NULL, MAGIC_MIME_TYPE);
  magicmimeencoding = load (NULL, MAGIC_MIME_ENCODING);
  magicapple = load (NULL, MAGIC_APPLE);

  logtofilew (logfile, L"magics: %08x, %08x, %08x, %08x\n", magicname, magicmimetype, magicmimeencoding, magicapple);
  wchartostr (lpfile, &argv1, CP_THREAD_ACP);
  logtofilew (logfile, L"file to check is %S\n", argv1);
  
  memset (&mres, 0, sizeof (mres));

  mres.type = (char *) magic_file (magicmimetype, argv1);
  mres.enc = (char *) magic_file (magicmimeencoding, argv1);
  mres.apple = (char *) magic_file (magicapple, argv1);
  mres.name = (char *) magic_file (magicname, argv1);

  logtofilew (logfile, L"magic results: {%S} {%S} {%S} {%S}\n", mres.name, mres.type, mres.enc, mres.apple);
  if (mres.name != NULL)
    mres.name = strdup (mres.name);
  if (mres.type != NULL)
    mres.type = strdup (mres.type);
  if (mres.enc != NULL)
    mres.enc = strdup (mres.enc);
  if (mres.apple != NULL)
    mres.apple = strdup (mres.apple);

  strtowchar (mres.name, &mres.wname, CP_THREAD_ACP);
  strtowchar (mres.type, &mres.wtype, CP_THREAD_ACP);
  strtowchar (mres.enc, &mres.wenc, CP_THREAD_ACP);
  strtowchar (mres.apple, &mres.wapple, CP_THREAD_ACP);

  magic_close (magicmimetype);
  magic_close (magicmimeencoding);
  magic_close (magicapple);
  magic_close (magicname);

  if (argv1 != NULL)
    free (argv1);

  if (mres.type == NULL && mres.apple == NULL && mres.name == NULL)
  {
    logtofilew (logfile, L"Zero results, returning.\n");
    ret = -1;
  }
  else
  {
    ret = handle (logfile, &mres, einfo, lpfile, lpdirectory);
  }

  if (mres.name != NULL)
    free (mres.name);
  if (mres.type != NULL)
    free (mres.type);
  if (mres.enc != NULL)
    free (mres.enc);
  if (mres.apple != NULL)
    free (mres.apple);

  if (mres.wname != NULL)
    free (mres.wname);
  if (mres.wtype != NULL)
    free (mres.wtype);
  if (mres.wenc != NULL)
    free (mres.wenc);
  if (mres.wapple != NULL)
    free (mres.wapple);
  
  logtofilew (logfile, L"<runmime %d\n", ret);
  return ret;
}
Exemple #28
0
 void Tooltip::update ()
 {
     ::SendMessageW(handle(),TTM_UPDATE,0,0);
 }
Exemple #29
0
/*
** Returns 0 for success, negative number for error code.
** bpp can be 24 or 8.
**
*/
int bmpdjvu_djvufile_to_bmp(WILLUSBITMAP *bmp,char *infile,int pageno,
                            int dpi,int bpp,FILE *out)

    {
    ddjvu_context_t *ctx;
    ddjvu_document_t *doc;
    ddjvu_page_t *page;
    /* ddjvu_page_type_t type; */
    ddjvu_rect_t prect;
    ddjvu_rect_t rrect;
    ddjvu_format_style_t style;
    ddjvu_render_mode_t mode;
    ddjvu_format_t *fmt;
    int i,iw,ih,idpi,status;

    ctx=ddjvu_context_create("bmpdjvu_djvufile_to_bmp");
    if (ctx==NULL)
        {
        nprintf(out,"Cannot create djvu context.\n");
        return(-1);
        }
    doc=ddjvu_document_create_by_filename_utf8(ctx,infile,1);
    if (doc==NULL)
        {
        ddjvu_context_release(ctx);
        nprintf(out,"Cannot create djvu document context from djvu file %s.\n",
                infile);
        return(-2);
        }
    i=ddjvu_document_get_pagenum(doc);
    if (pageno<0 || pageno>i)
        {
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Page number %d is out of range for djvu file %s.\n",pageno,infile);
        return(-3);
        }
    page=ddjvu_page_create_by_pageno(doc,pageno-1);
    if (page==NULL)
        {
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Cannot parse page %d of djvu file %s.\n",pageno,infile);
        return(-4);
        }
    while (!ddjvu_page_decoding_done(page))
        handle(1,ctx);
    if (ddjvu_page_decoding_error(page))
        {
        ddjvu_page_release(page);
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Error decoding page %d of djvu file %s.\n",pageno,infile);
        return(-5);
        }
    /* type= */ ddjvu_page_get_type(page);
    /*
    printf("type=%d\n",type);
    description=ddjvu_page_get_long_description(page);
    printf("Description='%s'\n",description);
    */
    iw = ddjvu_page_get_width(page);
    ih = ddjvu_page_get_height(page);
    idpi = ddjvu_page_get_resolution(page);
    prect.x=prect.y=0;
    bmp->width=prect.w=iw*dpi/idpi;
    bmp->height=prect.h=ih*dpi/idpi;
    bmp->bpp=(bpp==8) ? 8 : 24;
    rrect=prect;
    bmp_alloc(bmp);
    if (bmp->bpp==8)
        {
        int ii;
        for (ii=0;ii<256;ii++)
            bmp->red[ii]=bmp->blue[ii]=bmp->green[ii]=ii;
        }
    mode=DDJVU_RENDER_COLOR;
    style=bpp==8 ? DDJVU_FORMAT_GREY8 : DDJVU_FORMAT_RGB24;
    fmt=ddjvu_format_create(style,0,0);
    if (fmt==NULL)
        {
        ddjvu_page_release(page);
        ddjvu_document_release(doc);
        ddjvu_context_release(ctx);
        nprintf(out,"Error setting DJVU format for djvu file %s (page %d).\n",infile,pageno);
        return(-6);
        }
    ddjvu_format_set_row_order(fmt,1);
    status=ddjvu_page_render(page,mode,&prect,&rrect,fmt,bmp_bytewidth(bmp),(char *)bmp->data);
    /* Seems to return 0 for blank/empty page */
    if (!status) 
        bmp_fill(bmp,255,255,255);
    ddjvu_format_release(fmt);
    ddjvu_page_release(page);
    ddjvu_document_release(doc);
    ddjvu_context_release(ctx);
    /*
    if (!status)
        {
        nprintf(out,"Error rendering page %d of djvu file %s.\n",pageno,infile);
        return(-7);
        }
    */
    return(0);
    }
Exemple #30
0
A pString_Connection::readBurst(void)
{
  ipcWarn(wrnlvl(),"%t pString_Connection::readBurst\n");
  MSBuffer bbuff;
  A d,z=(A)0;
  I slen=readFileLength(),slen1,n,s,count;
  if(-1==slen)R(A)0;
  if(0==slen)
  {
    static char fmt[]="\343 IPC warning: pA::ReadBurst: read event with no data [%d]\n";
    Warn(fmt, handle());
  }

  /* create buff to hold it.  Fill buffer */
  slen1=slen?slen:4;
  bbuff.minofbuffer(mab(slen1));
  bbuff.maxofbuffer(bbuff.minofbuffer()+slen1);
  bbuff.reset();
  if(0>(n=readTheBuffer(&bbuff,slen1))) {mfbuffer(&bbuff); R(A)0;}
  if(0==n&&0==slen) {turnInReadOff(); mfbuffer(&bbuff); R(A)0;}

  d=getAobjFromBuffer(&bbuff);
  if((A)0==d){mfbuffer(&bbuff); R(A)0;}

  // determine how many more complete A-objects lie in bbuff
  count=1;
  for(C *cp=bbuff.get();cp<bbuff.put();cp+=s)
  {
    s=longAt(cp);
    cp+=sizeof(long);
    if(s<=bbuff.put()-cp)++count;
  }

  // create result
  z=gv(Et,count);
  for(int i=0;i<count;++i)z->p[i]=(I)aplus_nl;
  int idx=0;
  z->p[idx++]=(I)d;

  // retrieve additional A-objects from bbuff, fill in z
  while(idx<count)
  {
    d=getAobjFromBuffer(&bbuff);
    if((A)0==d)break;
    z->p[idx++]=(I)d;
  }
  if(idx<count)
  {
    ipcWarn(wrnlvl(),"%t burst mode aborted.  Possible data loss.\n");
  }

  // run once more to clear out bbuff and move partial object into connection
  // buffers
  if(bbuff.get()==bbuff.put())turnInReadOff();
  else
  {
    d=getAobjFromBuffer(&bbuff);
    if((A)0!=d || bbuff.get()!=bbuff.put())
    {
      ipcWarn(wrnlvl(),"%t burst buffer not cleared: %d %d %d\n",
	    d,bbuff.get(),bbuff.put());
    }
  }

  // free bbuff;
  mfbuffer(&bbuff);

  return z;     
}