Exemplo n.º 1
0
void OptionsTabApplication::restoreOptions()
{
	if ( !w )
		return;

	OptApplicationUI *d = (OptApplicationUI *)w;

	d->ck_autoUpdate->setChecked(PsiOptions::instance()->getOption("options.auto-update.check-on-startup").toBool());
	d->ck_quitOnClose->setChecked(PsiOptions::instance()->getOption("options.ui.contactlist.quit-on-close").toBool());

	// docklet
	d->ck_docklet->setChecked( PsiOptions::instance()->getOption("options.ui.systemtray.enable").toBool() );
	d->ck_dockDCstyle->setChecked( PsiOptions::instance()->getOption("options.ui.systemtray.use-double-click").toBool() );
	d->ck_dockHideMW->setChecked( PsiOptions::instance()->getOption("options.contactlist.hide-on-start").toBool() );
	d->ck_dockToolMW->setChecked( PsiOptions::instance()->getOption("options.contactlist.use-toolwindow").toBool() );
	doEnableQuitOnClose(d->ck_docklet->isChecked()?1:0);

	// data transfer
	d->le_dtPort->setText( QString::number(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt()) );
	d->le_dtExternal->setText( PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString() );

	// Language
	VarList vList = TranslationManager::instance()->availableTranslations();
	QStringList lang = vList.varsToStringList();
	d->cb_lang->addItem(tr("Default"));
	foreach(QString item, lang) {
		d->cb_lang->addItem(vList.get(item));
	}
Exemplo n.º 2
0
InstFakeKill::InstFakeKill(Cfg *Func, const VarList &KilledRegs,
                           const Inst *Linked)
    : Inst(Func, Inst::FakeKill, KilledRegs.size(), NULL), Linked(Linked) {
  for (VarList::const_iterator I = KilledRegs.begin(), E = KilledRegs.end();
       I != E; ++I) {
    Variable *Var = *I;
    addSource(Var);
  }
}
Exemplo n.º 3
0
void renderDofAmountTest()
{
    Options opts;
    opts.xRes = 320;
    opts.yRes = 240;
    opts.gridSize = 8;
    opts.clipNear = 0.1;
    opts.superSamp = Imath::V2i(10,10);
    opts.pixelFilter = makeGaussianFilter(Vec2(2.0,2.0));
    opts.fstop = 100;
    opts.focalLength = 20;
    opts.focalDistance = 3;

    Attributes attrs;
    attrs.shadingRate = 1;
    attrs.smoothShading = true;

    Mat4 camToScreen =
        perspectiveProjection(90, opts.clipNear, opts.clipFar) *
        screenWindow(-2.33333, 0.33333, -1, 1);

    // Output variables.
    VarList outVars;
    outVars.push_back(Stdvar::Cs);

    Renderer r(opts, camToScreen, outVars);

    Mat4 wToO = Mat4().setTranslation(Vec3(-0.5,-0.5,-1)) *
                Mat4().setAxisAngle(Vec3(0,0,1), deg2rad(45)) *
                Mat4().setTranslation(Vec3(-1.5, 0, 2));

    const float P[12] = {0, 0, 0,  1, 0, 0,  0, 1, 0,  1, 1, 0};
    {
        const float Cs[3] = {1, 0.7, 0.7};
        r.add(createPatch(P, Cs, wToO), attrs);
    }
    {
        const float Cs[3] = {0.7, 1, 0.7};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,1))*wToO), attrs);
    }
    {
        const float Cs[3] = {0.7, 0.7, 1};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,2))*wToO), attrs);
    }
    {
        const float Cs[3] = {1, 0.7, 0.7};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,5))*wToO), attrs);
    }
    {
        const float Cs[3] = {0.7, 1, 0.7};
        r.add(createPatch(P, Cs, Mat4().setTranslation(Vec3(0,0,25))*wToO), attrs);
    }

    r.render();
}
Exemplo n.º 4
0
void DataRewriter::organizeNewBss(Region* reg, unsigned char magic) {
   /**
    *
    */

   fprintf(stderr, "BSS region starts at %p\n", reg->getRegionAddr());

   VarList globals = filterVariables(reg);

   unsigned int dataSize = 0;
   unsigned int dataBase = 0;
   unsigned int dataOffset = 0;

   unsigned int rawIndex = 0;
   unsigned int rawValue = 0;

   unsigned int newRawIndex = 0;

   dataSize = reg->getRegionSize();
   dataBase = newDataBase + newDataSize;

   fprintf(stderr, "BSS base = %p\n", (void*) dataBase);

   unsigned int newBssSize = sizeof(unsigned char) * dataSize;

   oldRawBss = (unsigned char*) reg->getPtrToRawData();
   newRawBss = (unsigned char*) malloc (newBssSize);

   memcpy(newRawBss, oldRawBss, dataSize);


   for (int i = 0; i < globals.size(); i++) {
      dataOffset = globals[i]->getOffset();
      rawIndex = dataOffset - dataBase;
      // Update the relocated address mapping
      newLocs[dataOffset] = dataBase + newRawIndex;
      newRawIndex += globals[i]->getSize();
   }

   for (AddrMapping::const_iterator iter = newLocs.begin();
         iter != newLocs.end();
         ++iter) {
      fprintf(stderr, "%p -> %p\n", iter->first, iter->second);
   }

   // Causes a segfault in the mutated binary
   // 
   //if (!reg->setPtrToRawData(newRawBss, newDataSize)) {
   //   fprintf(stderr, "Unable to assign new data section.\n");
   //   exit(EXIT_FAILURE);
   //}

}
Exemplo n.º 5
0
    const Var* var( const size_t index ) const
    {
        VarList::const_iterator var = m_vars.begin();
        VarList::const_iterator last = m_vars.end();
        size_t counter = 0;
        while ( var != last )
        {
            if ( counter++ == index ) break;
            var++;
        }

        return( *var );
    }
Exemplo n.º 6
0
    const Var* var( const std::string name ) const
    {
        VarList::const_iterator var = m_vars.begin();
        VarList::const_iterator last = m_vars.end();
        while ( var != last )
        {
            if ( (*var)->name() == name ) break;

            var++;
        }

        return( *var );
    }
Exemplo n.º 7
0
void DataRewriter::organizeNewData(Region* reg, unsigned char magic) {
   /**
    *
    */
   VarList globals = filterVariables(reg);

   unsigned int dataSize = 0;
   unsigned int dataBase = 0;
   unsigned int dataOffset = 0;

   unsigned int rawIndex = 0;
   unsigned int rawValue = 0;

   unsigned int newRawIndex = 0;

   dataSize = reg->getRegionSize();
   dataBase = reg->getRegionAddr();

   newDataBase = dataBase;
   newDataSize = sizeof(unsigned char) * dataSize * 2;

   oldRaw = (unsigned char*) reg->getPtrToRawData();
   newRaw = (unsigned char*) malloc (newDataSize);

   // The dso_handle bullshit
   memcpy(newRaw, oldRaw, 4);
   memset(newRaw + 4, magic, 4);
   newRawIndex += 8;

   // Pad the new data section with an extra 4 bytes between all 4 byte values.
   for (int i = 0; i < globals.size(); i++) {
      dataOffset = globals[i]->getOffset();
      rawIndex = dataOffset - dataBase;
      memcpy(newRaw + newRawIndex, oldRaw + rawIndex, 4);
      // Sanity checks, write magic values into padding
      memset(newRaw + newRawIndex + 4, magic, 4);
      // Update the relocated address mapping
      newLocs[dataOffset] = dataBase + newRawIndex;
      newRawIndex += 8;
   }

   fprintf(stderr, "NEW DATA: %p through %p\n", newDataBase, newDataBase + newDataSize);

   if (!reg->setPtrToRawData(newRaw, newDataSize)) {
      fprintf(stderr, "Unable to assign new data section.\n");
      exit(EXIT_FAILURE);
   }

}
Exemplo n.º 8
0
void ParseBool(char *buffer)
{
string VarName="";
// skip boool 
int i=5;
while(buffer[i]!= '=')
	VarName+=buffer[i++];
// add to the global list
GlobalVar v(VarName,GlobalIndex,line);
GlobalList.push_back(v);
CheckForDuplicateVarNames();
GlobalIndex++;
// now get the variable value up to the ; token
// skip = sign
i++;
VarName="";
while(buffer[i]!= ';')
	VarName+=buffer[i++];
bool vf;
if(VarName == "true")
	vf=true;
else if(VarName == "false")
	vf=false;
else
	{
	cout <<"***************ERROR IN COMPILATION**********************"<<endl;
	cout <<" Error in compilation line :"<<line<<endl;
	cout <<" bool data type must be initialised as either true or false "<<endl;
	cout << "****************** COMPILATION FAILED EXITING ***********"<<endl;
	exit(0);
	}
VarObj Vo(vf);
Globals.Add(Vo);
}
Exemplo n.º 9
0
void CameraParameters::AdditionalCalibrationInformation::addSettingsToList(
    VarList& list) {
  for (int i = 0; i < kNumControlPoints; ++i) {
    list.addChild(control_point_set[i]);
  }

  list.addChild(initial_distortion);
  list.addChild(camera_height);
  list.addChild(line_search_corridor_width);
  list.addChild(image_boundary);
  list.addChild(max_feature_distance);
  list.addChild(convergence_timeout);
  list.addChild(cov_corner_x);
  list.addChild(cov_corner_y);
  list.addChild(cov_ls_x);
  list.addChild(cov_ls_y);
  list.addChild(pointSeparation);
}
Exemplo n.º 10
0
void test_varlist()
{
	VarList args;	
	args.add(1);
	args.add("ddddd");
	args.add(true);
	printf("args count: %d\n", args.count());
	printf("args 0: %d\n", args.get(0).toInt());
	printf("args 1: %s\n", args.get(1).toString());
	printf("args 2: %s\n", args.get(2).toBool() ? "true" : "false");
}
Exemplo n.º 11
0
Variable FunctionCheckInit::call( Variable &input, VarList lParams ) {
	VarList::const_iterator i = lParams.begin();
	
	// Fetch values
	Bu::String what = (*i).getString();
	
	// Lets check stuff!
	pContext->getView()->checkBegin(what);
	
	return new Variable(Variable::typeNone);
}
Exemplo n.º 12
0
Variable FunctionTargets::call( Variable &/*input*/, VarList lParams )
{
    Variable vRet( Variable::typeList );
    TargetList lTrg;
    if( lParams.getSize() == 0 )
    {
        lTrg = pContext->getExplicitTargets();
    }
    else
    {
        lTrg = pContext->getTag( lParams.first().toString() );
    }
    for( TargetList::const_iterator i = lTrg.begin(); i; i++ )
    {
        for( StrList::const_iterator j = (*i)->getOutputList().begin(); j; j++ )
        {
            vRet.append( *j );
        }
    }
    return vRet;
}
Exemplo n.º 13
0
	//------------------------------------------------------------------------
	wstring StringParser::GetString( const string& key, const VarList& args, bool returnKeyIfFailed/*=true*/ )
	{
		StringParser::StringItem* item = m_StringItems.GetStringItemById( key );
		if( item == 0 )
		{
			_LogError( string("StringParser::GetString Error : ") + key + " ²»´æÔÚ" );
			if( returnKeyIfFailed )
				return We::Type::ToWstring( key );
			return L"";
		}
		if( item->m_Texts.size() != args.Size() + 1 )
		{
			_LogError( string("StringParser::GetString Error : ") + key + " ²ÎÊý¸öÊý²»Æ¥Åä" );
			if( returnKeyIfFailed )
				return We::Type::ToWstring( key );
			return L"";
		}
		wstring ret = item->m_Texts[0];
		for( int i=0; i<args.Size(); ++i )
			ret += args.GetValue( item->m_Indexes[i]-1 ).ForceToWstring() + item->m_Texts[i+1];
		return ret;
	}
Exemplo n.º 14
0
    ~File( void )
    {
        if ( m_file ) delete m_file;

        DimList::iterator dim = m_dims.begin();
        DimList::const_iterator last_dim = m_dims.end();
        while ( dim != last_dim )
        {
            if ( *dim ) delete *dim;
            dim++;
        }
        m_dims.clear();

        VarList::iterator var = m_vars.begin();
        VarList::const_iterator last_var = m_vars.end();
        while ( var != last_var )
        {
            if ( *var ) delete *var;
            var++;
        }
        m_vars.clear();
    }
Exemplo n.º 15
0
void CameraParameters::addSettingsToList(VarList& list) {
  list.addChild(focal_length);
  list.addChild(principal_point_x);
  list.addChild(principal_point_y);
  list.addChild(distortion);
  list.addChild(q0);
  list.addChild(q1);
  list.addChild(q2);
  list.addChild(q3);
  list.addChild(tx);
  list.addChild(ty);
  list.addChild(tz);
}
Exemplo n.º 16
0
void ParseVector(char *buffer)
{
string VarName="";
char val[BUFFSIZE];
//Vector vf;
// skip Vector
int i=7;
int s=0;
while(buffer[i]!= '=')
	VarName+=buffer[i++];
//VarName[s]='\0';
// add to the global list
GlobalVar v(VarName,GlobalIndex,line);
GlobalList.push_back(v);
CheckForDuplicateVarNames();
GlobalIndex++;
// skip over [
i+=2;
float x,y,z,w;
s=0;
while(buffer[i]!= ',')
	val[s++]=buffer[i++];
val[s]='\0';
x=atof(val);

i++; s=0;
while(buffer[i]!= ',')
	val[s++]=buffer[i++];
val[s]='\0';
y=atof(val);

i++; s=0;
while(buffer[i]!= ',')
	val[s++]=buffer[i++];
val[s]='\0';
z=atof(val);
i++; s=0;
while(buffer[i]!= ']')
	val[s++]=buffer[i++];
val[s]='\0';
w=atof(val);
Vec4 vf(x,y,z,w);
VarObj Vo(vf);
Globals.Add(Vo);
//cout <<"Buffer "<<buffer <<" ";
//cout <<"X "<<x<<" Y "<<y <<" z "<<z<<endl;
}
Exemplo n.º 17
0
void ParsePoint(char *buffer)
{
string VarName="";
char val[30];
Vec3 vf;
// skip Vector
int i=6;
int s=0;
while(buffer[i]!= '=')
	VarName+=buffer[i++];
// add to the global list
GlobalVar v(VarName,GlobalIndex,line);
GlobalList.push_back(v);
CheckForDuplicateVarNames();
GlobalIndex++;
// skip over [
i+=2;
float x,y,z;
s=0;
while(buffer[i]!= ',')
	val[s++]=buffer[i++];
val[s]='\0';
x=atof(val);

i++; s=0;
while(buffer[i]!= ',')
	val[s++]=buffer[i++];
val[s]='\0';
y=atof(val);

i++; s=0;
while(buffer[i]!= ']')
	val[s++]=buffer[i++];
val[s]='\0';
z=atof(val);
vf.set(x,y,z);
VarObj Vo(vf);
Globals.Add(Vo);
}
Exemplo n.º 18
0
    const bool read( const std::string filename )
    {
        if ( m_file ) delete m_file;

        m_filename = filename;
        m_file = new NcFile( filename.c_str(), NcFile::ReadOnly );
        if ( !m_file ) return( false );
        if ( !m_file->is_valid() ) return( false );

        const int ndims = m_file->num_dims();
        for ( int i = 0; i < ndims; i++ )
        {
            m_dims.push_back( new Dim( m_file->get_dim(i) ) );
        }

        const int nvars = m_file->num_vars();
        for ( int i = 0; i < nvars; i++ )
        {
            m_vars.push_back( new Var( m_file->get_var(i) ) );
        }

        return( true );
    }
Exemplo n.º 19
0
void ParseFuzzy(char *buffer)
{
string VarName="";
char val[30];
fuzzy vf;
// skip float 
int i=6;
int s=0;
while(buffer[i]!= '=')
	VarName+=buffer[i++];
// add to the global list
GlobalVar v(VarName,GlobalIndex,line);
GlobalList.push_back(v);
CheckForDuplicateVarNames();
GlobalIndex++;
// now get the variable value up to the ; token
// skip = sign
i++;
while(buffer[i]!= ';')
	val[s++]=buffer[i++];
vf=atof(val);
VarObj Vo(vf);
Globals.Add(Vo);
}
Exemplo n.º 20
0
 const size_t nvars( void ) const
 {
     return( m_vars.size() );
 }
Exemplo n.º 21
0
void ScriptEngine::callEvent( const char *name, const VarList &args, VarList &result )
{
    FUNCTION_MAP::iterator it = m_functionMap.find(name);
    if (it != m_functionMap.end())
    {
        LUA_FUNCTION nHandler = it->second;

        LuaHelper::getRefFunction(m_luaState, nHandler);
        if (lua_isfunction(m_luaState, -1))
        {
            size_t count = args.count();
            for (size_t i=0; i<count; ++i)
            {
                int type = args.get(i).getType();
                switch (type)
                {
                case Var::BOOL:
                    lua_pushboolean(m_luaState, args.get(i).toBool() ? 1 : 0);
                    break;
                case Var::BYTE:
                case Var::SHORT:
                case Var::INT:
                case Var::INT64:
                case Var::FLOAT:
                case Var::NUMBER:
                    lua_pushnumber(m_luaState, args.get(i).toNumber());
                    break;
                case Var::STRING:
                    lua_pushstring(m_luaState, args.get(i).toString());
                    break;
                default:
                    break;
                }
            }
            int error = lua_pcall(m_luaState, args.count(), 1, NULL);
            if (error)
            {
                printf("[LUA ERROR] %s\n", lua_tostring(m_luaState, - 1));
                lua_pop(m_luaState, 1); // remove error message from stack
            }
            else
            {
                // get return value
                if (lua_isnumber(m_luaState, -1))
                {
                    int ret = lua_tointeger(m_luaState, -1);
                    result.add(ret);
                }
                else if (lua_isboolean(m_luaState, -1))
                {
                    int ret = lua_toboolean(m_luaState, -1);
                    result.add(ret);
                }
                else if (lua_isstring(m_luaState, -1))
                {
                    const char *ret = lua_tostring(m_luaState, -1);
                    result.add(ret);
                }

                // remove return value from stack
                lua_pop(m_luaState, 1);
            }
        }

    }
}
Exemplo n.º 22
0
MainWindow::MainWindow(bool start_capture, bool enforce_affinity)
{

  affinity=0;
  if (enforce_affinity) affinity=new AffinityManager();
  //opt=new GetOpt();
  settings=0;
  setupUi((QMainWindow *)this);

  tree_view=new VarTreeView();
  tmodel=new VarTreeModel();

  splitter = new QSplitter(Qt::Horizontal,this);
  splitter2 = new QSplitter(Qt::Vertical);

  root=new VarList("Vision System");

  opts=new RenderOptions();
  right_tab=0;

  QString stack_id="";

  //opt->addArgument("stack",&stack_id);
  //opt->parse();

  //load RoboCup SSL stack by default:
  multi_stack=new MultiStackRoboCupSSL(opts, 2);

  VarExternal * stackvar;
  root->addChild(stackvar= new VarExternal((multi_stack->getSettingsFileName() + ".xml").c_str(),multi_stack->getName()));
  stackvar->addChild(multi_stack->getSettings());
  //create tabs, GL visualizations and tool-panes for each capture thread in the multi-stack:
  for (unsigned int i=0;i<multi_stack->threads.size();i++) {
    VisionStack * s = multi_stack->threads[i]->getStack();
    if (affinity!=0) multi_stack->threads[i]->setAffinityManager(affinity);

    GLWidget * gl=new GLWidget(0,false);
    gl->setRingBuffer(multi_stack->threads[i]->getFrameBuffer());
    gl->setVisionStack(s);
    QString label = "Camera " + QString::number(i);

    VarList * threadvar = new VarList(label.toStdString());

    threadvar->addChild(s->getSettings());
    //iterate through plugin variables

    QSplitter * stack_widget = new QSplitter(Qt::Horizontal);
    stack_widgets.push_back(stack_widget);
    QSplitter * stack_vis_splitter = new QSplitter(Qt::Vertical);
    stack_widget->addWidget(stack_vis_splitter);
    QTabWidget * stack_control_tab = new QTabWidget();
    stack_control_tab->setTabPosition(QTabWidget::East);
    stack_widget->addWidget(stack_control_tab);

    VideoWidget * w=new VideoWidget(label,gl);
    display_widgets.push_back(gl);
    threadvar->addChild(multi_stack->threads[i]->getSettings());

    stack_vis_splitter->addWidget(w);
    //iterate through all plugins
    unsigned int n=s->stack.size();
    for (unsigned int j=0;j<n;j++) {
      VisionPlugin * p=s->stack[j];
      if (p->isSharedAmongStacks()) {
        if (i==0) {
          //this is a shared global plugin...
          //add it to global pane
          if (p->getSettings()!=0) stackvar->addChild(p->getSettings());

          QWidget * tmp_control = p->getControlWidget();
          if (tmp_control!=0) {
            if (right_tab==0) {
              right_tab=new QTabWidget();
              right_tab->setTabPosition(QTabWidget::East);
            }
            right_tab->addTab(tmp_control,QString::fromStdString(p->getName()));
          }
        
          QWidget * tmp_vis = p->getVisualizationWidget();
          if (tmp_vis!=0) splitter2->addWidget(tmp_vis);
        }
      
      } else {
        if (p->getSettings()!=0) threadvar->addChild(p->getSettings());
        //this is a local plugin relating only to a single thread
        //add it to the context.
        QWidget * tmp_control = p->getControlWidget();
        if (tmp_control!=0) stack_control_tab->addTab(tmp_control,QString::fromStdString(p->getName()));
      
        QWidget * tmp_vis = p->getVisualizationWidget();
        if (tmp_vis!=0) stack_vis_splitter->addWidget(tmp_vis);
      }
    }
    stackvar->addChild(threadvar);

    splitter2->addWidget(stack_widget);
  }
  
  if (affinity!=0) affinity->demandCore(multi_stack->threads.size());

  // Set position and size of main window:
  QSettings window_settings("RoboCup", "ssl-vision");
  window_settings.beginGroup("MainWindow");
  QPoint pos = window_settings.value("pos", QPoint(100, 100)).toPoint();
  QSize size = window_settings.value("size", QSize(800, 600)).toSize();
  window_settings.endGroup();
  resize(size);
  move(pos);

  //FINISHED STRUCTURAL TREE
  //NOW LOAD DATA:

  world.push_back(root); 
  world=VarXML::read( world,"settings.xml");

  //update network output settings from xml file
  ((MultiStackRoboCupSSL*)multi_stack)->RefreshNetworkOutput();
  multi_stack->start();

  if (start_capture==true) {
    for (unsigned int i = 0; i < multi_stack->threads.size(); i++) {
      CaptureThread * ct = multi_stack->threads[i];
      ct->init();
    }
  }

  tree_view->setModel(tmodel);
  tmodel->setRootItems(world);
  tree_view->expandAndFocus(stackvar);
  tree_view->fitColumns();

  left_tab=new QTabWidget();
  left_tab->setTabPosition(QTabWidget::West);

  splitter->addWidget(left_tab);
  splitter->addWidget(splitter2);
  if (right_tab!=0) splitter->addWidget(right_tab);

  left_tab->addTab(tree_view,"Data-Tree");

  setCentralWidget(splitter); //was splitter

  startTimer(10);

}
Exemplo n.º 23
0
void NetSystem::CompleteRecv(epoll_event& event) {
    LinkInfo * pLink = (LinkInfo *) event.data.ptr;
    //如果是已经连接的用户,并且收到数据,那么进行读入。
    char recvbuff[RECVBUF_SIZE];
    memset(recvbuff, 0, RECVBUF_SIZE);
    int nRecvLen = 0;
    //在这里会不会出现因为tpc接受缓冲区一直有东西存在 所以就直卡死在这个read中 所以改成read一次
    //但是有可能出现消息丢失
    while (true) { //这里注意 要增加 频率检测
        if ((nRecvLen = read(pLink->m_socket, recvbuff, RECVBUF_SIZE)) <= 0) {
            if (EAGAIN == errno && -1 == nRecvLen) {
                break;
            }

            if (0 == nRecvLen) {
                LOG_ERROR("NetSystem::MainLoop client is EOF, LinkID : %d", pLink->m_socket);
                m_pCallBackSystem->ExKernelEvent(m_pKernel,
                        pLink->m_remotetype, KERNEL_EVENT_CONNECTION_EOF, pLink->m_socket, VarList());
            } else {
                LOG_ERROR("NetSystem::MainLoop client is break off, LinkID : %d", pLink->m_socket);
                m_pCallBackSystem->ExKernelEvent(m_pKernel,
                        pLink->m_remotetype, KERNEL_EVENT_CONNECTION_BREAK, pLink->m_socket, VarList());
            }

            CleanLink(pLink);
            event.data.ptr = NULL;
            break;
        }

        if (!pLink->m_recvstream.WriteBuff(recvbuff, nRecvLen)) {
            LOG_TRACE("NetSystem::MainLoop WriteBuff error, LinkID : %d", pLink->m_socket);
            m_pCallBackSystem->ExKernelEvent(m_pKernel,
                    pLink->m_remotetype, KERNEL_EVENT_CONNECTION_BREAK, pLink->m_socket, VarList());
            CleanLink(pLink);
            event.data.ptr = NULL;
            break;
        }

        Archive msg;
        VarList args;
        while (pLink->m_recvstream.ReadArchive(msg)) {
            if (msg.ToVarList(args)) {
                if (args.Type(0) != TYPE_INT) {
                    LOG_ERROR("NetSystem::MainLoop Error msg");
                    m_pCallBackSystem->ExKernelEvent(m_pKernel,
                            pLink->m_remotetype, KERNEL_EVENT_CONNECTION_BREAK, pLink->m_socket, VarList());
                    CleanLink(pLink);
                    event.data.ptr = NULL;
                    break;
                }

                UI32 nMsgId = args.GetInt(0);
                m_pCallBackSystem->ExMsgCall(m_pKernel, pLink->m_remotetype, nMsgId, pLink->m_socket, args);

                const CIdentity player = m_pObjectManage->QueryPlayer(pLink->m_socket);
                if (player != CIdentity_INIT()) {
                    m_pCallBackSystem->ExMsgCall(m_pKernel, pLink->m_remotetype, nMsgId, player, args);
                }
            }
        }
    }

    if (pLink != NULL) {
        //设置用于写操作的文件描述符
        struct epoll_event ev;
        ev.data.ptr = pLink;
        ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
        epoll_ctl(m_epfd, EPOLL_CTL_MOD, pLink->m_socket, &ev);
    }

    return;
}
Exemplo n.º 24
0
bool NetSystem::Initialize() {
    if (NULL == (m_pKernel = Kernel::Employ()) ||
            NULL == (m_pCallBackSystem = CallBackSystem::Employ()) ||
            NULL == (m_pConfigManage = ConfigManage::Employ()) ||
            NULL == (m_pObjectManage = ObjectManage::Employ()) ||
            NULL == (m_pHeartBeatManage = HeartBeatManage::Employ()) ||
            NULL == (m_pLogSystem = LogSystem::Employ())) {
        LOG_ERROR("NetSystem initialize failed");
        Assert(false);
        return false;
    }

    m_alive = true;
    const CIniConfig * globlaconfig = m_pConfigManage->GetConfig(KERNEL_CONFIG_GLOBLA_INI);
    if (NULL == globlaconfig) {
        LOG_ERROR("Get GloblaConfig Failed");
        Assert(false);
        return false;
    }

    const char * pStrServerTypes = globlaconfig->GetStringConfig("Global", "ServerTypes");
    if ("" == string(pStrServerTypes)) {
        LOG_ERROR("Get ServerTypes Failed");
        Assert(false);
        return false;
    }

    VarList types;
    SafeSplitString(pStrServerTypes, ";", types);
    UI32 nCount = types.Count();
    if (0 >= nCount) {
        LOG_ERROR("Count Of ServerTypes : 0");
        Assert(0);
        return false;
    }

    for (UI32 i = 0; i < nCount; i++) {
        m_linkmanage.AddLinkType(types.GetString(i));
    }

    const CIniConfig * baseconfig = m_pConfigManage->GetConfig(KERNEL_CONFIG_BASE_INI);
    if (NULL == baseconfig) {
        LOG_ERROR("Get BaseConfig failed ");
        Assert(false);
        return false;
    }

    const char * pstartlisten = baseconfig->GetStringConfig("Base", "Listen");
    if (pstartlisten != NULL && strlen(pstartlisten) != 0) {
        VarList lslist;
        SafeSplitString(pstartlisten, ";", lslist);
        nCount = lslist.Count();
        for (UI32 i = 0; i < nCount; i++) {
            VarList listeninfo;
            SafeSplitString(lslist.GetString(i), ",", listeninfo);
            if (listeninfo.Count() != 3) {
                LOG_ERROR("Check the format of you listen config : %s", lslist.GetString(i));
                Assert(false);
                return false;
            }

            Listen(listeninfo.GetString(0), listeninfo.GetString(1), StringAsInt(listeninfo.GetString(2)), LISTEN_GAME_SOCKET);
        }
    }

    const char * pstartconnects = baseconfig->GetStringConfig("Base", "Connect");
    if (pstartconnects != NULL && strlen(pstartconnects) != 0) {
        VarList connects;
        SafeSplitString(pstartconnects, ";", connects);
        nCount = connects.Count();
        for (UI32 i = 0; i < nCount; i++) {
            VarList connectinfo;
            SafeSplitString(connects.GetString(i), ",", connectinfo);
            if (connectinfo.Count() != 3) {
                LOG_ERROR("Check the format of you connect config : %s", connects.GetString(i));
                Assert(false);
                return false;
            }

            Connect(connectinfo.GetString(0), connectinfo.GetString(1), StringAsInt(connectinfo.GetString(2)));
        }
    }

    const char * pConsolelisten = baseconfig->GetStringConfig("Base", "Console");
    if (pConsolelisten != NULL && strlen(pConsolelisten) != 0) {
        VarList csllist;
        SafeSplitString(pConsolelisten, ";", csllist);
        nCount = csllist.Count();
        for (UI32 i = 0; i < nCount; i++) {
            VarList listeninfo;
            SafeSplitString(csllist.GetString(i), ",", listeninfo);
            if (listeninfo.Count() != 3) {
                LOG_ERROR("Check the format of you listen config : %s", csllist.GetString(i));
                Assert(false);
                return false;
            }

            Listen(listeninfo.GetString(0), listeninfo.GetString(1), StringAsInt(listeninfo.GetString(2)), LISTEN_CONSOLE_SOCKET);
        }
    }

    return true;
}
Exemplo n.º 25
0
/**
 * Convenience function for conditioning one iterator on the current
 * value of another. This equalivalent to the following code
 * <pre>
 * DomainIterator it1(...), it2(...);
 * DomainIterator::VarList vars = it1.getVars();
 * DomainIterator::IndList inds = it1.getSubInd();
 * it2.condition(vars.begin(),vars.end(),inds.begin(), inds.end());
 * </pre>
 * @see DomainIterator::condition(const VarIt,const VarIt,const IndIt,const IndIt)
 */
void DomainIterator::condition(const DomainIterator& it)
{
   VarList vars = it.getVars();
   IndList inds = it.getSubInd();
   condition(vars.begin(),vars.end(),inds.begin(), inds.end());
}