Esempio n. 1
0
void pawsPetStatWindow::BuySkill()
{
    csString commandData;
    commandData.Format("<B NAME=\"%s\" />", EscpXML(selectedSkill).GetData());
    psPetSkillMessage outgoing( psPetSkillMessage::BUY_SKILL, commandData);
    outgoing.SendMessage();
}
Esempio n. 2
0
int
main (void)
{
  struct client *bob = (struct client *) malloc (sizeof (struct client));
  bob->name = "bob";
  bob->privateKey = "key-bob";
  struct userPublicKeyPair *userPublicKeyPairRjh =
    (struct userPublicKeyPair *) malloc (sizeof (struct userPublicKeyPair));
  userPublicKeyPairRjh->user = "******";
  userPublicKeyPairRjh->publicKey = "key-rjh";
  NODE *userPublicKeyPairsBob = list_create (userPublicKeyPairRjh);
  bob->userPublicKeyPairs = userPublicKeyPairsBob;

  struct client *rjh = (struct client *) malloc (sizeof (struct client));
  rjh->name = "rjh";
  rjh->privateKey = "key-rjh";
  struct userPublicKeyPair *userPublicKeyPairBob =
    (struct userPublicKeyPair *) malloc (sizeof (struct userPublicKeyPair));
  userPublicKeyPairBob->user = "******";
  userPublicKeyPairBob->publicKey = "key-bob";
  NODE *userPublicKeyPairsRjh = list_create (userPublicKeyPairBob);
  rjh->userPublicKeyPairs = userPublicKeyPairsRjh;
  rjh->forwardReceiver = "chucknorris";

  struct email *mail = (struct email *) malloc (sizeof (struct email));
  mail->to = "rjh";
  mail->subject = "<some subject>";
  mail->body = "<some body>";

  outgoing (bob, mail);
  incoming (rjh, mail);

  return 0;
}
Esempio n. 3
0
void*
multipart_receiver(void* arg)
{
  zmq::socket_t s(ctx, ZMQ_REP);
  s.connect(static_cast<char*>(arg));

  ZmqMessage::has_more(s); //to load libzmqmessage.so

  for (size_t i = 0; i < ITERS; ++i)
  {
    ZmqMessage::Incoming<ZmqMessage::SimpleRouting, ReqStorage> incoming(s);

    incoming.receive(ARRAY_LEN(req_parts), req_parts, true);

    StringFace s1, s2, s3;

    incoming >> s1 >> s2 >> s3;

    assert(s1 == PART1);
    assert(s2 == PART2);
    assert(s3 == PART3);

    ZmqMessage::Outgoing<ZmqMessage::SimpleRouting> outgoing(s, 0);

    outgoing << ZmqMessage::NullMessage << ZmqMessage::Flush;
  }
  return 0;
}
void ZC_JR_Post_Migrate_Fn(void *data, int num_gid_entries, int num_lid_entries,
			   int num_import, ZOLTAN_ID_PTR import_glob_id, 
			   ZOLTAN_ID_PTR import_local_id, int *import_procs, 
			   int num_export, ZOLTAN_ID_PTR export_glob_id, 
			   ZOLTAN_ID_PTR export_local_id, int *export_procs,
			  int *ierr)
{
  ::ZoltanSpace::EntityListImpl outgoing(num_export), incoming(num_import) ;
  
  incoming.create_gid_list(num_import*num_gid_entries, import_glob_id) ;
  incoming.create_lid_list(num_import*num_lid_entries, import_local_id) ;
  incoming.create_proc_list(num_import, import_procs) ;

  outgoing.create_gid_list(num_export*num_gid_entries, export_glob_id) ;
  outgoing.create_lid_list(num_export*num_lid_entries, export_local_id) ;
  outgoing.create_proc_list(num_export, export_procs) ;

  incoming.addRef() ; outgoing.addRef() ;
  int res = ::ZoltanSpace::Globals::pDataMigPort->PostUnpackingProcessing( 
		      dynamic_cast< ::LoadPartitionerSpace::EntityList *> (&outgoing),	
		      dynamic_cast< ::LoadPartitionerSpace::EntityList *> (&incoming) ) ;

  *ierr = (res < 0 ) ? ZOLTAN_FATAL : ZOLTAN_OK ;

  return ;
}
Esempio n. 5
0
void psCreationManager::GetParentData()
{
    if ( !hasParentData )
    {
        psCreationChoiceMsg outgoing(MSGTYPE_CHAR_CREATE_PARENTS);
        outgoing.SendMessage();
    }
}
Esempio n. 6
0
void psCreationManager::GetChildhoodData()
{
    if ( !hasChildhoodData )
    {
        psCreationChoiceMsg outgoing(MSGTYPE_CHAR_CREATE_CHILDHOOD);
        outgoing.SendMessage();
    }
}
Esempio n. 7
0
void pawsSkillWindow::Hide()
{
    psGUISkillMessage outgoing(psGUISkillMessage::QUIT, "");
    outgoing.SendMessage();
    skillCache.clear();
    pawsControlledWindow::Hide();
    train = false;
}
Esempio n. 8
0
void psCreationManager::GetTraitData()
{
    if ( !hasTraitData )
    {
        psCreationChoiceMsg outgoing(MSGTYPE_CHAR_CREATE_TRAITS);
        outgoing.SendMessage();
    }
}
Lav_PUBLIC_FUNCTION LavError Lav_deviceGetName(unsigned int index, char** destination) {
	PUB_BEGIN
	auto n = (*audio_output_factory)->getOutputNames();
	if(index >= n.size()) ERROR(Lav_ERROR_RANGE, "Invalid device index.");
	auto s = n[index];
	char* outgoingStr = new char[s.size()+1];
	std::copy(s.c_str(), s.c_str()+s.size(), outgoingStr);
	outgoingStr[s.size()] = '\0';
	std::shared_ptr<char> outgoing(outgoingStr, [](char* what){delete[] what;});
	*destination = outgoingPointer<char>(outgoing);
	PUB_END
}
Esempio n. 10
0
/// Calculate the distances traversed by the neutrons within the sample
/// @param detector :: The detector we are working on
/// @param L2s :: A vector of the sample-detector distance for  each segment of
/// the sample
void AbsorptionCorrection::calculateDistances(const IDetector &detector,
                                              std::vector<double> &L2s) const {
  V3D detectorPos(detector.getPos());
  if (detector.nDets() > 1) {
    // We need to make sure this is right for grouped detectors - should use
    // average theta & phi
    detectorPos.spherical(detectorPos.norm(),
                          detector.getTwoTheta(V3D(), V3D(0, 0, 1)) * 180.0 /
                              M_PI,
                          detector.getPhi() * 180.0 / M_PI);
  }

  for (size_t i = 0; i < m_numVolumeElements; ++i) {
    // Create track for distance in cylinder between scattering point and
    // detector
    V3D direction = detectorPos - m_elementPositions[i];
    direction.normalize();
    Track outgoing(m_elementPositions[i], direction);
    int temp = m_sampleObject->interceptSurface(outgoing);

    /* Most of the time, the number of hits is 1. Sometime, we have more than
     * one intersection due to
     * arithmetic imprecision. If it is the case, then selecting the first
     * intersection is valid.
     * In principle, one could check the consistency of all distances if hits is
     * larger than one by doing:
     * Mantid::Geometry::Track::LType::const_iterator it=outgoing.begin();
     * and looping until outgoing.end() checking the distances with it->Dist
     */
    // Not hitting the cylinder from inside, usually means detector is badly
    // defined,
    // i.e, position is (0,0,0).
    if (temp < 1) {
      // FOR NOW AT LEAST, JUST IGNORE THIS ERROR AND USE A ZERO PATH LENGTH,
      // WHICH I RECKON WILL MAKE A
      // NEGLIGIBLE DIFFERENCE ANYWAY (ALWAYS SEEMS TO HAPPEN WITH ELEMENT RIGHT
      // AT EDGE OF SAMPLE)
      L2s[i] = 0.0;

      // std::ostringstream message;
      // message << "Problem with detector at " << detectorPos << " ID:" <<
      // detector->getID() << '\n';
      // message << "This usually means that this detector is defined inside the
      // sample cylinder";
      // g_log.error(message.str());
      // throw std::runtime_error("Problem in
      // AbsorptionCorrection::calculateDistances");
    } else // The normal situation
    {
      L2s[i] = outgoing.cbegin()->distFromStart;
    }
  }
}
void CustomPropertyAutomator::CopyTo( IDispatchPtr spDestDispProps )
{
    CustomPropertyAutomator outgoing( spDestDispProps );

    long lCount = GetCount();
    for( long l = 1; l <= lCount; ++l )
    {
        std::pair< CStdString, _variant_t > propPair = GetCustomProperty( l );
        if( propPair.first != _T("") && propPair.second.vt != VT_EMPTY )
        {
            outgoing.SetCustomProperty( propPair.first, propPair.second );
        }
    }
}
Esempio n. 12
0
void
autoRespond (struct client *client, struct email *msg)
{
  if (!client->autoResponse || !isReadable (msg))
    return;
  struct email *response = cloneEmail (msg);
  response->to = strdup (msg->from);
  response->body = strdup (client->autoResponse);
  char *respondPrefix = "Auto-Response ";
  response->subject =
    (char *) malloc (strlen (respondPrefix) + strlen (msg->subject));
  strcat (response->subject, respondPrefix);
  strcat (response->subject, msg->subject);
  outgoing (client, response);
}
Esempio n. 13
0
void pawsSkillWindow::OnNumberEntered(const char* /*name*/, int /*param*/, int number)
{
    csString commandData;

    if(number == -1)
        return;

    if (selectedSkill.IsEmpty())
    {
        PawsManager::GetSingleton().CreateWarningBox("You have to select a skill to buy.");
        return;
    }

    commandData.Format("<B NAME=\"%s\" AMOUNT=\"%d\"/>", EscpXML(selectedSkill).GetData(), number);
    psGUISkillMessage outgoing(psGUISkillMessage::BUY_SKILL, commandData);
    outgoing.SendMessage();
}
Esempio n. 14
0
static float bez2( Key *key0, Key *key1, float time )
{
   float x, y, t, t0 = 0.0f, t1 = 1.0f;

   if ( key0->shape == SHAPE_BEZ2 )
      x = key0->time + key0->param[ 2 ];
   else
      x = key0->time + ( key1->time - key0->time ) / 3.0f;

   t = bez2_time( key0->time, x, key1->time + key1->param[ 0 ], key1->time,
      time, &t0, &t1 );

   if ( key0->shape == SHAPE_BEZ2 )
      y = key0->value + key0->param[ 3 ];
   else
      y = key0->value + outgoing( (lwKey*)key0, key1 ) / 3.0f;

   return bezier( key0->value, y, key1->param[ 1 ] + key1->value, key1->value, t );
}
Esempio n. 15
0
void OdbcLog::clear()
{ QF_STACK_PUSH(OdbcLog::clear)

  std::stringstream whereClause;

  whereClause << "WHERE ";

  if( m_pSessionID )
  {
    whereClause
    << "BeginString = '" << m_pSessionID->getBeginString().getValue() << "' "
    << "AND SenderCompID = '" << m_pSessionID->getSenderCompID().getValue() << "' "
    << "AND TargetCompID = '" << m_pSessionID->getTargetCompID().getValue() << "' ";

    if( m_pSessionID->getSessionQualifier().size() )
      whereClause << "AND SessionQualifier = '" << m_pSessionID->getSessionQualifier() << "'";
  }
  else
  {
    whereClause << "BeginString = NULL AND SenderCompID = NULL && TargetCompID = NULL";
  }

  std::stringstream incomingQuery;
  std::stringstream outgoingQuery;
  std::stringstream eventQuery;

  incomingQuery 
    << "DELETE FROM " << m_incomingTable << " " << whereClause.str();
  outgoingQuery 
    << "DELETE FROM " << m_outgoingTable << " " << whereClause.str();
  eventQuery 
    << "DELETE FROM " << m_eventTable << " " << whereClause.str();

  OdbcQuery incoming( incomingQuery.str() );
  OdbcQuery outgoing( outgoingQuery.str() );
  OdbcQuery event( eventQuery.str() );
  m_pConnection->execute( incoming );
  m_pConnection->execute( outgoing );
  m_pConnection->execute( event );
  
  QF_STACK_POP
}
Esempio n. 16
0
void pawsSkillWindow::Show()
{
    pawsControlledWindow::Show();

    // Hack set to no when show called because of an incoming skill table.
    if (skillString != "no")
    {
        skillCache.clear(); // Clear the skill cache before the new request
        psGUISkillMessage outgoing(psGUISkillMessage::REQUEST, "");
        outgoing.SendMessage();
    }

    // If this is the first time the window is open then we need to get our
    // full list of faction information.
    if (!train && !factRequest)
    {
        psFactionMessage factionRequest(0, psFactionMessage::MSG_FULL_LIST);
        factionRequest.BuildMsg();
        factionRequest.SendMessage();
    }
}
Esempio n. 17
0
void pawsSkillWindow::OnListAction( pawsListBox* widget, int status )
{
    if (status == LISTBOX_HIGHLIGHTED)
    {
        pawsListBoxRow* row = widget->GetSelectedRow();
        pawsTextBox* skillName = (pawsTextBox*)(row->GetColumn(0));

        selectedSkill.Replace( skillName->GetText() );

        // Try to find cached copy of the description string */
        csStringID skillNameId = (csStringID)psengine->FindCommonStringId(selectedSkill);

        psSkillDescription *desc = NULL;
        if (skillNameId != csInvalidStringID)
        {
            desc = skillDescriptions.Get(skillNameId, NULL);
        }

        if (!desc)
        {
            // Request from the server
            csString commandData;
            commandData.Format("<S NAME=\"%s\" />", EscpXML(selectedSkill).GetData());
            psGUISkillMessage outgoing( psGUISkillMessage::SKILL_SELECTED, commandData);
            outgoing.SendMessage();
        }
        else
        {
            // Use the cached version
            if (desc->GetCategory() == CAT_FACTION)
            {
                factionsDescription->SetText(desc->GetDescription());
            }
            else
            {
                skills[desc->GetCategory()].description->SetText(desc->GetDescription());
            }
        }
    }
}
Esempio n. 18
0
void
multipart_sender(zmq::socket_t& s)
{
  for (size_t i = 0; i < ITERS; ++i)
  {
    ZmqMessage::Outgoing<ZmqMessage::SimpleRouting> outgoing(s, 0);

    outgoing
      << StringFace(PART1, ARRAY_LEN(PART1)-1)
      << StringFace(PART2, ARRAY_LEN(PART2)-1)
      << StringFace(PART3, ARRAY_LEN(PART3)-1)
      << ZmqMessage::Flush;

    ZmqMessage::Incoming<ZmqMessage::SimpleRouting, ResStorage> incoming(s);

    incoming.receive(1, true);

    if (i % 1000 == 0)
    {
      std::cout << ".";
      std::cout.flush();
    }
  }
}
Esempio n. 19
0
void Track::notify(int evtTime) {
    println("Track::notify");
    trackBlocked = false;
    outgoing(evtTime);
}
Esempio n. 20
0
float lwEvalEnvelope( lwEnvelope *env, float time )
{
   lwKey *key0, *key1, *skey, *ekey;
   float t, h1, h2, h3, h4, in, out, offset = 0.0f;
   int noff;


   /* if there's no key, the value is 0 */

   if ( env->nkeys == 0 ) return 0.0f;

   /* if there's only one key, the value is constant */

   if ( env->nkeys == 1 )
      return env->key->value;

   /* find the first and last keys */

   skey = ekey = env->key;
   while ( ekey->next ) ekey = ekey->next;

   /* use pre-behavior if time is before first key time */

   if ( time < skey->time ) {
      switch ( env->behavior[ 0 ] )
      {
         case BEH_RESET:
            return 0.0f;

         case BEH_CONSTANT:
            return skey->value;

         case BEH_REPEAT:
            time = range( time, skey->time, ekey->time, NULL );
            break;

         case BEH_OSCILLATE:
            time = range( time, skey->time, ekey->time, &noff );
            if ( noff % 2 )
               time = ekey->time - skey->time - time;
            break;

         case BEH_OFFSET:
            time = range( time, skey->time, ekey->time, &noff );
            offset = noff * ( ekey->value - skey->value );
            break;

         case BEH_LINEAR:
            switch ( skey->shape ) {
               case SHAPE_STEP:
                  return skey->value;
               case SHAPE_LINE:
                  return ( skey->value - skey->next->value )
                       / ( skey->time - skey->next->time )
                       * ( time - skey->next->time )
                       + skey->next->value;
               case SHAPE_TCB:
               case SHAPE_HERM:
               case SHAPE_BEZI:
                  out = outgoing( skey, (Key*)(skey->next) )
                      / ( skey->next->time - skey->time );
                  return out * ( time - skey->time ) + skey->value;
               case SHAPE_BEZ2:
                  return ( skey->param[ 1 ] - skey->param[ 3 ] )
                       / ( skey->param[ 0 ] - skey->param[ 2 ] )
                       * ( time - skey->time )
                       + skey->value;
            }
      }
   }

   /* use post-behavior if time is after last key time */

   else if ( time > ekey->time ) {
      switch ( env->behavior[ 1 ] )
      {
         case BEH_RESET:
            return 0.0f;

         case BEH_CONSTANT:
            return ekey->value;

         case BEH_REPEAT:
            time = range( time, skey->time, ekey->time, NULL );
            break;

         case BEH_OSCILLATE:
            time = range( time, skey->time, ekey->time, &noff );
            if ( noff % 2 )
               time = ekey->time - skey->time - time;
            break;

         case BEH_OFFSET:
            time = range( time, skey->time, ekey->time, &noff );
            offset = noff * ( ekey->value - skey->value );
            break;

         case BEH_LINEAR:
            switch ( ekey->shape ) {
               case SHAPE_STEP:
                  return ekey->value;
               case SHAPE_LINE:
                  return ( ekey->value - ekey->prev->value )
                       / ( ekey->time - ekey->prev->time )
                       * ( time - ekey->prev->time )
                       + ekey->prev->value;
               case SHAPE_TCB:
               case SHAPE_HERM:
               case SHAPE_BEZI:
                  in = incoming( (Key*)(ekey->prev), (Key*)ekey )
                     / ( ekey->time - ekey->prev->time );
                  return in * ( time - ekey->time ) + ekey->value;
               case SHAPE_BEZ2:
                  return ( ekey->param[ 3 ] - ekey->param[ 1 ] )
                       / ( ekey->param[ 2 ] - ekey->param[ 0 ] )
                       * ( time - ekey->time )
                       + ekey->value;
            }
      }
   }

   /* get the endpoints of the interval being evaluated */

   key0 = env->key;
   while ( time > key0->next->time )
      key0 = key0->next;
   key1 = key0->next;

   /* check for singularities first */

   if ( time == key0->time )
      return key0->value + offset;
   else if ( time == key1->time )
      return key1->value + offset;

   /* get interval length, time in [0, 1] */

   t = ( time - key0->time ) / ( key1->time - key0->time );

   /* interpolate */

   switch ( key1->shape )
   {
      case SHAPE_TCB:
      case SHAPE_BEZI:
      case SHAPE_HERM:
         out = outgoing( key0, (Key*)key1 );
         in = incoming( (Key*)key0, (Key*)key1 );
         hermite( t, &h1, &h2, &h3, &h4 );
         return h1 * key0->value + h2 * key1->value + h3 * out + h4 * in + offset;

      case SHAPE_BEZ2:
         return bez2( (Key*)key0, (Key*)key1, time ) + offset;

      case SHAPE_LINE:
         return key0->value + t * ( key1->value - key0->value ) + offset;

      case SHAPE_STEP:
         return key0->value + offset;

      default:
         return offset;
   }
}
Esempio n. 21
0
double LWEnvelope::Evaluate(double Time)
{

if ( NumKeys == 0 )
	return 0.0;

if ( NumKeys == 1 )
    return Keys.begin()->value;

if(InternalCalculation)
{
   float offset=0.0;

	if (Time>EndTime)
		Time=EndTime;
	if (Time<StartTime)
		Time=StartTime;

   /* get the endpoints of the interval being evaluated */

	std::list<LWKey>::iterator key0(Keys.begin());
	std::list<LWKey>::iterator key1(Keys.begin());

   while ( Time > (*(++key1)).Time )   // Hope this construction works!
   {
      key0 = key1;
   }

   /* check for singularities first */

   if ( Time == (*key0).Time )
      return (*key0).value + offset;
   else if ( Time == (*key1).Time )
      return (*key1).value + offset;

   /* get interval length, time in [0, 1] */

   float t = ( Time - (*key0).Time ) / ( (*key1).Time - (*key0).Time );

float out=0.0;
float in=0.0;

float h1,h2,h3,h4;

   switch ( (*key1).shape )
   {
      case SHAPE_TCB:
      case SHAPE_BEZI:
      case SHAPE_HERM:
         out = outgoing( key0, key1 );
         in = incoming( key0, key1 );
         hermite( t, &h1, &h2, &h3, &h4 );
         return h1 * (*key0).value + h2 * (*key1).value + h3 * out + h4 * in + offset;

      case SHAPE_BEZ2:
         return 0.0;//bez2( key0, key1, time ) + offset;

      case SHAPE_LINE:
         return (*key0).value + t * ( (*key1).value - (*key0).value ) + offset;

      case SHAPE_STEP:
         return (*key0).value + offset;

      default:
         return offset;
   }



	double TheResult=1.0;

		return TheResult;//Lightwave3D::chaninfo->channelEvaluate(EnvChannel,Time);
}
else
	return Lightwave3D::chaninfo->channelEvaluate(EnvChannel,Time);
}
Esempio n. 22
0
void PassManager::run_passes(DexStoresVector& stores, ConfigFiles& cfg) {
  DexStoreClassesIterator it(stores);
  Scope scope = build_class_scope(it);

  {
    Timer t("API Level Checker");
    api::LevelChecker::init(m_redex_options.min_sdk, scope);
  }

  char* seeds_output_file = std::getenv("REDEX_SEEDS_FILE");
  if (seeds_output_file) {
    std::string seed_filename = seeds_output_file;
    Timer t("Writing seeds file " + seed_filename);
    std::ofstream seeds_file(seed_filename);
    redex::print_seeds(seeds_file, cfg.get_proguard_map(), scope, false, false);
  }
  if (!cfg.get_printseeds().empty()) {
    Timer t("Writing seeds to file " + cfg.get_printseeds());
    std::ofstream seeds_file(cfg.get_printseeds());
    redex::print_seeds(seeds_file, cfg.get_proguard_map(), scope);
    std::ofstream config_file(cfg.get_printseeds() + ".pro");
    redex::show_configuration(config_file, scope, *m_pg_config);
    std::ofstream incoming(cfg.get_printseeds() + ".incoming");
    redex::print_classes(incoming, cfg.get_proguard_map(), scope);
    std::ofstream shrinking_file(cfg.get_printseeds() + ".allowshrinking");
    redex::print_seeds(shrinking_file, cfg.get_proguard_map(), scope, true,
                       false);
    std::ofstream obfuscation_file(cfg.get_printseeds() + ".allowobfuscation");
    redex::print_seeds(obfuscation_file, cfg.get_proguard_map(), scope, false,
                       true);
  }

  // Enable opt decision logging if specified in config.
  const Json::Value& opt_decisions_args =
      cfg.get_json_config()["opt_decisions"];
  if (opt_decisions_args.get("enable_logs", false).asBool()) {
    opt_metadata::OptDataMapper::get_instance().enable_logs();
  }

  // TODO(fengliu) : Remove Pass::eval_pass API
  for (size_t i = 0; i < m_activated_passes.size(); ++i) {
    Pass* pass = m_activated_passes[i];
    TRACE(PM, 1, "Evaluating %s...\n", pass->name().c_str());
    Timer t(pass->name() + " (eval)");
    m_current_pass_info = &m_pass_info[i];
    pass->eval_pass(stores, cfg, *this);
    m_current_pass_info = nullptr;
  }

  // Retrieve the type checker's settings.
  const Json::Value& type_checker_args =
      cfg.get_json_config()["ir_type_checker"];
  bool run_after_each_pass =
      type_checker_args.get("run_after_each_pass", false).asBool();
  // When verify_none is enabled, it's OK to have polymorphic constants.
  bool polymorphic_constants =
      type_checker_args.get("polymorphic_constants", false).asBool() ||
      get_redex_options().verify_none_enabled;
  bool verify_moves = type_checker_args.get("verify_moves", false).asBool();
  bool check_no_overwrite_this =
      type_checker_args.get("check_no_overwrite_this", false).asBool();
  std::unordered_set<std::string> trigger_passes;

  for (auto& trigger_pass : type_checker_args["run_after_passes"]) {
    trigger_passes.insert(trigger_pass.asString());
  }

  for (size_t i = 0; i < m_activated_passes.size(); ++i) {
    Pass* pass = m_activated_passes[i];
    TRACE(PM, 1, "Running %s...\n", pass->name().c_str());
    Timer t(pass->name() + " (run)");
    m_current_pass_info = &m_pass_info[i];

    {
      ScopedCommandProfiling cmd_prof(
          m_profiler_info && m_profiler_info->pass == pass
              ? boost::make_optional(m_profiler_info->command)
              : boost::none);
      jemalloc_util::ScopedProfiling malloc_prof(m_malloc_profile_pass == pass);
      pass->run_pass(stores, cfg, *this);
    }

    if (run_after_each_pass || trigger_passes.count(pass->name()) > 0) {
      scope = build_class_scope(it);
      // It's OK to overwrite the `this` register if we are not yet at the
      // output phase -- the register allocator can fix it up later.
      run_type_checker(scope, polymorphic_constants, verify_moves,
                       /* check_no_overwrite_this */ false);
    }
    m_current_pass_info = nullptr;
  }

  // Always run the type checker before generating the optimized dex code.
  scope = build_class_scope(it);
  run_type_checker(scope, polymorphic_constants, verify_moves,
                   check_no_overwrite_this);

  if (!cfg.get_printseeds().empty()) {
    Timer t("Writing outgoing classes to file " + cfg.get_printseeds() +
            ".outgoing");
    // Recompute the scope.
    scope = build_class_scope(it);
    std::ofstream outgoing(cfg.get_printseeds() + ".outgoing");
    redex::print_classes(outgoing, cfg.get_proguard_map(), scope);
  }
}
Esempio n. 23
0
void test_udp_messenger_send_receive() {
  rstd::vector<rstd::string> client_peer_strings;
  rstd::vector<rstd::string> worker_peer_strings;

  client_peer_strings.push_back("127.0.0.1:22222");  // The requestor.

  worker_peer_strings.push_back("127.0.0.1:22223");  // Workers
  worker_peer_strings.push_back("127.0.0.1:22224");  
  worker_peer_strings.push_back("127.0.0.1:22225");  
  worker_peer_strings.push_back("127.0.0.1:22226");  
  worker_peer_strings.push_back("127.0.0.1:22227");  
  worker_peer_strings.push_back("127.0.0.1:22228");  
  worker_peer_strings.push_back("127.0.0.1:22229"); 

  static const size_t NUMBER_WORKERS = 7;
  static const size_t NUMBER_MESSAGES = 1000;

  size_t i;
  for (i = 0; i < NUMBER_WORKERS; ++i) {
    pid_t pid = ::np1::process::mandatory_fork();
    switch (pid) {
    case 0:
      // Child.
      {
        run_worker_udp_messenger(client_peer_strings, worker_peer_strings,
                                  worker_peer_strings[i]);
        exit(0);
      }
      break;

    default:
      // Parent- just go around again.
      break;
    }        
  }

  // We can only get to here if we are the parent.
  udp_messenger_type messenger(client_peer_strings, worker_peer_strings,
                                client_peer_strings[0], false);
  
  // Send all the messages and receive any responses we get while sending.
  // We'll just pretend there is one resource per message because in a real query
  // that's (very) approximately what will happen anyway.
  ::np1::skip_list<rstd::string> worker_responses;
  size_t unique_responses_received = 0;

  udp_messenger_type::message incoming;

  for (i = 0; i < NUMBER_MESSAGES; ++i) {
    rstd::string outgoing_payload = ::np1::str::to_dec_str(i);
    rstd::string resource_id = outgoing_payload;
    ::np1::str::ref resource_id_ref = ::np1::str::ref(resource_id);
    udp_messenger_type::message outgoing(resource_id_ref);
    outgoing.append(outgoing_payload.c_str(), outgoing_payload.length() + 1);
    
    if (messenger.receive(incoming, 0)) {
      // DON'T assume that the message is null-terminated in production code!
      if (worker_responses.insert(rstd::string((const char *)incoming.payload_ptr()))) {
        ++unique_responses_received;
      }      
    }

    messenger.send(outgoing);
  }

  // Receive all the leftover responses.
  while (unique_responses_received < NUMBER_MESSAGES) {
    if (messenger.receive(incoming)) {
      // DON'T assume that the message is null-terminated in production code!
      if (worker_responses.insert(rstd::string((const char *)incoming.payload_ptr()))) {
        ++unique_responses_received;
      }
    }
  }

  printf("  number_sinbins: %lu  number_retries: %lu\n",
          (unsigned long)messenger.number_sinbins(),
          (unsigned long)messenger.number_retries());

  printf("  Telling workers to shut down\n");  

  // Tell all the workers to shut down.
  for (i = 0; i < NUMBER_WORKERS; ++i) {
    rstd::string outgoing_payload = "exit";
    ::np1::io::net::ip_endpoint worker_ep(worker_peer_strings[i]);    
    udp_messenger_type::message outgoing(worker_ep);
    outgoing.append(outgoing_payload.c_str(), outgoing_payload.length() + 1);
    messenger.send(outgoing);
  }

  printf("  Waiting for workers to shut down\n");  


  // Wait for all the workers to shut down.
  int status;
  do {
    udp_messenger_type::message ignored;
    messenger.receive(ignored);
  } while (::wait(&status) != -1);
  
  // Now check that all the response messages are present and accounted for.
  for (i = 0; i < NUMBER_MESSAGES; ++i) {
    NP1_TEST_ASSERT(
      worker_responses.find("x" + ::np1::str::to_dec_str(i)) != worker_responses.end());
  }  
}
Esempio n. 24
0
bool pawsBankWindow::OnButtonPressed( int mouseButton, int keyModifier, pawsWidget* widget )
{
    if(widget->GetID() == MONEYBUTTON)
    {
        Money->SetState(true);
        Admin->SetState(false);

        moneyWindow->Show();
        adminWindow->Hide();
    }

    if(widget->GetID() == ADMINBUTTON)
    {
        Money->SetState(false);
        Admin->SetState(true);

        moneyWindow->Hide();
        adminWindow->Show();
    }

    if(widget->GetID() == CIRCLESBUTTON)
    {
        octas->SetState(false);
        hexas->SetState(false);
        trias->SetState(false);
    }

    if(widget->GetID() == OCTASBUTTON)
    {
        circles->SetState(false);
        hexas->SetState(false);
        trias->SetState(false);
    }

    if(widget->GetID() == HEXASBUTTON)
    {
        circles->SetState(false);
        octas->SetState(false);
        trias->SetState(false);
    }

    if(widget->GetID() == TRIASBUTTON)
    {
        circles->SetState(false);
        octas->SetState(false);
        hexas->SetState(false);
    }

    if(widget->GetID() == WITHDRAW)
    {
        // Send request to server.
        int circles = 0;
        sscanf(circlesToWithdraw->GetText(), "%d", &circles);

        int octas = 0;
        sscanf(octasToWithdraw->GetText(), "%d", &octas);

        int hexas = 0;
        sscanf(hexasToWithdraw->GetText(), "%d", &hexas);

        int trias = 0;
        sscanf(triasToWithdraw->GetText(), "%d", &trias);

        psGUIBankingMessage outgoing(psGUIBankingMessage::WITHDRAWFUNDS,
                                     guild, circles, octas, hexas, trias);
        outgoing.SendMessage();

        // Reset to 0.
        circlesToWithdraw->SetText("0");
        octasToWithdraw->SetText("0");
        hexasToWithdraw->SetText("0");
        triasToWithdraw->SetText("0");

        return true;
    }

    if(widget->GetID() == DEPOSIT)
    {
        // Send request to server.
        int circles = 0;
        sscanf(circlesToDeposit->GetText(), "%d", &circles);

        int octas = 0;
        sscanf(octasToDeposit->GetText(), "%d", &octas);

        int hexas = 0;
        sscanf(hexasToDeposit->GetText(), "%d", &hexas);

        int trias = 0;
        sscanf(triasToDeposit->GetText(), "%d", &trias);


        psGUIBankingMessage outgoing(psGUIBankingMessage::DEPOSITFUNDS,
                                     guild, circles, octas, hexas, trias);
        outgoing.SendMessage();

        // Reset to 0.
        circlesToDeposit->SetText("0");
        octasToDeposit->SetText("0");
        hexasToDeposit->SetText("0");
        triasToDeposit->SetText("0");

        return true;
    }

    if(widget->GetID() == EXCHANGE)
    {
        // Send request to server.
        int coins = 0;
        sscanf(coinsToExchange->GetText(), "%d", &coins);

        int coin = -1;
        if(circles->GetState())
        {
            coin = 0;
            circles->SetState(false);
        }
        else if(octas->GetState())
        {
            coin = 1;
            octas->SetState(false);
        }
        else if(hexas->GetState())
        {
            coin = 2;
            hexas->SetState(false);
        }
        else if(trias->GetState())
        {
            coin = 3;
            trias->SetState(false);
        }

        if(coin != -1)
        {
            psGUIBankingMessage outgoing(psGUIBankingMessage::EXCHANGECOINS,
                                         guild, coins, coin);
            outgoing.SendMessage();
        }

        // Reset to 0.
        coinsToExchange->SetText("0");

        return true;
    }

    return false;
}
Esempio n. 25
0
    void operator()(const hypergraph_type& source, hypergraph_type& target)
    {
      if (! source.is_valid()) {
	target.clear();
	return;
      }
      
      target = source;

      edge_set_type outgoing(target.nodes.size());
      edge_set_type leaning(target.nodes.size());
      
      hypergraph_type::edge_set_type::const_iterator eiter_end = target.edges.end();
      for (hypergraph_type::edge_set_type::const_iterator eiter = target.edges.begin(); eiter != eiter_end; ++ eiter) {
	const edge_type& edge = *eiter;
	
	if (edge.tails.empty()) continue;
	
	int tail_pos = 0;
	rule_type::symbol_set_type::const_iterator riter_end = edge.rule->rhs.end();
	for (rule_type::symbol_set_type::const_iterator riter = edge.rule->rhs.begin(); riter != riter_end; ++ riter) 
	  if (riter->is_non_terminal()) {
	    const int __non_terminal_index = riter->non_terminal_index();
	    const int antecedent_index = utils::bithack::branch(__non_terminal_index <= 0, tail_pos, __non_terminal_index - 1);
	    
	    if (antecedent_index == 0)
	      leaning[edge.tails[tail_pos]].push_back(edge.id);
	    
	    outgoing[edge.tails[tail_pos]].push_back(edge.id);
	    
	    ++ tail_pos;
	  }
      }
      
      hypergraph_type::node_set_type::const_reverse_iterator niter_end = target.nodes.rend();
      for (hypergraph_type::node_set_type::const_reverse_iterator niter = target.nodes.rbegin(); niter != niter_end; ++ niter) {
	const hypergraph_type::node_type& node = *niter;
	
	// this should not happen, though..
	if (node.edges.empty()) continue;
	if (leaning[node.id].empty()) continue;
	
	if (outgoing[node.id].size() == 1) {
	  
	  if (! target.edges[outgoing[node.id].front()].features.empty()) {
	    const feature_set_type intersected(target.edges[outgoing[node.id].front()].features);
	    
	    node_type::edge_set_type::const_iterator eiter_end = node.edges.end();
	    for (node_type::edge_set_type::const_iterator eiter = node.edges.begin(); eiter != eiter_end; ++ eiter)
	      target.edges[*eiter].features += intersected;
	    
	    edge_list_type::const_iterator oiter_end = outgoing[node.id].end();
	    for (edge_list_type::const_iterator oiter = outgoing[node.id].begin(); oiter != oiter_end; ++ oiter)
	      target.edges[*oiter].features -= intersected;
	  }
	} else {
	  feature_set_type intersected(target.edges[outgoing[node.id].front()].features);
	    
	  edge_list_type::const_iterator oiter_end = outgoing[node.id].end();
	  for (edge_list_type::const_iterator oiter = outgoing[node.id].begin() + 1; oiter != oiter_end; ++ oiter)
	    intersected.intersect(target.edges[*oiter].features);

	  if (! intersected.empty()) {
	    edge_list_type::const_iterator oiter_end = outgoing[node.id].end();
	    for (edge_list_type::const_iterator oiter = outgoing[node.id].begin(); oiter != oiter_end; ++ oiter)
	      target.edges[*oiter].features -= intersected;
	      
	    node_type::edge_set_type::const_iterator eiter_end = node.edges.end();
	    for (node_type::edge_set_type::const_iterator eiter = node.edges.begin(); eiter != eiter_end; ++ eiter)
	      target.edges[*eiter].features += intersected;
	  }
	}
      }
    }