Esempio n. 1
0
  static void test_common()
  {
    log::asio_logger lgr;
    log::logger_t lg = boost::bind(&gce::log::asio_logger::output, &lgr, _arg1, "");
    try
    {
      std::size_t echo_num = 100;

      attributes attrs;
      attrs.lg_ = lg;
      attrs.id_ = atom("two");
      context ctx2(attrs);
      threaded_actor base2 = spawn(ctx2);

      svcid_t guidsys = make_svcid("cachesys", "cachesys");

      connect(base2, "cachesys", "tcp://127.0.0.1:20001");
      base2.sleep_for(millisecs(100));

      for(int i = 0; i < test_count; i++)
      {
          p::xs2ds_entity_req req;
          req.req_guid = 1;
          base2->send(guidsys, XS2DS_ENTITY_REQ, req);
          p::ds2xs_entity_ack ack;
          base2->match(DS2XS_ENTITY_ACK).recv(ack);
          //std::cout << "received, index: " << ack.data << std::endl;
          GCE_INFO(lg) << i << " "<< ack.data << "\n";
      }
    }
    catch (std::exception& ex)
    {
      std::cerr << ex.what() << std::endl;
    }
  }
Esempio n. 2
0
DragNDropResponse::DragNDropResponse(JsonClient *client, const QtJson::JsonObject &command) :
    DelayedResponse(client, command)
{
    WidgetLocatorContext<QWidget> ctx(static_cast<Player *>(jsonClient()), command, "srcoid");
    WidgetLocatorContext<QWidget> ctx2(static_cast<Player *>(jsonClient()), command, "destoid");

    if (ctx.hasError()) { writeResponse(ctx.lastError); return; }
    if (ctx2.hasError()) { writeResponse(ctx2.lastError); return; }

    QPoint srcPos;
    if (command.contains("srcpos") && ! command["srcpos"].isNull()) {
        srcPos = pointFromString(command["srcpos"].toString());
    } else {
        srcPos = ctx.widget->rect().center();
    }

    QPoint destPos;
    if (command.contains("destpos") && ! command["destpos"].isNull()) {
        destPos = pointFromString(command["destpos"].toString());
    } else {
        destPos = ctx2.widget->rect().center();
    }

    m_src = ctx.widget;
    m_dest = ctx2.widget;
    m_srcPos = srcPos;
    m_destPos = destPos;
}
Esempio n. 3
0
void if_match_node::execute( proof_context& ctx )
{
  proof_context ctx2( ctx.silent_clone() );
  bool result = false;

  // We don't want exceptions from the test to terminate
  // the search. 
  // 
  // TODO  What about falseness?  Should we ignore
  // falseness during the test expresion?  
  //
  // For example, if I have
  //
  //   W = repeat { b, /1*8?/: b, break; p }
  //   H = repeat { b, /1*8/:  b, break; p }
  //   prove W,4H  // false: 3H comes round
  //
  // does this mean that the fourth H should be suppressed?
  //
  // Currently it does, and I think this is wrong.

  try {
    result = test.evaluate( ctx2 );
  } 
  catch ( script_exception const& ) {}

  if ( result )
    iftrue.execute( ctx );
  else if ( !iffalse.isnull() )
    iffalse.execute( ctx );
}
Esempio n. 4
0
void test_case_6()
{
    value1 = 0;
    value2 = "";
    value3 = "";
    BOOST_CHECK_EQUAL( 0, value1);
    BOOST_CHECK_EQUAL( std::string(""), value2);
    BOOST_CHECK_EQUAL( std::string(""), value3);

    boost::contexts::context ctx1(
        fn4, "abc", "xyz",
        boost::contexts::default_stacksize(),
        boost::contexts::stack_unwind,
		boost::contexts::return_to_caller);
    boost::contexts::context ctx2(
        fn1, 7,
        boost::contexts::default_stacksize(),
        boost::contexts::stack_unwind,
		ctx1);

    BOOST_CHECK( ! ctx1.is_complete() );
    BOOST_CHECK( ! ctx2.is_complete() );
    ctx2.start();
    BOOST_CHECK( ctx1.is_complete() );
    BOOST_CHECK( ctx2.is_complete() );
  
    BOOST_CHECK_EQUAL( 7, value1);
    BOOST_CHECK_EQUAL( "abc", value2);
    BOOST_CHECK_EQUAL( "xyz", value3);
}
Esempio n. 5
0
bool MgDot::_draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const
{
    GiContext ctx2(0, GiColor::Invalid(), GiContext::kNullLine,
                   ctx.hasFillColor() ? ctx.getFillColor() : ctx.getLineColor());
    float w = gs.calcPenWidth(ctx.getLineWidth(), false);
    
    bool ret = gs.drawCircle(&ctx2, _point, gs.xf().displayToModel(w));
    return __super::_draw(mode, gs, ctx, segment) || ret;
}
Esempio n. 6
0
void test_case_1()
{
    boost::contexts::context ctx1;
    boost::contexts::context ctx2(
        fn0,
        boost::contexts::default_stacksize(),
        boost::contexts::stack_unwind, boost::contexts::return_to_caller);
    BOOST_CHECK( ! ctx1);
    BOOST_CHECK( ctx2);
    ctx1 = boost::move( ctx2);
    BOOST_CHECK( ctx1);
    BOOST_CHECK( ! ctx2);
}
Esempio n. 7
0
  static void test_base()
  {
    try
    {
      std::size_t echo_num = 10;

      gce::log::asio_logger lg;
      attributes attrs;
      attrs.lg_ = boost::bind(&gce::log::asio_logger::output, &lg, _arg1, "");
      
      attrs.id_ = atom("router");
      context ctx(attrs);
      attrs.id_ = atom("one");
      context ctx1(attrs);
      attrs.id_ = atom("two");
      context ctx2(attrs);
      
      threaded_actor base = spawn(ctx);
      threaded_actor base1 = spawn(ctx1);
      threaded_actor base2 = spawn(ctx2);
      
      netopt_t opt = make_netopt();
      opt.is_router = 1;
      gce::bind(base, "tcp://127.0.0.1:14923", remote_func_list_t(), opt);

      spawn(base1, "test_lua_actor/services.lua", monitored);
      spawn(base2, "test_lua_actor/services.lua", monitored);

      opt.reconn_period = seconds(1);
      connect(base1, "router", "tcp://127.0.0.1:14923", opt);
      connect(base2, "router", "tcp://127.0.0.1:14923", opt);
      base2.sleep_for(millisecs(200));

      for (std::size_t i=0; i<echo_num; ++i)
      {
        base1->send("echo_svc", "echo");
        base1->recv("echo");
      }

      base1->send(make_svcid("one", "echo_svc"), "end");
      base1->send(make_svcid("two", "echo_svc"), "end");

      base1->recv(exit);
      base2->recv(exit);
    }
    catch (std::exception& ex)
    {
      std::cerr << ex.what() << std::endl;
    }
  }
Esempio n. 8
0
void test_move() {
    value1 = 0;
    ctx::captured_context ctx;
    BOOST_CHECK( ! ctx);
    ctx::captured_context ctx1( fn1, 1);
    ctx::captured_context ctx2( fn1, 3);
    BOOST_CHECK( ctx1);
    BOOST_CHECK( ctx2);
    ctx1 = std::move( ctx2);
    BOOST_CHECK( ctx1);
    BOOST_CHECK( ! ctx2);
    BOOST_CHECK_EQUAL( 0, value1);
    ctx1();
    BOOST_CHECK_EQUAL( 3, value1);
}
Esempio n. 9
0
bool GiGraphics::drawPath(const GiContext* ctx, const MgPath& path, bool fill, bool modelUnit)
{
    if (ctx && ctx->hasArrayHead() && path.getSubPathCount() == 1 && !path.isClosed()) {
        MgPath pathw(path);
        GiContext ctx2(*ctx);
        
        pathw.transform(S2D(xf(), modelUnit));
        
        ctx2.setNoFillColor();
        ctx2.setStartArrayHead(0);
        ctx2.setEndArrayHead(0);
        
        return drawPathWithArrayHead(ctx2, pathw, ctx->getStartArrayHead(), ctx->getEndArrayHead());
    }
    
    return drawPath_(ctx, path, fill, S2D(xf(), modelUnit));
}
Esempio n. 10
0
  static void test_base()
  {
    try
    {
      std::size_t echo_num = 100;

      attributes attrs;
      attrs.id_ = atom("one");
      context ctx1(attrs);
      attrs.id_ = atom("two");
      context ctx2(attrs);

      mixin_t base1 = spawn(ctx1);
      mixin_t base2 = spawn(ctx2);

      gce::bind(base2, "tcp://127.0.0.1:14923");

      aid_t echo_aid =
        spawn(
          base2,
          boost::bind(
            &socket_ut::echo, _1
            ),
          monitored
          );

      wait(base1, boost::chrono::milliseconds(100));
      net_option opt;
      opt.reconn_period_ = seconds_t(1);
      connect(base1, atom("two"), "tcp://127.0.0.1:14923", false, opt);

      for (std::size_t i=0; i<echo_num; ++i)
      {
        send(base1, echo_aid, atom("echo"));
        recv(base1, atom("echo"));
      }
      send(base1, echo_aid, atom("end"));

      recv(base2);
    }
    catch (std::exception& ex)
    {
      std::cerr << "test_base except: " << ex.what() << std::endl;
    }
  }
Esempio n. 11
0
int
main(int argc, char *argv[])
{  
    std::cout << "SSLDemo  Copyright (C) 2015,  W. B. Yates" << std::endl;
    std::cout << "This program comes with ABSOLUTELY NO WARRANTY; for details see http://www.gnu.org/licenses/." << std::endl;
    std::cout << "This is free software, and you are welcome to redistribute it" << std::endl;
    std::cout << "under certain conditions; see http://www.gnu.org/licenses/" << std::endl;
    
    SSLContext ctx1("client", "client.pem", "password");
    SSLContext ctx2("server", "server.pem", "password", true);
    
    SSLSocket::registerContext( &ctx1 );
    SSLSocket::registerContext( &ctx2 );
    
    SSLSocket client;
    client.setContext("client");
    
    SSLSocket server("server");
    
    //Socket client;
    //Socket server;
    

    for (int i = 0; i < 5; ++i)
    {
        std::cout << "\nBegin socket test " << i + 1 <<  std::endl;
        std::thread thread1 = std::thread(rec,&server);
        std::thread thread2;
        
        if (i == 0)
            thread2 = std::thread(sender1,&client);
        else thread2 = std::thread(sender2,&client);
        thread1.join();
        thread2.join();
    }

    SSLSocket::clearRegister();
    std::cout << "End socket test" <<  std::endl;
    return 0;
}
std::execution_context<int,int> ctx1(
        [](std::execution_context<int,int> ctx2,int i,int j){
            std::printf("inside ctx1,i==%d j==%d\n",i,j);
            std::tie(ctx2,i,j)=ctx2(i+j,i-j);
            return ctx2;
        });
int i=2,j=1;
std::tie(ctx1,i,j)=ctx1(i,j);
std::printf("i==%d j==%d\n",i,j);

output:
    inside ctx1,i==2 j==1
    i==3 j==1
std::execution_context<int> ctx1([](std::execution_context<int> ctx2,int j){
            std::printf("inside ctx1,j==%d\n",j);
            std::tie(ctx2,j)=ctx2(j+1);
            return ctx2;
        });
int i=1;
std::tie(ctx1,i)=ctx1(i);
std::printf("i==%d\n",i);

output:
    inside ctx1,j==1
    i==2