Ejemplo n.º 1
0
	/** set the first half face handle of the hedron */
	void TopologyKernel::set_first_half_face_handle(const HedronHandle & _hh, const HalfFaceHandle & _hfh)
	{
		if (is_valid_handle(_hh) && is_valid_handle(_hfh))
		{
			hedrons_[_hh].hfh_ = _hfh;
		}
		
	}
Ejemplo n.º 2
0
	/** check if the input half face has opposite half face */
	bool TopologyKernel::has_opposite_half_face(const HalfFaceHandle & _hfh) const 
	{
		if (is_valid_handle(_hfh))
		{
			return (is_valid_handle(half_face(_hfh).opp_hfh_));
		}
		return false;
	}
Ejemplo n.º 3
0
	/** check if the input half edge has opposite half edge */
	bool TopologyKernel::has_opposite_half_edge(const HalfEdgeHandle & _heh) const 
	{
		if (is_valid_handle(_heh))
		{
			return (is_valid_handle(half_edge(_heh).opp_heh_));
		}
		return false;
	}
Ejemplo n.º 4
0
	/** set the opposite half edge handle */
	void TopologyKernel::set_ccw_opposite_half_edge(const HalfEdgeHandle & _heh, const HalfEdgeHandle & _ohfh, bool _double /* = true */)
	{
		if (is_valid_handle(_heh))
		{
			half_edge(_heh).opp_heh_ = _ohfh;
		}
		if (is_valid_handle(_ohfh) && _double)
		{
			half_edge(_ohfh).opp_heh_ = _heh;
		}
	}
Ejemplo n.º 5
0
	/** set the opposite half face handle */
	void TopologyKernel::set_opposite_half_face(const HalfFaceHandle & _hfh, const HalfFaceHandle & _ohfh, bool _double /* = true */)
	{
		if (is_valid_handle(_hfh))
		{
			half_face(_hfh).opp_hfh_ = _ohfh;
		}
		if (is_valid_handle(_ohfh) && _double)
		{
			half_face(_ohfh).opp_hfh_ = _hfh;
		}		
	}
Ejemplo n.º 6
0
bool zz_thread::thread_start ()
{
#ifdef ZZ_MULTI_THREAD
	if (is_valid_handle(handle_)) return true;

	handle_ = (HANDLE)_beginthreadex(NULL, 0, call_thread_proc , (void*)this, 0, (unsigned int*)&thread_id_);
	assert(is_valid_handle(handle_));
	return is_valid_handle(handle_);
#else
	return false;
#endif
}
Ejemplo n.º 7
0
/******************************************************************************
 *  release_handle
 *
 * Releases resources occupied by the specified handle in the given table.
 * The reference count of the handled object is decremented. If it becomes
 * zero and if the 'destructor' function pointer member is non NULL, the
 * destructor function will be called. Note that release_handle does not 
 * release resources other than the handle itself. If this is wanted, do it
 * in the destructor function.
 *
 * PARAMS
 *  lpTable [I] Pointer to the handle table, from which a handle is to be 
 *              released.
 *  handle  [I] The handle, which is to be released
 *  dwType  [I] Identifier for the type of the object, for which a handle is
 *              to be released.
 *
 * RETURNS
 *  non zero,  if successful
 *  zero,      if not successful (invalid handle)
 */
int release_handle(HANDLETABLE *lpTable, unsigned int handle, DWORD dwType)
{
    unsigned int index = HANDLE2INDEX(handle);
    OBJECTHDR *pObject;
    int ret = 0;

    TRACE("(lpTable=%p, hande=%d)\n", lpTable, handle);
    
    EnterCriticalSection(&lpTable->mutex);
    
    if (!is_valid_handle(lpTable, handle, dwType))
        goto exit;

    pObject = lpTable->paEntries[index].pObject;
    if (InterlockedDecrement(&pObject->refcount) == 0)
    {
        TRACE("destroying handle %d\n", handle);
        if (pObject->destructor)
            pObject->destructor(pObject);
    }

    lpTable->paEntries[index].pObject = NULL;
    lpTable->paEntries[index].iNextFree = lpTable->iFirstFree;
    lpTable->iFirstFree = index;
   
    ret = 1;
exit:
    LeaveCriticalSection(&lpTable->mutex);
    return ret;
}
Ejemplo n.º 8
0
	/** set the half face handle for half edge */
	void TopologyKernel::set_half_face(const HalfEdgeHandle & _heh, const HalfFaceHandle & _hfh)
	{
		if (is_valid_handle(_heh))
		{
			half_edge(_heh).fh_ = _hfh;
		}
	}
Ejemplo n.º 9
0
void GLMeshRendererFactory::free_mesh_renderer(RendererHandle handle)
{
    // Invalid handle, nothing to free
    if (!is_valid_handle(handle))
        return;

    if (renderers_[handle]) // valid non-null renderer, needs to be freed
    {
        delete renderers_[handle];
        renderers_[handle] = NULL;

        if (renderers_for_vpm_[handle])
        {
            delete renderers_for_vpm_[handle];
            renderers_for_vpm_[handle] = NULL;
        }

        if (meshes_[handle])
        {
            delete meshes_[handle];
            meshes_[handle] = NULL;
        }

        free_handles_.push_back(handle);
    }
}
Ejemplo n.º 10
0
	/** set the half edge handle for vertex */
	void TopologyKernel::set_vertex_half_edge(const VertexHandle & _vh, const HalfEdgeHandle & _heh)
	{
		if (is_valid_handle(_vh))
		{
			vertex(_vh).heh_ = _heh;
		}
	}
Ejemplo n.º 11
0
IMeshRenderer* GLMeshRendererFactory::get_renderer(RendererHandle handle)
{
    if (!is_valid_handle(handle))
        return NULL;
    else
        return renderers_[handle];
}
Ejemplo n.º 12
0
	/** retrieve the half face handle of a half edge */
	HalfFaceHandle TopologyKernel::half_face_handle(const HalfEdgeHandle & _heh) const
	{
		if (is_valid_handle(_heh))
		{
			return half_edge(_heh).fh_;
		}
		return HalfFaceHandle(-1);
	}
Ejemplo n.º 13
0
bool zz_thread::thread_resume () {
#ifdef ZZ_MULTI_THREAD
	if (!is_valid_handle(handle_)) return false; // not started
	return (::ResumeThread(handle_) != ((DWORD)-1));
#else
	return false;
#endif
}
Ejemplo n.º 14
0
void
tmout_destroy (timeout_t handle)
{
	assert (is_valid_handle (handle));

	dtable_remove ((void **)&table_, &table_used_, handle,
	               (unused_setter_t)set_unused);
}
Ejemplo n.º 15
0
	/** retrieve the opposite half edge handle */
	HalfEdgeHandle TopologyKernel::ccw_opp_half_edge_handle(const HalfEdgeHandle & _heh)  const
	{
		if (is_valid_handle(_heh))
		{
			return half_edge(_heh).opp_heh_;
		}
		return HalfEdgeHandle(-1);
	}
Ejemplo n.º 16
0
/*
*	execute the 'index' procedure
*/
int		sblib_proc_exec(int index, int param_count, slib_par_t *params, var_t *retval)
{
	int		success = 0;
	int		handle;

	switch ( index )	{
	case	0:	// GDBM_CLOSE handle
		success = mod_parint(0, params, param_count, &handle);
		if	( success )	{
			if	( is_valid_handle(handle) )	{
				gdbm_close(table[handle].dbf);
				table[handle].dbf = NULL;
				success = 1;
				}
			else	{
				success = 0;
				v_setstr(retval, "GDBM_CLOSE: INVALID HANDLE");
				}
			}
		else
			v_setstr(retval, "GDBM_CLOSE: argument error");
		break;

	case	1:	// GDBM_SYNC handle
		success = mod_parint(0, params, param_count, &handle);
		if	( success )	{
			if	( is_valid_handle(handle) )	{
				gdbm_sync(table[handle].dbf);
				success = 1;
				}
			else	{
				success = 0;
				v_setstr(retval, "GDBM_SYNC: INVALID HANDLE");
				}
			}
		else
			v_setstr(retval, "GDBM_SYNC: argument error");
		break;

	default:
		v_setstr(retval, "GDBM: procedure does not exist!");
		}

	return success;
}
Ejemplo n.º 17
0
	/** retrieve the half edge handle of a vertex */
	HalfEdgeHandle TopologyKernel::half_edge_handle(const VertexHandle & _vh) const
	{
		if (is_valid_handle(_vh))
		{
			return vertex(_vh).heh_;
		}
		return HalfEdgeHandle(-1);
		
	}
Ejemplo n.º 18
0
	/** set the start vertex of a half edge */
	void TopologyKernel::set_start_vertex(const HalfEdgeHandle & _heh, const VertexHandle & _vh)
	{
		if (is_valid_handle(_heh))
		{
			half_edge(_heh).vh_ = _vh;

		}
		
	}
Ejemplo n.º 19
0
void
tmout_start (timeout_t handle)
{
	struct timeout *tmout;

	assert (is_valid_handle (handle));

	tmout = &(table_[handle]);
	crono_start (&(tmout->to_crono));
}
Ejemplo n.º 20
0
void
tmout_set (timeout_t handle, const struct timeval *max)
{
	struct timeout *tmout;

	assert (is_valid_handle (handle));
	assert (max != NULL);

	tmout = &(table_[handle]);
	memcpy (&(tmout->to_maxval), max, sizeof(*max));
}
Ejemplo n.º 21
0
MatchErrorCode
MatchTableAbstract::query_counters(entry_handle_t handle,
				   counter_value_t *bytes,
				   counter_value_t *packets) const
{
  ReadLock lock = lock_read();
  if(!with_counters) return MatchErrorCode::COUNTERS_DISABLED;
  if(!is_valid_handle(handle)) return MatchErrorCode::INVALID_HANDLE;
  const MatchUnit::EntryMeta &meta = match_unit_->get_entry_meta(handle);
  // should I hide counter implementation more?
  meta.counter.query_counter(bytes, packets);
  return MatchErrorCode::SUCCESS;
}
Ejemplo n.º 22
0
void win_file_event::shutdown()
{
    LOG_COMP_TRACE_FUNCTION(win_file_event);

    if(is_valid_handle(change_handle_))
    {
        LOG_COMP_NOTICE(win_file_event, "shutting down event notifications");

        terminated_ = true;

        ::FindCloseChangeNotification(change_handle_);
        change_handle_ = INVALID_HANDLE_VALUE;
    }
}
Ejemplo n.º 23
0
void
tmout_print (timeout_t handle)
{
	struct timeout *tmout;

	assert (is_valid_handle (handle));

	tmout = &(table_[handle]);

	printf ("at ");
	crono_print (&(tmout->to_crono));

	printf (" max ");
	tv_print (&(tmout->to_maxval));
}
Ejemplo n.º 24
0
bool
tmout_left (timeout_t handle, struct timeval *result)
{
	struct timeval elapsed;
	struct timeval left;
	struct timeout *tmout;

	assert (is_valid_handle (handle));

	tmout = &(table_[handle]);
	crono_measure (&(tmout->to_crono), &elapsed);
	tv_diff (&left, &(tmout->to_maxval), &elapsed);
	if (result)
		memcpy (result, &left, sizeof(*result));
	if (tv_cmp (&left, &time_0ms) <= 0)
		return FALSE;
	return TRUE;
}
Ejemplo n.º 25
0
/******************************************************************************
 *  lookup_handle
 *
 * Returns the object identified by the handle in the given handle table
 *
 * PARAMS
 *  lpTable    [I] Pointer to the handle table, in which the handle is looked up.
 *  handle     [I] The handle, which is to be looked up
 *    lplpObject [O] Pointer to the variable, into which the pointer to the 
 *                   object looked up is copied.
 * RETURNS
 *  non zero,  if successful
 *  zero,      if not successful (invalid handle)
 */
int lookup_handle(HANDLETABLE *lpTable, unsigned int handle, DWORD dwType, OBJECTHDR **lplpObject)
{
    int ret = 0;
    
    TRACE("(lpTable=%p, handle=%d, lplpObject=%p)\n", lpTable, handle, lplpObject);
    
    EnterCriticalSection(&lpTable->mutex);
    if (!is_valid_handle(lpTable, handle, dwType)) 
    {
        *lplpObject = NULL;
        goto exit;
    }
    *lplpObject = lpTable->paEntries[HANDLE2INDEX(handle)].pObject;

    ret = 1;
exit:
    LeaveCriticalSection(&lpTable->mutex);
    return ret;
}
Ejemplo n.º 26
0
void win_file_event::initialize()
{
    LOG_COMP_TRACE_FUNCTION(win_file_event);

    if(!is_valid_handle(change_handle_))
    {
        LOG_COMP_NOTICE(win_file_event, "initializing event notifications");

        terminated_ = false;

        std::string const path = util::path::remove_filespec(file_.filename());
        change_handle_ = ::FindFirstChangeNotificationA(path.c_str(), FALSE, FILE_NOTIFY_CHANGE_SIZE);

        if(INVALID_HANDLE_VALUE == change_handle_)
        {
            throw std::runtime_error(util::win::error_to_string("FindFirstChangeNotification", ::GetLastError()));
        }
    }
}
Ejemplo n.º 27
0
/*
*	execute the 'index' function
*/
int		sblib_func_exec(int index, int param_count, slib_par_t *params, var_t *retval)
{
	int		success = 0;

	switch ( index )	{
	case	0:	// handle <- GDBM_OPEN(file[, block_size, flags, mode])
		{
			char	*file;
			int		bsize, flags, mode;

			success = mod_parstr_ptr(0, params, param_count, &file);
			success = mod_opt_parint(1, params, param_count, &bsize, 0);
			success = mod_opt_parint(2, params, param_count, &flags, GDBM_WRCREAT);
			success = mod_opt_parint(3, params, param_count, &mode, 0666);
		
			if	( success )	{
				int		handle;

				handle = get_free_handle();
				if	( handle >= 0 )	{
					table[handle].dbf = gdbm_open(file, bsize, flags, mode, NULL);
					success = (table[handle].dbf != NULL);
					if	( success )	
						v_setint(retval, handle);
					else
						v_setstr(retval, gdbm_strerror(gdbm_errno));
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_OPEN: NO FREE HANDLES");
					}
				}
			else
				v_setstr(retval, "GDBM_OPEN: argument error");
		}
		break;

	case	1:	// handle <- GDBM_STORE(handle, key, data [, flags])
		{
			int		handle, flags;
			char	*key, *data;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			success = mod_parstr_ptr(2, params, param_count, &data);
			success = mod_opt_parint(3, params, param_count, &flags, GDBM_REPLACE);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key, dt_data;
					int		r;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;
					dt_data.dptr  = data;
					dt_data.dsize = strlen(data) + 1;
					
					r = gdbm_store(table[handle].dbf, dt_key, dt_data, flags);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_STORE: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_STORE: argument error");
		}
		break;

	case	2:	// data <- GDBM_FETCH(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key, dt_data;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;
					
					dt_data = gdbm_fetch(table[handle].dbf, dt_key);
					v_setstr(retval, (char *) dt_data.dptr);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_FETCH: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_FETCH: argument error");
		}
		break;

	case	3:	// status <- GDBM_DELETE(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;
					int		r;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;
					
					r = gdbm_delete(table[handle].dbf, dt_key);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_DELETE: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_DELETE: argument error");
		}
		break;

	case	4:	// key <- GDBM_FIRSTKEY(handle)
		{
			int		handle;

			success = mod_parint    (0, params, param_count, &handle);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;

					dt_key = gdbm_firstkey(table[handle].dbf);
					v_setstr(retval, (char *) dt_key.dptr);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_FIRSTKEY: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_FIRSTKEY: argument error");
		}
		break;

	case	5:	// key <- GDBM_NEXTKEY(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;

					dt_key = gdbm_nextkey(table[handle].dbf, dt_key);
					v_setstr(retval, (char *) dt_key.dptr);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_NEXTKEY: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_NEXTKEY: argument error");
		}
		break;

	case	6:	// status <- GDBM_REORGANIZE(handle)
		{
			int		handle;

			success = mod_parint    (0, params, param_count, &handle);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					int		r;

					r = gdbm_reorganize(table[handle].dbf);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_REORGANIZE: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_REORGANIZE: argument error");
		}
		break;

	case	7:	// status <- GDBM_EXISTS(handle, key)
		{
			int		handle;
			char	*key;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parstr_ptr(1, params, param_count, &key);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					datum	dt_key;
					int		r;

					dt_key.dptr   = key;
					dt_key.dsize  = strlen(key) + 1;

					r = gdbm_exists(table[handle].dbf, dt_key);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_EXISTS: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_EXISTS: argument error");
		}
		break;

	case	8:	// str <- GDBM_STRERROR()
		v_setstr(retval, gdbm_strerror(gdbm_errno));
		break;

	case	9:	// status <- GDBM_SETOPT(handle, option, value, size)
		{
			int		handle, option, value, size;

			success = mod_parint    (0, params, param_count, &handle);
			success = mod_parint    (1, params, param_count, &option);
			success = mod_parint    (2, params, param_count, &value);
			success = mod_parint    (3, params, param_count, &size);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					int		r;

					r = gdbm_setopt(table[handle].dbf, option, &value, size);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_SETOPT: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_SETOPT: argument error");
		}
		break;

	case	10:	// status <- GDBM_FDESC(handle)
		{
			int		handle;

			success = mod_parint    (0, params, param_count, &handle);
			if	( success )	{
				if	( is_valid_handle(handle) )	{
					int		r;

					r = gdbm_fdesc(table[handle].dbf);
					v_setint(retval, r);
					success = 1;
					}
				else	{
					success = 0;
					v_setstr(retval, "GDBM_FDESC: INVALID HANDLE");
					}
				}
			else
				v_setstr(retval, "GDBM_FDESC: argument error");
		}
		break;

	default:
		v_setstr(retval, "GDBM: function does not exist!");
		}

	return success;
}
Ejemplo n.º 28
0
GLMeshRendererFactory::RendererHandle
GLMeshRendererFactory::new_mesh_renderer(const std::string& filename,
                                         GLsizei viewport_width,
                                         GLsizei viewport_height)
{
    // Get an available handle
    RendererHandle handle = get_next_avail_handle();

    // No more free handles, do not create the object
    if (!is_valid_handle(handle))
        return handle;

	if (filename.rfind(".vpm") != std::string::npos)
	{
        ViewDependentProgressiveMesh* mesh = NULL;
        GLMeshRendererES1* renderer = NULL;
        GLVpmMeshRenderer* result = NULL;
        try
        {
            mesh = new ViewDependentProgressiveMesh(filename);
            renderer = new GLMeshRendererES1(viewport_width, viewport_height);
            result = new GLVpmMeshRenderer(*renderer, mesh);
        }
        catch (MobiMeshException& ex)
        {
            if (mesh)
                delete mesh;
            if (renderer)
                delete renderer;
            if (result)
                delete result;
            throw UnableToCreateRendererException(ex.what());
        }
        renderers_[handle] = result;
        renderers_for_vpm_[handle] = renderer;
        meshes_[handle] = mesh;
	}
	else if (filename.rfind( ".pm") != std::string::npos)
	{
        ProgressiveMesh* mesh = NULL;
        GLMeshRendererES1* renderer = NULL;
        try
        {
            mesh = new ProgressiveMesh(filename);
            renderer = new GLMeshRendererES1(mesh,
                                             viewport_width, viewport_height);
        }
        catch (MobiMeshException& ex)
        {
            if (mesh)
                delete mesh;
            if (renderer)
                delete renderer;
            throw UnableToCreateRendererException(ex.what());
        }
        renderers_[handle] = renderer;
        meshes_[handle] = mesh;
	}
    else if (filename.rfind(".tvpm") != std::string::npos)
    {
        TrulyViewDependentPM* mesh = NULL;
        GLMeshRendererES1* renderer = NULL;
        GLTvpmMeshRenderer* result = NULL;
        try
        {
            if (filename.rfind(".tvpm64") != std::string::npos)
                mesh = new TrulyViewDependentPM64(filename);
            else
                mesh = new TrulyViewDependentPM32(filename);
            renderer = new GLMeshRendererES1(viewport_width, viewport_height);
            result = new GLTvpmMeshRenderer(*renderer, mesh);
        }
        catch (MobiMeshException& ex)
        {
            if (mesh)
                delete mesh;
            if (renderer)
                delete renderer;
            if (result)
                delete result;
            throw UnableToCreateRendererException(ex.what());
        }
        renderers_[handle] = result;
        renderers_for_vpm_[handle] = renderer;
        meshes_[handle] = mesh;
    }
	else
    {
		throw InvalidMeshTypeException("filename must end with .vpm, .pm, "
                                       ".tvpm, or .tvpm64");
    }

    use_next_avail_handle();
	return handle;
}
Ejemplo n.º 29
0
	/** check if the input half face has opposite half face */
	bool TopologyKernel::has_opposite_half_face(const HalfFace & _hf) const
	{
		return (is_valid_handle(_hf.opp_hfh_));
	}
Ejemplo n.º 30
0
	/** check if the input half edge has opposite half edge */
	bool TopologyKernel::has_opposite_half_edge(const HalfEdge & _he) const
	{
		return (is_valid_handle(_he.opp_heh_));
	}