Exemplo n.º 1
0
static void identity_info_cb(SignonIdentity *self, const SignonIdentityInfo *info, const GError *error, gpointer user_data)
{
     if (error)
     {
        g_warning ("%s: Error: %s ", __func__, error->message);
        fail_if (info != NULL, "Error: %s ", error->message);
        g_main_loop_quit(main_loop);
        return;
     }

     g_warning ("No error");

     SignonIdentityInfo **pattern_ptr = (SignonIdentityInfo **)user_data;
     SignonIdentityInfo *pattern = NULL;

     if (pattern_ptr)
         pattern = (*pattern_ptr);

     if (pattern == NULL)
         fail_unless (info == NULL, "The info must be NULL");
     else
     {
         fail_unless (info != NULL, "The info must be non-null");
         fail_unless (g_strcmp0 (signon_identity_info_get_username(info),
                                 signon_identity_info_get_username(pattern)) == 0, "The info has wrong username");
         fail_unless (g_strcmp0 (signon_identity_info_get_caption(info),
                                 signon_identity_info_get_caption(pattern)) == 0, "The info has wrong caption");

         GHashTable *methods = (GHashTable *)signon_identity_info_get_methods (info);
         gchar **mechs1 = g_hash_table_lookup (methods, "method1");
         gchar **mechs2 = g_hash_table_lookup (methods, "method2");
         gchar **mechs3 = g_hash_table_lookup (methods, "method3");

         fail_unless (g_strv_length (mechs1) == 3);
         fail_unless (g_strv_length (mechs2) == 3);
         fail_unless (g_strv_length (mechs3) == 3);

         fail_unless (_contains(mechs1, "mechanism1"));
         fail_unless (_contains(mechs1, "mechanism2"));
         fail_unless (_contains(mechs1, "mechanism3"));

         fail_unless (_contains(mechs2, "mechanism1"));
         fail_unless (_contains(mechs2, "mechanism2"));
         fail_unless (_contains(mechs2, "mechanism3"));

         fail_unless (_contains(mechs3, "mechanism1"));
         fail_unless (_contains(mechs3, "mechanism2"));
         fail_unless (_contains(mechs3, "mechanism3"));
     }

     if (info)
     {
         signon_identity_info_free (pattern);
         *pattern_ptr = signon_identity_info_copy (info);
     }

     g_main_loop_quit(main_loop);
}
Exemplo n.º 2
0
bool AVLTree::_contains(string& data, AVLNode*& node)
{
    if (node == nullptr) return false;
    else if (node->data->getWord() == data) return true;
    else
    {
        if (data > node->data->getWord())
            return _contains(data, node->right);
        else
            return _contains(data, node->left);
    }
}
Exemplo n.º 3
0
bool AVLTree::contains(string& data)
{
    if (root == nullptr) return false;
    else if (root->data->getWord() == data) return true;
    else
    {
        if (data > root->data->getWord())
        {
            return _contains(data, root->right);
        }
        else
        {
            return _contains(data, root->left);
        }
    }
}
Exemplo n.º 4
0
int _remove(PriorityList * plist, Task * task) {

    if (!plist->priorities)
        return 0;

    TPriority * p = _contains(plist->priorities, task->priority);

    if (!p)
        return 0;

    TQueue * q = initializeq();

    while (!emptyq(p->tasks)) {
        Task * temp = pop(p->tasks);
        if (temp != task)
            push(q, temp);
    }



    if (emptyq(q)) {
        _removepriority(plist, p);
        q = NULL;
    }

    p->tasks = q;

    return 1;

}
Exemplo n.º 5
0
int _contains(Leaf *leaf, int item) {
  // Uses recursion to test for containment.
  int result;

  if(leaf == NULL)
    return 0;

  if(item == leaf->data)
    result = 1;
  else if(item < leaf->data)
    result = _contains(leaf->left, item);
  else
    result = _contains(leaf->right, item);

  return result;
}
Exemplo n.º 6
0
int contains(Tree *tree, int item) {
  // Determines if 'item' is in the given Tree.
  int result = 0;

  if(tree != NULL)
    result = _contains(tree->root, item);
  
  return result;    
}
Exemplo n.º 7
0
Arquivo: rrg.cpp Projeto: dqyi11/RRG
void RRG::extend() {
    bool node_inserted = false;
    while( false==node_inserted ) {
        POS2D rnd_pos = _sampling();
        KDNode2D nearest_node = _find_nearest( rnd_pos );

        if (rnd_pos[0]==nearest_node[0] && rnd_pos[1]==nearest_node[1]) {
            continue;
        }

        POS2D new_pos = _steer( rnd_pos, nearest_node );

        if( true == _contains(new_pos) ) {
            continue;
        }
        if( true == _is_in_obstacle( new_pos ) ) {
            continue;
        }

        if( true == _is_obstacle_free( nearest_node, new_pos ) ) {
            std::list<KDNode2D> near_list = _find_near( new_pos );
            KDNode2D new_node( new_pos );

            // create new node
            RRGNode * p_new_rnode = _create_new_node( new_pos );
            new_node.setRRGNode( p_new_rnode );

            _p_kd_tree->insert( new_node );
            node_inserted = true;

            RRGNode* p_nearest_rnode = nearest_node.getRRGNode();
            std::list<RRGNode*> near_rnodes;
            near_rnodes.clear();
            for( std::list<KDNode2D>::iterator itr = near_list.begin();
                itr != near_list.end(); itr++ ) {
                KDNode2D kd_node = (*itr);
                RRGNode* p_near_rnode = kd_node.getRRGNode();
                near_rnodes.push_back( p_near_rnode );
            }

            // attach new node to reference trees
            _attach_new_node( p_new_rnode, p_nearest_rnode, near_rnodes );
            // rewire near nodes of reference trees
            _rewire_near_nodes( p_new_rnode, near_rnodes );
        }
    }
    _current_iteration++;
}
Exemplo n.º 8
0
void _insert(PriorityList * plist, Task * task) {//insere ordenado

    if (!plist->priorities) {

        TPriority * p = _create(task->priority);
        push(p->tasks, task);
        plist->priorities = p;

    } else {

        TPriority * p = _contains(plist->priorities, task->priority);

        if (p)
            push(p->tasks, task);
        else {

            TPriority * tmp = plist->priorities;
            TPriority * ant = NULL;

            while (tmp && tmp->priority < task->priority) {
                ant = tmp;
                tmp = tmp->next;
            }

            p = _create(task->priority);
            push(p->tasks, task);

            if (ant) {
                ant->next = p;
                p->next = tmp;
            } else {
                p->next = tmp;
                plist->priorities = p;
            }
        }
    }
}
Exemplo n.º 9
0
 bool contains(const __Key& _Key) { return _contains(const_cast<__Key&>(_Key)); }
Exemplo n.º 10
0
 bool contains(__Key& _Key) { return _contains(_Key); }
void events::run()
{
	m_running = true ;
	m_mtoto   = this ;

	connect( m_mtoto,SIGNAL( finished() ),m_main,SLOT( threadStopped() ) ) ;
	connect( m_mtoto,SIGNAL( finished() ),m_mtoto,SLOT( deleteLater() ) ) ;

	connect( this,SIGNAL( volumeMiniProperties( volumeEntryProperties * ) ),
		 m_babu,SLOT( autoMountVolume( volumeEntryProperties * ) ) ) ;
	connect( this,SIGNAL( volumeRemoved( QString ) ),
		 m_babu,SLOT( volumeRemoved( QString ) ) ) ;

	utility::fileHandle f( inotify_init() ) ;

	int fd = f.handle() ;

	if( fd == -1 ){

		return this->failedToStart() ;
	}

	int dev = inotify_add_watch( fd,"/dev",IN_CREATE|IN_DELETE ) ;
	int dm  = inotify_add_watch( fd,"/dev/mapper",IN_CREATE|IN_DELETE ) ;
	int md  = -1 ;

	if( utility::pathExists( "/dev/dm" ) ){

		md = inotify_add_watch( fd,"/dev/md",IN_DELETE ) ;
	}

	auto _allowed_device = []( const char * device ){

		/*
		 * dont care about these devices.
		 * /dev/sgX seem to be created when a usb device is plugged in
		 * /dev/dm-X are dm devices we dont care about since we will be dealing with them differently
		 */
		bool s = _startsWith( device,"sg" )     ||
			 _startsWith( device,"dm-" )    ||
			 _contains( device,"dev/tmp" )  ||
			 _contains( device,"dev-tmp" )  ||
			 _contains( device,".tmp.md." ) ||
			 _contains( device,"md/md-device-map" ) ;

		return s == false ;
	} ;

	auto _device_action = [&]( const struct inotify_event * event ){

		/*
		 * /dev/md/ folder seem to be deleted when the last entry in it is removed and
		 * created before the first entry is added.To account for this,monitor for the
		 * folder creation to start monitoring its contents.
		 */

		if( event->wd == dev && event->mask & IN_CREATE ){

			if( _stringsAreEqual( "md",event->name ) ){

				md = inotify_add_watch( fd,"/dev/md",IN_DELETE ) ;

				return false ;
			}
		}

		if( event->wd == dev && event->mask & IN_DELETE ){

			if( _stringsAreEqual( "md",event->name ) ){

				inotify_rm_watch( md,dev ) ;

				return false ;
			}
		}

		return true ;
	} ;

	const char * currentEvent ;
	const char * end ;

	constexpr int BUFF_SIZE = 4096 ;
	char buffer[ BUFF_SIZE ] ;

	fd_set rfds ;

	FD_ZERO( &rfds ) ;

	int select_fd = fd + 1 ;

	auto _eventsReceived = [ & ](){

		/*
		 * we are blocking on select() and not on read() because QThread->terminate() does not seem to
		 * be able to get out of a blocked read() on certain Qt versions.
		 */

		auto _gotEvents = [ & ](){

			FD_SET( fd,&rfds ) ;

			return select( select_fd,&rfds,nullptr,nullptr,nullptr ) > 0 ;
		} ;

		if( _gotEvents() ){

			auto s = read( fd,buffer,BUFF_SIZE ) ;

			if( s > 0 ){

				end          = buffer + s ;
				currentEvent = buffer ;

				return true ;
			}
		}

		return false ;
	} ;

	auto _processEvent = [ & ]( const struct inotify_event * event ){

		if( _device_action( event ) && _allowed_device( event->name ) ){

			auto _device = [ & ](){

				if( event->wd == dm ){

					return zuluMountTask::devices::dm_device ;

				}else if( event->wd == md ){

					return zuluMountTask::devices::md_device ;

				}else{
					return zuluMountTask::devices::device ;
				}
			} ;

			zuluMountTask::event e{ _device(),event->mask == IN_CREATE,event->name } ;

			Task::exec( [ this,e ](){

				auto r = zuluMountTask::deviceProperties( e ) ;

				if( r.volumeRemoved ){

					emit volumeRemoved( r.volumeName ) ;
				}else{
					emit volumeMiniProperties( r.entry ) ;
				}
			} ) ;
		}
	} ;

	#define _cast( x ) reinterpret_cast< const struct inotify_event * >( currentEvent )
	#define _eventSize sizeof( struct inotify_event )

	while( true ){

		if( _eventsReceived() ){

			while( currentEvent < end ){

				auto event = _cast( currentEvent ) ;

				if( event ){

					_processEvent( event ) ;
					currentEvent += _eventSize + event->len ;
				}else{
					currentEvent += _eventSize ;
				}
			}
		}
	}
}