void MprisControlPlugin::seeked(qlonglong position){
    //qCDebug(KDECONNECT_PLUGIN_MPRIS) << "Seeked in player";
    NetworkPackage np(PACKAGE_TYPE_MPRIS);
    np.set("pos", position/1000); //Send milis instead of nanos
    OrgFreedesktopDBusPropertiesInterface* interface = (OrgFreedesktopDBusPropertiesInterface*)sender();
    const QString& service = interface->service();
    const QString& player = playerList.key(service);
    np.set("player", player);
    sendPackage(np);
}
示例#2
0
void Flowfield::draw () {
    for( int z = 0; z < flowList.size(); z++){
        for( int y = 0; y < flowList[z].size(); y++){
            for( int x=0; x<flowList[z][y].size(); x++){
                ofVec3f np( x*resolution, y*resolution, z*resolution );
                ofLine ( np, np+flowList[z][y][x] );
            }
        } 
    }
}
int main(int argc, char **argv) {
  ros::init(argc, argv,"feature_extraction");
  ros::NodeHandle n;
  ros::NodeHandle np("~");

  yagokoro_recognition::FeatureExtraction fe(n, np);

  ros::spin();

  return 0;
}
示例#4
0
// called from ---CPU--- thread
bool NetPlay::GetNetPads(const u8 pad_nb, const SPADStatus* const pad_status, NetPad* const netvalues)
{
	{
	std::lock_guard<std::recursive_mutex> lkp(m_crit.players);

	// in game mapping for this local pad
	unsigned int in_game_num = m_local_player->pad_map[pad_nb];

	// does this local pad map in game?
	if (in_game_num < 4)
	{
		NetPad np(pad_status);

		// adjust the buffer either up or down
		// inserting multiple padstates or dropping states
		while (m_pad_buffer[in_game_num].Size() <= m_target_buffer_size)
		{
			// add to buffer
			m_pad_buffer[in_game_num].Push(np);

			// send
			SendPadState(pad_nb, np);
		}
	}

	}	// unlock players

	//Common::Timer bufftimer;
	//bufftimer.Start();

	// get padstate from buffer and send to game
	while (!m_pad_buffer[pad_nb].Pop(*netvalues))
	{
		// wait for receiving thread to push some data
		Common::SleepCurrentThread(1);

		if (false == m_is_running)
			return false;

		// TODO: check the time of bufftimer here,
		// if it gets pretty high, ask the user if they want to disconnect

	}

	//u64 hangtime = bufftimer.GetTimeElapsed();
	//if (hangtime > 10)
	//{
	//	std::ostringstream ss;
	//	ss << "Pad " << (int)pad_nb << ": Had to wait " << hangtime << "ms for pad data. (increase pad Buffer maybe)";
	//	Core::DisplayMessage(ss.str(), 1000);
	//}

	return true;
}
示例#5
0
int main( int nargs , char *args[] ) {
  nestedParallel np( &nargs , &args );
  std::cout << "My rank = " << np.getMyRank() << "  ";
  std::cout << np.getMyDOTColor() << "  ";
  if( np.getMyDistributedMemoryMPIComm() != MPI_COMM_NULL )
    std::cout << " distributed node ";
  else
    std::cout << " non-dist node ";
  std::cout << "Shared memory mpi_comm_rank = " << np.getMyRankInSharedMemoryComm() << "\n";
  return 0;
}
示例#6
0
void testEnableIf()
{
    SimpleStruct s;
    s.x = 10;

    SimpleStruct* pCopy = copy(s);

    NonPodStruct np(2);
    NonPodStruct* pNonCopy = copy(np);

}
示例#7
0
uORB::DeviceNode *uORB::DeviceMaster::GetDeviceNode(const char *nodepath)
{
	uORB::DeviceNode *rc = nullptr;
	std::string np(nodepath);

	if (_node_map.find(np) != _node_map.end()) {
		rc = _node_map[np];
	}

	return rc;
}
示例#8
0
void graph::ucs(const std::string& v1, const std::string& v2, 
                std::ofstream& fp, std::ofstream& fl,
                double (graph::* cost_f) (unsigned, unsigned) const) const
{
    unsigned i1 = get_index(v1);
    unsigned i2 = get_index(v2);
    ucs_node_queue q;
    std::set<unsigned> e;
    std::vector<unsigned> t(1, i1);
    q.insert(ucs_node(i1, t, 0));
    while (!q.empty()) {
        ucs_node n = *q.begin();
        fl << m_names[n.m_vertex] << "\n";
        q.erase(q.begin());
        if (n.m_vertex == i2) {
            for (unsigned j = 0; j < n.m_path.size(); ++j) {
                fp << m_names[n.m_path[j]] << "\n";
            }
            return;
        }
        e.insert(n.m_vertex);
        std::vector<unsigned>::const_iterator i;
        for (i = m_adjacent_vertices[n.m_vertex].begin(); i != m_adjacent_vertices[n.m_vertex].end(); ++i) {
            if (e.find(*i) == e.end()) {
                ucs_node_queue::iterator qi = find_in_queue(q, *i);
                if (qi == q.end()) {
                    std::vector<unsigned> np(n.m_path);
                    np.push_back(*i);
                    q.insert(ucs_node(*i, np, n.m_cost + (this->*cost_f)(n.m_vertex, *i)));
                } else {
                    if (n.m_cost + (this->*cost_f)(n.m_vertex, *i) < qi->m_cost) {
                        q.erase(qi);
                        std::vector<unsigned> np(n.m_path);
                        np.push_back(*i);
                        q.insert(ucs_node(*i, np, n.m_cost + (this->*cost_f)(n.m_vertex, *i)));
                    }
                }
            }
        }
    }
}
static int
auth_user_pass_verify (struct plugin_context *context, struct plugin_per_client_context *pcc, const char *argv[], const char *envp[])
{
  if (context->test_deferred_auth)
    {
      /* get username/password from envp string array */
      const char *username = get_env ("username", envp);
      const char *password = get_env ("password", envp);

      /* get auth_control_file filename from envp string array*/
      const char *auth_control_file = get_env ("auth_control_file", envp);

      printf ("DEFER u='%s' p='%s' acf='%s'\n",
	      np(username),
	      np(password),
	      np(auth_control_file));

      /* Authenticate asynchronously in n seconds */
      if (auth_control_file)
	{
	  char buf[256];
	  int auth = 2;
	  sscanf (username, "%d", &auth);
	  snprintf (buf, sizeof(buf), "( sleep %d ; echo AUTH %s %d ; echo %d >%s ) &",
		    context->test_deferred_auth,
		    auth_control_file,
		    auth,
		    pcc->n_calls < auth,
		    auth_control_file);
	  printf ("%s\n", buf);
	  system (buf);
	  pcc->n_calls++;
	  return OPENVPN_PLUGIN_FUNC_DEFERRED;
	}
      else
	return OPENVPN_PLUGIN_FUNC_ERROR;
    }
  else
    return OPENVPN_PLUGIN_FUNC_SUCCESS;
}
示例#10
0
void MuseScore::registerPlugin(const QString& pluginPath)
      {
      QFileInfo np(pluginPath);
      QString baseName = np.baseName();

      foreach(QString s, plugins) {
            QFileInfo fi(s);
            if (fi.baseName() == baseName) {
                  if (MScore::debugMode)
                        qDebug("  Plugin <%s> already registered\n", qPrintable(pluginPath));
                  return;
                  }
            }
示例#11
0
int main(int argc, char * argv[]){

    ros::init(argc, argv, "nice_predictor");

    ros::NodeHandle n;

    nice_predictor::NicePredictor np(n);

    np.nodeLoop();

    return 0;

}
示例#12
0
uORB::DeviceNode *uORB::DeviceMaster::GetDeviceNode(const char *nodepath)
{
	uORB::DeviceNode *rc = nullptr;
	std::string np(nodepath);

	auto iter = _node_map.find(np);

	if (iter != _node_map.end()) {
		rc = iter->second;
	}

	return rc;
}
void NodelControlReceiverTest::run() throw(std::runtime_error)
{
  ModelControlSenderNet mcsn;
  DummyReceiver bla;
  MyNetProtocol np(mcsn);
  ModelControlReceiverNet mcrn(np);
		
  mcsn.registerModelControlReceiver(bla);	

  mcrn.addModule("testname");
  if (bla.name != "testname")
	  throw std::runtime_error("Wrong error (?)"); 
		
}	
//I'm in a new network, let's be polite and introduce myself
void LanLinkProvider::onNetworkChange()
{
    if (!mTcpServer->isListening()) {
        //Not started
        return;
    }

    Q_ASSERT(mTcpPort != 0);

    qCDebug(KDECONNECT_CORE()) << "Broadcasting identity packet";
    NetworkPackage np("");
    NetworkPackage::createIdentityPackage(&np);
    np.set("tcpPort", mTcpPort);
    mUdpSocket.writeDatagram(np.serialize(), QHostAddress("255.255.255.255"), port);
}
示例#15
0
文件: grid.hpp 项目: mbaptist/eke
  const IV nearest_point_index(const RV & coord)
  { 
#if 0
	IV np(static_cast<int>(floor((coord[0]+.5*lx_)/deltax_)),
               static_cast<int>(floor((coord[1]+.5*ly_)/deltay_)),
               static_cast<int>(floor((coord[2]+.5*lz_)/deltaz_)));
	RV dist=coord-coordinates(np[0],np[1],np[2]);
	for(int n=0;n<3;++n)
		if(dist[n]>=.5*deltal(n))
			np[n]+=1;
	return np;
#endif
   return IV(static_cast<int>(round((coord[0]+.5*lx_)/deltax_))%nx_,
               static_cast<int>(round((coord[1]+.5*ly_)/deltay_))%ny_,
              static_cast<int>(round((coord[2]+.5*lz_)/deltaz_))%nz_);
  };
示例#16
0
void MuseScore::registerPlugin(PluginDescription* plugin)
      {
      QString pluginPath = plugin->path;
      QFileInfo np(pluginPath);
      if (np.suffix() != "qml")
            return;
      QString baseName = np.baseName();

      foreach(QString s, plugins) {
            QFileInfo fi(s);
            if (fi.baseName() == baseName) {
                  if (MScore::debugMode)
                        qDebug("  Plugin <%s> already registered\n", qPrintable(pluginPath));
                  return;
                  }
            }
示例#17
0
void handle::pivot(float f, ofVec2f p, ofVec2f t, string jType, string actor){

    ofVec2f np(m_posC);

    if(jType == "weld"){

        np = m_posC.getRotated(f, p, ofVec3f(0,0,1));
        t.set(np - m_posC);
        m_posC.set(np);
        m_rotC += f;

    }else if(jType == "pivot"){
        if(m_posC != p){
            m_posC += t;
        }
    }

    //recursive function call on children
    vector <handleJoint>::iterator it = m_children.begin();

    while(it != m_children.end()){
        if(it->m_handle->getIndex() == actor){++it; continue;} //actor is to prevent double calls
        if(it->m_type == "free"){++it; continue;}
        if(jType == "weld" &&  it->m_type == "weld"){
            it->m_handle->pivot(f, p, t, "weld", m_index);
        }else if(jType == "pivot" || it->m_type == "pivot"){
            if(m_posC != p)it->m_handle->pivot(f, p, t, "pivot", m_index);
        }
        ++it;
    }

    //pivot the parent
    if(m_parent){
        if(actor != m_parent->getIndex()){

            handleJoint hj = m_parent->getChildJoint(m_index);

            if(jType == "weld" &&  hj.m_type == "weld"){
                m_parent->pivot(f, p, t, "weld", m_index);
            }else if(jType == "pivot" || hj.m_type == "pivot"){
                if(m_posC != p)m_parent->pivot(f, p, t, "pivot", m_index);
            }

        }
    }

}
示例#18
0
文件: pf.c 项目: benjdag/openvpn
void
pf_context_print(const struct pf_context *pfc, const char *prefix, const int lev)
{
    msg(lev, "----- %s : struct pf_context -----", prefix);
    if (pfc)
    {
        msg(lev, "enabled=%d", pfc->enabled);
#ifdef PLUGIN_PF
        msg(lev, "filename='%s'", np(pfc->filename));
        msg(lev, "file_last_mod=%u", (unsigned int)pfc->file_last_mod);
        msg(lev, "n_check_reload=%u", pfc->n_check_reload);
        msg(lev, "reload=[%d,%u,%u]", pfc->reload.defined, pfc->reload.n, (unsigned int)pfc->reload.last);
#endif
        pf_set_print(pfc->pfs, lev);
    }
    msg(lev, "--------------------");
}
示例#19
0
//**********************************************
void Photon_map :: irradiance_estimate(
  float irrad[3],                // returned irradiance
  const float pos[3],            // surface position
  const float normal[3],         // surface normal at pos
  const float max_dist,          // max distance to look for photons
  const int nphotons ) const     // number of photons to use
//**********************************************
{
  irrad[0] = irrad[1] = irrad[2] = 0.0;

  NearestPhotons np(nphotons+1);

  np.pos[0] = pos[0]; np.pos[1] = pos[1]; np.pos[2] = pos[2];
  np.max = nphotons;
  np.found = 0;
  np.got_heap = 0;
  np.dist2[0] = max_dist*max_dist;

  // locate the nearest photons
  locate_photons( &np, 1 );

  // if less than 8 photons return
  if (np.found<8)
    return;

  float pdir[3];

  // sum irradiance from all photons
  for (int i=1; i<=np.found; i++) {
    const Photon *p = np.index[i];
    // the photon_dir call and following if can be omitted (for speed)
    // if the scene does not have any thin surfaces
    photon_dir( pdir, p );
    if ( (pdir[0]*normal[0]+pdir[1]*normal[1]+pdir[2]*normal[2]) < 0.0f ) {
      irrad[0] += p->power[0];
      irrad[1] += p->power[1];
      irrad[2] += p->power[2];
    }
  }

  const float tmp=(1.0f/M_PI)/(np.dist2[0]);  // estimate of density

  irrad[0] *= tmp;
  irrad[1] *= tmp;
  irrad[2] *= tmp;
}
int main(void)
{
    int flag;
    while(scanf("%d",&num)!=EOF)
    {
        flag=np(1);
        if(1==flag)
        {
            printf("Stan wins.\n");
        }
        else
        {
            printf("Ollie wins.\n");
        }
    }
return 0;
}
示例#21
0
std::vector<double> PMFFilter::morphOpen(PointViewPtr view, float radius)
{
    point_count_t np(view->size());

    KD2Index index(*view);
    index.build();

    std::vector<double> minZ(np), maxZ(np);
    typedef std::vector<PointId> PointIdVec;
    std::map<PointId, PointIdVec> neighborMap;

    // erode
    for (PointId i = 0; i < np; ++i)
    {
        double x = view->getFieldAs<double>(Dimension::Id::X, i);
        double y = view->getFieldAs<double>(Dimension::Id::Y, i);
        auto ids = index.radius(x, y, radius);

        // neighborMap.insert(std::pair<PointId, std::vector<PointId>(i, ids));
        neighborMap[i] = ids;
        double localMin(std::numeric_limits<double>::max());
        for (auto const& j : ids)
        {
            double z = view->getFieldAs<double>(Dimension::Id::Z, j);
            if (z < localMin)
                localMin = z;
        }
        minZ[i] = localMin;
    }

    // dilate
    for (PointId i = 0; i < np; ++i)
    {
        auto ids = neighborMap[i];
        double localMax(std::numeric_limits<double>::lowest());
        for (auto const& j : ids)
        {
            double z = minZ[j];
            if (z > localMax)
                localMax = z;
        }
        maxZ[i] = localMax;
    }

    return maxZ;
}
示例#22
0
cv::Mat EyeTracker::floodKillEdges(cv::Mat& mat) {
    cv::rectangle(mat, cv::Rect(0, 0, mat.cols, mat.rows), 255);
    cv::Mat mask(mat.rows, mat.cols, CV_8U, 255);
    std::queue<cv::Point> to_do;
    to_do.push(cv::Point(0, 0));
    
    auto should_push = [&](cv::Point p) {
        return p.x >= 0 && p.x < mat.cols && p.y >= 0 && p.y < mat.rows;
    };
    
    while (!to_do.empty()) {
        cv::Point p = to_do.front();
        to_do.pop();
        if (mat.at<float>(p) == 0.0f) {
            continue;
        }
        
        // right
        cv::Point np(p.x + 1, p.y);
        if (should_push(np))
            to_do.push(np);
            
        // left
        np.x = p.x - 1;
        np.y = p.y;
        if (should_push(np))
            to_do.push(np);
            
        // down
        np.x = p.x;
        np.y = p.y - 1;
        if (should_push(np))
            to_do.push(np);
            
        // up
        np.x = p.x;
        np.y = p.y + 1;
        if (should_push(np))
            to_do.push(np);
            
        mat.at<float>(p) = 0.0f;
        mask.at<uchar>(p) = 0;
    }
    return mask;
}
void FlowField::addCircularForce(float x, float y, float radius, float strength) {
    ofVec2f mousePos(x, y);
    
    for( int y=0; y<flowList.size(); y++){
        for( int x=0; x<flowList[y].size(); x++){
            ofVec2f np( x*resolution, y*resolution );
            
            if( np.distance(mousePos) < radius ){
                float pct = 1 - (np.distance(mousePos) / radius);
                
                // add strength towards the mouse
                ofVec2f dir = (np - mousePos);
                flowList[y][x].x -= dir.normalized().y * strength;
                flowList[y][x].y += dir.normalized().x * strength;
            }
        }
    }
}
示例#24
0
void graph::dfs(unsigned i1, unsigned i2, std::ofstream& fl, const std::vector<unsigned>& path, std::vector<unsigned>& found_path) const
{
    fl << m_names[i1] << "\n";
    if (i1 == i2) {
        if (found_path.empty() || cost(found_path) > cost(path)) {
            found_path = path;
        }
        return;
    }
    std::vector<unsigned>::const_reverse_iterator i;
    for (i = m_adjacent_vertices[i1].rbegin(); i != m_adjacent_vertices[i1].rend(); ++i) {
        if(std::find(path.begin(), path.end(), *i) == path.end()) {
            std::vector<unsigned> np(path);
            np.push_back(*i);
            dfs(*i, i2, fl, np, found_path);
        }
    }
}
示例#25
0
文件: qnapi.cpp 项目: konserw/Qnapi
QNapiComplexResult QNapi::bazinga(const QString& movie)
{
    QNapiComplexResult res(movie);

    QNapiProjektEngine np(movie, m_lang);
    res.setNp(np.process());

    //qDebug() << movie << "\t|NapiProjekt:\t" << f;

    if(res.np() != success)
    {
        QOpenSubtitlesEngine os(movie, m_lang);
        res.setOs(os.process());
   //     qDebug() << movie << "\t|OpenSubs:\t" << f;
    }

    return res;
}
void LanLinkProvider::connectError()
{
    QSslSocket* socket = qobject_cast<QSslSocket*>(sender());
    if (!socket) return;
    disconnect(socket, SIGNAL(connected()), this, SLOT(connected()));
    disconnect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectError()));

    qCDebug(KDECONNECT_CORE) << "Fallback (1), try reverse connection (send udp packet)" << socket->errorString();
    NetworkPackage np("");
    NetworkPackage::createIdentityPackage(&np);
    np.set("tcpPort", mTcpPort);
    mUdpSocket.writeDatagram(np.serialize(), receivedIdentityPackages[socket].sender, port);

    //The socket we created didn't work, and we didn't manage
    //to create a LanDeviceLink from it, deleting everything.
    delete receivedIdentityPackages.take(socket).np;
    delete socket;
}
示例#27
0
void generate_bfs(bool** upper,bool** left,Point p,bool** visited,int m,int n,int depth){
    queue<Point> pq; //store the visited points in current level
    pq.push(p);
    visited[p.r][p.c]=true;
    int arr[]={0,1,2,3};

    while(!pq.empty()){
        int size=pq.size();
        cout<<"size: "<<size<<endl;
        while(size--)
        {
            Point p=pq.front();
            
            shuffle(arr);
            for(int i=0;i<4;i++)
            {
                int d=arr[i];
                //for each point, walk depth steps
                int dps=depth;
                Point np(p.r,p.c);
                while(dps)
                {
                    dps--;
                    np.r+=dr[d];
                    np.c+=dc[d];
                
                    
                    if(np.r>=0 && np.r<m && np.c>=0 && np.c<n && !visited[np.r][np.c])
                    {
                        visited[np.r][np.c]=true;
//                    if(dps==0)
                        pq.push(np);
                        carve(upper, left, np.r, np.c, d);
                    }else
                        break;
                    d=rand()%4;
                }//while
            }//for
            pq.pop();
        }
    }
    
}
示例#28
0
void NodeImporter::importCities(const std::string& seedString) {
    /*
      READ CITY POSITIONS ON EARTH SURFACE
    */
    Config_Ptr config(new Config);

    Config_Ptr cityFilterConfig(config->subConfig("cityfilter"));
    int populationThreshold = cityFilterConfig->get<int>("citysizethreshold");

    auto lr = std::make_shared<SQLiteLocationReader>(_dbFilename, populationThreshold);

    typedef std::map<std::string, std::vector<CityNode>> CountryMap;
    std::unique_ptr<CountryMap> countries(new CountryMap);

    while (lr->hasNext()) {
        CityNode next = lr->getNext();
        (*countries)[next.country()].push_back(next);
    }

    std::unique_ptr<InternetUsageStatistics> stat(new InternetUsageStatistics(_dbFilename));

    typedef std::mt19937_64 RNG;
    std::seed_seq seed(seedString.begin(), seedString.end());
    std::unique_ptr<RNG> randGen(new RNG);
    randGen->seed(seed);
    std::uniform_real_distribution<double> dist(0.0, 1.0);

    // filter cities
    for (auto country : *countries) {
        std::string countryName = country.first;
        auto& cityVec = country.second;
        double percentInetUsers = (*stat)[countryName] / 100.0;

        for (auto city : cityVec)
            if (dist(*randGen) <= percentInetUsers) {
                city.setId(_nodenumber);
                ++_nodenumber;
                GeographicNode_Ptr np(new CityNode(city));
                addNode(np);
            }
    }
}
void FlowField::addRepelForce(float x, float y, float radius, float strength) {
    ofVec2f mousePos(x, y);
    
    for( int y=0; y<flowList.size(); y++){
        for( int x=0; x<flowList[y].size(); x++){
            ofVec2f np( x*resolution, y*resolution );
            
            if( np.distance(mousePos) < radius ){
                float pct = 1 - (np.distance(mousePos) / radius);
                
                // add strength in the direction it's already moving in
//                flowList[y][x] += flowList[y][x].normalized() * strength;
                
                // add strength away from the mouse
                ofVec2f dir = (np - mousePos);
                flowList[y][x] += dir.normalized() * strength;
            }
        }
    }
}
示例#30
0
//I'm in a new network, let's be polite and introduce myself
void LanLinkProvider::broadcastToNetwork()
{

    if (!mServer->isListening()) {
        //Not started
        return;
    }

    Q_ASSERT(mTcpPort != 0);

    qCDebug(KDECONNECT_CORE()) << "Broadcasting identity packet";

    QHostAddress destAddress = mTestMode? QHostAddress::LocalHost : QHostAddress(QStringLiteral("255.255.255.255"));

    NetworkPackage np(QLatin1String(""));
    NetworkPackage::createIdentityPackage(&np);
    np.set(QStringLiteral("tcpPort"), mTcpPort);

#ifdef Q_OS_WIN
    //On Windows we need to broadcast from every local IP address to reach all networks
    QUdpSocket sendSocket;
    for (const QNetworkInterface &iface : QNetworkInterface::allInterfaces()) {
        if ( (iface.flags() & QNetworkInterface::IsUp)
          && (iface.flags() & QNetworkInterface::IsRunning)
          && (iface.flags() & QNetworkInterface::CanBroadcast)) {
            for (const QNetworkAddressEntry &ifaceAddress : iface.addressEntries()) {
                QHostAddress sourceAddress = ifaceAddress.ip();
                if (sourceAddress.protocol() == QAbstractSocket::IPv4Protocol && sourceAddress != QHostAddress::LocalHost) {
                    qCDebug(KDECONNECT_CORE()) << "Broadcasting as" << sourceAddress;
                    sendSocket.bind(sourceAddress, PORT);
                    sendSocket.writeDatagram(np.serialize(), destAddress, PORT);
                    sendSocket.close();
                }
            }
        }
    }
#else
    mUdpSocket.writeDatagram(np.serialize(), destAddress, PORT);
#endif

}