예제 #1
0
파일: serv02m.c 프로젝트: YuanFanBin/learn
int main(int argc, char **argv)
{
    int       listenfd, i;
    socklen_t addrlen;
    void      sig_int(int);
    pid_t     child_make(int, int, int);

    if (argc == 3) {
        listenfd = tcp_listen(NULL, argv[1], &addrlen);
    } else if (argc == 4) {
        listenfd = tcp_listen(argv[1], argv[2], &addrlen);
    } else {
        err_quit("usage: serv02m [ <host> ] <port#> <#children>");
    }
    nchildren = atoi(argv[argc-1]);
    pids = (pid_t *) calloc(nchildren, sizeof(pid_t));
    cptr = meter(nchildren);

    for (i = 0; i < nchildren; i++) {
        pids[i] = child_make(i, listenfd, addrlen); // parent returns
    }
    signal(SIGINT, sig_int);

    for ( ; ; ) {
        pause();    // everything done by children
    }
}
예제 #2
0
void Pilas::on_pushMeter_clicked()
{
    int n = ui->spinMeter->value();
    NodoPila* temp = new NodoPila(n);
    meter(temp);
    imprimir();
}
예제 #3
0
파일: serv02.c 프로젝트: sugite/hplsp
int main(int argc, char *argv[])
{
	int listenfd , i;
	socklen_t addrlen;
	void sig_int(int);
	pid_t child_make(int,int,int);

	if(argc == 3)
		listenfd = Tcp_listen(NULL, argv[1], &addrlen);
	else if(argc == 4)
		listenfd = Tcp_listen(argv[1], argv[2], &addrlen);
	else
		err_quit("usage: serv02 [<host>] <port#> <#children>");

	nchildren = atoi(argv[argc-1]);
	pids = (pid_t*)Calloc(nchildren, sizeof(pid_t));

	
	cptr = meter(nchildren);

	for (i = 0; i < nchildren; ++i)
	{
		/* code */
		pids[i] = child_make(i, listenfd, addrlen);
	}

	Signal(SIGINT, sig_int);
	for(;;)
		pause();
}
예제 #4
0
//---------------------------------------------------------------------------------------
URect HyperlinkCtrl::determine_text_position_and_size()
{
    int align = m_style->text_align();
    URect pos;

    //select_font();    //AWARE: font already selected
    TextMeter meter(m_libraryScope);
    pos.width = meter.measure_width(m_label);
    pos.height = meter.get_font_height();
    pos.y = m_pos.y + (pos.height + m_height) / 2.0f;

    switch (align)
    {
        case ImoTextStyle::k_align_left:
        {
            pos.x = m_pos.x;
            break;
        }
        case ImoTextStyle::k_align_right:
        {
            pos.x = m_pos.x + m_width - pos.width;
            break;
        }
        case ImoTextStyle::k_align_center:
        {
            pos.x = m_pos.x + (m_width - pos.width) / 2.0f;
            break;
        }
    }
    return pos;
}
	int
main(int argc, char **argv)
{
	int			listenfd, i;
	socklen_t	addrlen;
	void		sig_int(int);
	pid_t		child_make(int, int, int);

	if (argc == 3)
		listenfd = Tcp_listen(NULL, argv[1], &addrlen);
	else if (argc == 4)
		listenfd = Tcp_listen(argv[1], argv[2], &addrlen);
	else
		err_quit("usage: ./server_prefork_meter [ <host> ] <port#> <#children>");
	nchildren = atoi(argv[argc-1]);
	pids = calloc(nchildren, sizeof(pid_t));
	cptr = meter(nchildren);
	if(pids == NULL)
	{
		err_sys("calloc");
	}

	for (i = 0; i < nchildren; i++)
		pids[i] = child_make(i, listenfd, addrlen);	/* parent returns */

	if (signal(SIGINT, sig_int) == SIG_ERR)
		perror("signal SIGINT");

	for ( ; ; )
		pause();	/* everything done by children */
}
예제 #6
0
// Bus-gain command method.
bool qtractorBusGainCommand::redo (void)
{
	qtractorBus *pBus = bus();
	if (pBus == NULL)
		return false;

	// Set Bus gain (repective monitor gets set too...)
	const float fGain = m_fPrevGain;

	qtractorMeter *pMeter = meter();
	if (pMeter)
		pMeter->setGain(m_fGain);

	// MIDI buses are special...
	if (pBus->busType() == qtractorTrack::Midi) {
		// Now we gotta make sure of proper MIDI bus...
		qtractorMidiBus *pMidiBus
			= static_cast<qtractorMidiBus *> (pBus);
		if (pMidiBus)
			pMidiBus->setMasterVolume(m_fGain);
	}

	// Set undo value...
	m_fPrevGain = m_fGain;
	m_fGain     = fGain;

	return true;
}
예제 #7
0
int
main(int argc, char **argv)
{
	int			listenfd, i;
	socklen_t	addrlen;
	void		sig_int(int);
	pid_t		child_make(int, int, int);

	if (argc == 3)
		listenfd = Tcp_listen(NULL, argv[1], &addrlen);
	else if (argc == 4)
		listenfd = Tcp_listen(argv[1], argv[2], &addrlen);
	else
		err_quit("usage: serv03 [ <host> ] <port#> <#children>");
	nchildren = atoi(argv[argc-1]);
	pids = Calloc(nchildren, sizeof(pid_t));
	cptr = meter(nchildren);

	my_lock_init("/tmp/lock.XXXXXX");	/* one lock file for all children */
	for (i = 0; i < nchildren; i++)
		pids[i] = child_make(i, listenfd, addrlen);	/* parent returns */

	Signal(SIGINT, sig_int);

	for ( ; ; )
		pause();	/* everything done by children */
}
예제 #8
0
void FontManager::SDL_string_texture_create(QFont &font, QRgb color, QString &text, PGE_Texture *texture, bool borders)
{
    if(!isInit) return;

    int off = (borders ? 4 : 0);
    QPainterPath path;
    QFontMetrics meter(font);
    QImage text_image = QImage(meter.width(text) * 2 + off, (off + meter.height()) * text.split('\n').size(), QImage::Format_ARGB32);
    text_image.fill(Qt::transparent);
    QPainter x(&text_image);
    QFont font_i = font;

    if(borders)
        font_i.setPixelSize(font_i.pixelSize() - 1);

    x.setFont(font_i);
    x.setBrush(QBrush(color));
    x.setPen(QPen(QBrush(color), 1, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));

    if(borders)
    {
        path.addText(off, meter.height() + off, font_i, text);
        x.strokePath(path, QPen(QColor(Qt::black), 2));
        x.fillPath(path, QBrush(color));
    }
    else
        x.drawText(text_image.rect(), text);

    x.end();
    GlRenderer::QImage2Texture(&text_image, *texture);
}
예제 #9
0
void MainLoop::playModel(PModel model, bool withMusic, bool noAutoSave) {
  view->reset();
  const int stepTimeMilli = 3;
  Intervalometer meter(stepTimeMilli);
  double totTime = model->getTime();
  double lastMusicUpdate = -1000;
  double lastAutoSave = model->getTime();
  while (1) {
    double gameTimeStep = view->getGameSpeed() / stepTimeMilli;
    if (auto exitInfo = model->update(totTime)) {
      if (!exitInfo->isAbandoned())
        saveUI(model, exitInfo->getGameType(), View::SAVING);
      eraseAutosave(model.get());
      return;
    }
    if (lastMusicUpdate < totTime - 1 && withMusic) {
      jukebox->setType(model->getCurrentMusic(), model->changeMusicNow());
      lastMusicUpdate = totTime;
    }
    if (model->isTurnBased())
      ++totTime;
    else
      totTime += min(1.0, double(meter.getCount(view->getTimeMilli())) * gameTimeStep);
    if (lastAutoSave < model->getTime() - getAutosaveFreq() && !noAutoSave) {
      if (options->getBoolValue(OptionId::AUTOSAVE))
        saveUI(model, Model::GameType::AUTOSAVE, View::AUTOSAVING);
      lastAutoSave = model->getTime();
    }
  }
}
예제 #10
0
void FontManager::getChar1(QChar _x, int px_size, PGE_Texture &tex)
{
    TTFCharType cht = {_x, px_size};
    PGE_Texture &c = fontTable_1[cht];

    if(c.inited)
        tex = c;
    else
    {
        if(!isInit)
            return;

        if(tex.inited)
            GlRenderer::deleteTexture(tex);

        QImage text_image;
        QFont font_i = *defaultFont;
        font_i.setPixelSize(px_size);
        QFontMetrics meter(font_i);
        text_image = QImage(meter.width(_x), meter.height(), QImage::Format_ARGB32);
        text_image.fill(Qt::transparent);
        QPainter x(&text_image);
        x.setFont(font_i);
        x.setRenderHint(QPainter::Antialiasing, false);
        x.setBrush(QBrush(Qt::white));
        x.setPen(QPen(Qt::white));
        QString s;
        s.append(_x);
        x.drawText(text_image.rect(), s);
        x.end();
        GlRenderer::QImage2Texture(&text_image, c);
        tex = c;
    }
}
예제 #11
0
// Bus-panning command method.
bool qtractorBusPanningCommand::redo (void)
{
	qtractorBus *pBus = bus();
	if (pBus == NULL)
		return false;

	// Set Bus panning (repective monitor gets set too...)
	const float fPanning = m_fPrevPanning;

	qtractorMeter *pMeter = meter();
	if (pMeter)
		pMeter->setPanning(m_fPanning);

	// MIDI buses are special...
	if (pBus->busType() == qtractorTrack::Midi) {
		// Now we gotta make sure of proper MIDI bus...
		qtractorMidiBus *pMidiBus
			= static_cast<qtractorMidiBus *> (pBus);
		if (pMidiBus)
			pMidiBus->setMasterPanning(m_fPanning);
	}

	// Set undo value...
	m_fPrevPanning = m_fPanning;
	m_fPanning     = fPanning;

	return true;
}
예제 #12
0
파일: conjunto-bits.c 프로젝트: leolas95/c
int main(void)
{
	Conjunto A, B, C;

	A = vaciar();
	A = meter(A, 1);
	A = meter(A, 2);
	A = meter(A, 4);
	A = meter(A, 5);

	mostrar(A);

	B = vaciar();
	B = meter(B, 3);
	B = meter(B, 5);
	B = meter(B, 6);
	mostrar(B);

	C = vaciar();
	C = Diferencia(A, B);

	mostrar(C);

	return 0;
}
예제 #13
0
void MainLoop::uploadFile(const string& path) {
  ProgressMeter meter(1);
  atomic<bool> cancelled(false);
  view->displaySplash(meter, View::UPLOADING, [&] { cancelled = true; fileSharing->getCancelFun()();});
  optional<string> error = fileSharing->uploadRetired(path, meter);
  view->clearSplash();
  if (error && !cancelled)
    view->presentText("Error uploading file", *error);
}
예제 #14
0
//---------------------------------------------------------------------------------------
void CheckboxCtrl::select_font()
{
    TextMeter meter(m_libraryScope);
    meter.select_font(m_language,
                      m_style->font_file(),
                      m_style->font_name(),
                      m_style->font_size(),
                      m_style->is_bold(),
                      m_style->is_italic() );
}
예제 #15
0
bool MainLoop::downloadGame(const string& filename) {
  ProgressMeter meter(1);
  atomic<bool> cancelled(false);
  view->displaySplash(meter, View::DOWNLOADING, [&] { cancelled = true; fileSharing->getCancelFun()();});
  optional<string> error = fileSharing->download(filename, userPath, meter);
  view->clearSplash();
  if (error && !cancelled)
    view->presentText("Error downloading file", *error);
  return !error;
}
예제 #16
0
void CMorphwizardView::OnToolsPackMrd() 
{
	CGriIni cIni("Packing...");;
	cIni.Init(this);
	{
		CWizardProgressMeter meter(*GetWizard());
		GetWizard()->pack();
	}
	AfxMessageBox ("Packing is finished!");
}
예제 #17
0
PModel MainLoop::keeperGame() {
  PModel model;
  string ex;
  ProgressMeter meter(1.0 / 166000);
  view->displaySplash(meter, View::CREATING);
  NameGenerator::init(dataFreePath + "/names");
  model = ModelBuilder::collectiveModel(meter, options, view,
      NameGenerator::get(NameGeneratorId::WORLD)->getNext());
  view->clearSplash();
  return model;
}
예제 #18
0
void MainLoop::saveUI(PModel& model, Model::GameType type, View::SplashType splashType) {
  ProgressMeter meter(1.0 / 62500);
  Square::progressMeter = &meter;
  view->displaySplash(meter, splashType);
  string path = getSavePath(model.get(), type);
  MEASURE(saveGame(model, path), "saving time");
  view->clearSplash();
  Square::progressMeter = nullptr;
  if (type == Model::GameType::RETIRED_KEEPER && options->getBoolValue(OptionId::ONLINE))
    uploadFile(path);
}
예제 #19
0
census_run_result run_census_in_series::operator()
    (fs::path           const& file
    ,mcenum_emission    const  emission
    ,std::vector<Input> const& cells
    ,Ledger                  & composite
    )
{
    Timer timer;
    census_run_result result;
    boost::shared_ptr<progress_meter> meter
        (create_progress_meter
            (cells.size()
            ,"Calculating all cells"
            ,progress_meter_mode(emission)
            )
        );

    ledger_emitter emitter(file, emission);
    result.seconds_for_output_ += emitter.initiate();

    for(unsigned int j = 0; j < cells.size(); ++j)
        {
        if(!cell_should_be_ignored(cells[j]))
            {
            std::string const name(cells[j]["InsuredName"].str());
            IllusVal IV(serial_file_path(file, name, j, "hastur").string());
            IV.run(cells[j]);
            composite.PlusEq(*IV.ledger());
            result.seconds_for_output_ += emitter.emit_cell
                (serial_file_path(file, name, j, "hastur")
                ,*IV.ledger()
                );
            meter->dawdle(intermission_between_printouts(emission));
            }
        if(!meter->reflect_progress())
            {
            result.completed_normally_ = false;
            goto done;
            }
        }
    meter->culminate();

    result.seconds_for_output_ += emitter.emit_cell
        (serial_file_path(file, "composite", -1, "hastur")
        ,composite
        );
    result.seconds_for_output_ += emitter.finish();

  done:
    double total_seconds = timer.stop().elapsed_seconds();
    status() << Timer::elapsed_msec_str(total_seconds) << std::flush;
    result.seconds_for_calculations_ = total_seconds - result.seconds_for_output_;
    return result;
}
예제 #20
0
PModel MainLoop::loadModel(string file, bool erase) {
  ProgressMeter meter(1.0 / 62500);
  Square::progressMeter = &meter;
  view->displaySplash(meter, View::LOADING);
  Debug() << "Loading from " << file;
  PModel ret = loadGame(userPath + "/" + file, erase);
  view->clearSplash();
  if (ret) {
    ret->setView(view);
  } else
    view->presentText("Sorry", "This save file is corrupted :(");
  return ret;
}
예제 #21
0
//---------------------------------------------------------------------------------------
URect CheckboxCtrl::determine_text_position_and_size()
{
    URect pos;

    //select_font();    //AWARE: font already selected
    TextMeter meter(m_libraryScope);
    pos.width = meter.measure_width(m_label);
    pos.height = meter.get_font_height();
    pos.y = m_pos.y + (pos.height + m_height) / 2.0f;
    pos.x = m_pos.x;

    return pos;
}
예제 #22
0
//---------------------------------------------------------------------------------------
USize HyperlinkCtrl::measure()
{
    if (m_width < 0.0f || m_height < 0.0f)
    {
        select_font();
        TextMeter meter(m_libraryScope);
        if (m_width < 0.0f)
            m_width = meter.measure_width(m_label);
        if (m_height < 0.0f)
            m_height = meter.get_font_height();
    }
    return USize(m_width, m_height);
}
예제 #23
0
파일: serv02.cpp 프로젝트: eazon/webServer
int main(int argc, char* argv[])
{
    int iListenFd;
    sockaddr_in oBindAddr;
    sockaddr_in oCliAddr;
    socklen_t clilen;

    if (argc < 2)
    {
		printf("usage:Serv00 <port> <children>\n");
		return -1;
    }
    printf("argc =%d\n", argc);
    
    oBindAddr.sin_family = AF_INET;
    oBindAddr.sin_port	 = htons(atoi(argv[1]));
    oBindAddr.sin_addr.s_addr = 0;

    iListenFd = socket(AF_INET, SOCK_STREAM, 0);
    int iRet = bind(iListenFd,(struct sockaddr*) &oBindAddr, sizeof(oBindAddr));
    if (iRet != 0)
    {
		printf("bind error!\n");
		return -1;
    }
    listen(iListenFd, 1024);
   
    clilen = sizeof(oCliAddr);
    iChildren= atoi(argv[2]);
    tChildPid = (pid_t*)malloc( iChildren * sizeof(pid_t));
    cptr = meter(iChildren);

    printf("port=%d, children num=%d\n", oBindAddr.sin_port, iChildren);
    for (int i = 0; i < iChildren; i++)
    {
    	tChildPid[i] = child_make(i, iListenFd, clilen);
    }

    signal(SIGINT, sig_int);
    signal(SIGUSR1, sig_usr1);
    //signal(SIGCHLD, sig_chld);

    for(; ;)
    {
    	pause();
    }
    
}
예제 #24
0
파일: tmeter.cpp 프로젝트: SeeLook/nootka
QPixmap Tmeter::pixmap(int fontSize, const QColor& c) {
    if (meter() == e_none)
        return QPixmap();

    TnooFont font(fontSize);
    QFontMetrics fm(font);
    QString upperDigit = TnooFont::digit(upper());
    QPixmap pix(QSize(fm.boundingRect(upperDigit).width() + 4, fontSize + 12)); // upper digit is usually wider
    pix.fill(Qt::transparent);
    QPainter p(&pix);
    p.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing, true);
    p.setFont(font);
    p.setPen(c == -1 ? qApp->palette().text().color() : c);
    p.setBrush(Qt::NoBrush);
    p.drawText(QRect(0, 0, pix.width(), fontSize / 2 + 8), Qt::AlignCenter, upperDigit);
    p.drawText(QRect(0, fontSize / 2 - 1, pix.width(), fontSize / 2 + 8), Qt::AlignCenter, TnooFont::digit(lower()));
    return pix;
}
예제 #25
0
   void TestWithOneDim()
   {
      /*
      This will be modified to reflect changes later when
      a template map is used.
      */
      Metric::t_meter meter(1.34578f);
	  CPPUNIT_ASSERT_EQUAL( std::string("meter^1"), SOU::WhatAmI(meter) );
      
      Metric::t_second sec(58903.3);
	  CPPUNIT_ASSERT_EQUAL( std::string("second^1"), SOU::WhatAmI(sec) );
      
      Metric::t_velocity vel(81.5);
      CPPUNIT_ASSERT_EQUAL( std::string("meter^1 second^-1"), SOU::WhatAmI(vel) );
      
      Metric::t_gramPsec massFlow(3.895);
      CPPUNIT_ASSERT_EQUAL( std::string("second^-1 gram^1"), SOU::WhatAmI(massFlow) );
      
   }
예제 #26
0
void FontManager::getChar2(QChar _x, int px_size, PGE_Texture &tex)
{
    TTFCharType cht = {_x, px_size};
    PGE_Texture &c = fontTable_2[cht];

    if(c.inited)
        tex = c;
    else
    {
        if(!isInit)
            return;

        if(tex.inited)
            GlRenderer::deleteTexture(tex);

        QImage text_image;
        int off = 4;
        QFont font_i = *defaultFont;
        font_i.setPixelSize(px_size);
        QFontMetrics meter(*defaultFont);
        QPainterPath path;
        text_image = QImage(meter.width(_x) + off, meter.height() + off * 4, QImage::Format_ARGB32);
        text_image.fill(Qt::transparent);
        QPainter x(&text_image);
        x.setFont(font_i);
        x.setRenderHint(QPainter::Antialiasing, false);
        x.setBrush(QBrush(Qt::white));
        x.setPen(QPen(Qt::white));
        path.addText(off, meter.height() + off, font_i, QString(_x));
        x.strokePath(path, QPen(QColor(Qt::black), off));
        x.fillPath(path, QBrush(Qt::white));
        x.end();
        //if(double_pixled)
        //{
        //    //Pixelizing
        //    text_image = text_image.scaled(text_image.width()/2, text_image.height()/2);
        //    text_image = text_image.scaled(text_image.width()*2, text_image.height()*2);
        //}
        GlRenderer::QImage2Texture(&text_image, c);
        //return c.texture;
        tex = c;
    }
}
예제 #27
0
   /// function template is used by TestWithTwoDim()
   /// @see TestWithTwoDim()
	template< int SIZE > void MakeDimTest()
	{
	   namespace AU = Metric::AtomicUnit;
	   typedef SOU::MakeType< AU::Meter, AT::second, AU::gram, AU::kelvin, AU::coulomb > AUMetric;

	   // Length compound units
	   typedef AUMetric::MakeDim< SIZE,0,0,0,0>::type t_meter; //< Meter type
	   t_meter meter(4.2);

      // Produce the string a different way to test it.
	   std::stringstream stream;
	   stream << "meter^";
      stream << SIZE;
      //stream << " "; // << std::endl;
      std::string str = stream.str();

	   CPPUNIT_ASSERT_EQUAL( str, SOU::WhatAmI(meter) );

	}
OptionalModelObject ReverseTranslator::translateOutputMeterMeterFileOnly( const WorkspaceObject & workspaceObject )
{
  openstudio::model::Meter meter( m_model );

  OptionalString s = workspaceObject.getString(Output_Meter_MeterFileOnlyFields::Name);
  if(s){
    meter.setName(*s);
  }

  s = workspaceObject.getString(Output_Meter_MeterFileOnlyFields::ReportingFrequency);
  if(s){
    meter.setReportingFrequency(*s);
  }

  meter.setMeterFileOnly(true);

  meter.setCumulative(false);

  return meter;
}
예제 #29
0
BOOL CMorphwizardDoc::DoFileSave()
{
	if (GetWizard()->m_ReadOnly)
	{
		AfxMessageBox ("Wizard is readonly, cannot be saved");
		return TRUE;
	};
	
	CWaitCursor wait;
	try
	{
		CWizardProgressMeter meter(m_Wizard);
		GetWizard()->save_mrd();
	}
	catch(CExpc e)
	{
		AfxMessageBox(e.m_strCause.c_str());
		return FALSE;
	}
	return TRUE;
}
예제 #30
0
void FontManager::SDL_string_texture_create(QFont &font, PGE_Rect limitRect, int fontFlags, QRgb color, QString &text, PGE_Texture *texture, bool borders)
{
    if(!isInit) return;

    QImage text_image;
    int off = (borders ? 4 : 0);
    QPainterPath path;
    text_image = QImage(QSize(limitRect.width(), limitRect.height()), QImage::Format_ARGB32);
    text_image.fill(Qt::transparent);
    QFont font_i = font;

    if(borders)
        font_i.setPixelSize(font_i.pixelSize() - 1);

    QFontMetrics meter(font_i);
    QPainter x(&text_image);
    x.setFont(font_i);
    x.setBrush(QBrush(color));
    x.setPen(QPen(color));

    if(borders)
    {
        path.addText(off, meter.height() + off * 2, font_i, text);
        x.strokePath(path, QPen(QColor(Qt::black), off));
        x.fillPath(path, QBrush(color));
    }
    else
        x.drawText(text_image.rect(), fontFlags, text);

    x.end();

    if(double_pixled)
    {
        //Pixelizing
        text_image = text_image.scaled(text_image.width() / 2, text_image.height() / 2);
        text_image = text_image.scaled(text_image.width() * 2, text_image.height() * 2);
    }

    GlRenderer::QImage2Texture(&text_image, *texture);
}