2002-05-18 04:34:11 +02:00
|
|
|
/*
|
2003-05-04 22:43:36 +02:00
|
|
|
* Copyright (c) 2002-2003 Stephen Williams (steve@icarus.com)
|
2002-05-18 04:34:11 +02:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2005-06-12 03:10:26 +02:00
|
|
|
#ident "$Id: vpi_event.cc,v 1.11 2005/06/12 01:10:26 steve Exp $"
|
2002-05-18 04:34:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include <stdio.h>
|
|
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
|
# include <malloc.h>
|
|
|
|
|
#endif
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
2007-12-19 00:11:50 +01:00
|
|
|
static char* named_event_get_str(int code, vpiHandle ref)
|
2002-05-19 07:18:16 +02:00
|
|
|
{
|
|
|
|
|
assert((ref->vpi_type->type_code==vpiNamedEvent));
|
|
|
|
|
|
|
|
|
|
struct __vpiNamedEvent*obj = (struct __vpiNamedEvent*)ref;
|
|
|
|
|
|
2007-12-19 00:11:50 +01:00
|
|
|
return generic_get_str(code, &obj->scope->base, obj->name, NULL);
|
2002-05-19 07:18:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle named_event_get_handle(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert((ref->vpi_type->type_code==vpiNamedEvent));
|
|
|
|
|
|
|
|
|
|
struct __vpiNamedEvent*obj = (struct __vpiNamedEvent*)ref;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiScope:
|
|
|
|
|
return &obj->scope->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-18 04:34:11 +02:00
|
|
|
static const struct __vpirt vpip_named_event_rt = {
|
|
|
|
|
vpiNamedEvent,
|
|
|
|
|
|
|
|
|
|
0,
|
2007-12-19 00:11:50 +01:00
|
|
|
named_event_get_str,
|
2002-05-18 04:34:11 +02:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
|
2002-05-19 07:18:16 +02:00
|
|
|
named_event_get_handle,
|
2002-05-18 04:34:11 +02:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
|
2003-02-02 02:40:24 +01:00
|
|
|
0
|
2002-05-18 04:34:11 +02:00
|
|
|
};
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
vpiHandle vpip_make_named_event(const char*name, vvp_net_t*funct)
|
2002-05-18 04:34:11 +02:00
|
|
|
{
|
|
|
|
|
struct __vpiNamedEvent*obj = (struct __vpiNamedEvent*)
|
|
|
|
|
malloc(sizeof(struct __vpiNamedEvent));
|
|
|
|
|
|
|
|
|
|
obj->base.vpi_type = &vpip_named_event_rt;
|
2003-03-06 05:32:00 +01:00
|
|
|
obj->name = vpip_name_string(name);
|
2002-05-18 04:34:11 +02:00
|
|
|
obj->scope = vpip_peek_current_scope();
|
2003-04-23 05:09:25 +02:00
|
|
|
obj->funct = funct;
|
2002-05-19 07:18:16 +02:00
|
|
|
obj->callbacks = 0;
|
2002-05-18 04:34:11 +02:00
|
|
|
|
|
|
|
|
return &obj->base;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-04 22:43:36 +02:00
|
|
|
/*
|
|
|
|
|
* This function runs the callbacks for a named event. All the
|
|
|
|
|
* callbacks are listed in the callback member of the event handle,
|
|
|
|
|
* this function scans that list.
|
|
|
|
|
*
|
|
|
|
|
* This also handles the case where the callback has been removed. The
|
|
|
|
|
* vpi_remove_cb doesn't actually remove any callbacks, it marks them
|
|
|
|
|
* as cancelled by clearing the cb_rtn function. This function reaps
|
|
|
|
|
* those marked handles when it scans the list.
|
|
|
|
|
*/
|
2002-05-19 07:18:16 +02:00
|
|
|
void vpip_run_named_event_callbacks(vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert((ref->vpi_type->type_code==vpiNamedEvent));
|
|
|
|
|
|
|
|
|
|
struct __vpiNamedEvent*obj = (struct __vpiNamedEvent*)ref;
|
|
|
|
|
|
2003-05-04 22:43:36 +02:00
|
|
|
struct __vpiCallback*next = obj->callbacks;
|
|
|
|
|
struct __vpiCallback*prev = 0;
|
|
|
|
|
while (next) {
|
|
|
|
|
struct __vpiCallback*cur = next;
|
|
|
|
|
next = cur->next;
|
|
|
|
|
|
|
|
|
|
if (cur->cb_data.cb_rtn != 0) {
|
|
|
|
|
callback_execute(cur);
|
|
|
|
|
prev = cur;
|
|
|
|
|
|
|
|
|
|
} else if (prev == 0) {
|
|
|
|
|
obj->callbacks = next;
|
|
|
|
|
cur->next = 0;
|
|
|
|
|
vpi_free_object(&cur->base);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
assert(prev->next == cur);
|
|
|
|
|
prev->next = next;
|
|
|
|
|
cur->next = 0;
|
|
|
|
|
vpi_free_object(&cur->base);
|
|
|
|
|
}
|
2002-05-19 07:18:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-18 04:34:11 +02:00
|
|
|
/*
|
|
|
|
|
* $Log: vpi_event.cc,v $
|
2005-06-12 03:10:26 +02:00
|
|
|
* Revision 1.11 2005/06/12 01:10:26 steve
|
|
|
|
|
* Remove useless references to functor.h
|
|
|
|
|
*
|
2004-12-11 03:31:25 +01:00
|
|
|
* Revision 1.10 2004/12/11 02:31:30 steve
|
|
|
|
|
* Rework of internals to carry vectors through nexus instead
|
|
|
|
|
* of single bits. Make the ivl, tgt-vvp and vvp initial changes
|
|
|
|
|
* down this path.
|
|
|
|
|
*
|
2003-05-04 22:43:36 +02:00
|
|
|
* Revision 1.9 2003/05/04 20:43:36 steve
|
|
|
|
|
* Event callbacks support vpi_remove_cb.
|
|
|
|
|
*
|
2003-04-23 05:09:25 +02:00
|
|
|
* Revision 1.8 2003/04/23 03:09:25 steve
|
|
|
|
|
* VPI Access to named events.
|
|
|
|
|
*
|
2003-03-06 05:32:00 +01:00
|
|
|
* Revision 1.7 2003/03/06 04:32:00 steve
|
|
|
|
|
* Use hashed name strings for identifiers.
|
|
|
|
|
*
|
2003-02-02 02:40:24 +01:00
|
|
|
* Revision 1.6 2003/02/02 01:40:24 steve
|
|
|
|
|
* Five vpi_free_object a default behavior.
|
|
|
|
|
*
|
2002-08-12 03:34:58 +02:00
|
|
|
* Revision 1.5 2002/08/12 01:35:08 steve
|
|
|
|
|
* conditional ident string using autoconfig.
|
|
|
|
|
*
|
2002-07-12 20:23:30 +02:00
|
|
|
* Revision 1.4 2002/07/12 18:23:30 steve
|
|
|
|
|
* Use result buf for event and scope names.
|
|
|
|
|
*
|
2002-07-05 19:14:15 +02:00
|
|
|
* Revision 1.3 2002/07/05 17:14:15 steve
|
|
|
|
|
* Names of vpi objects allocated as vpip_strings.
|
|
|
|
|
*
|
2002-05-19 07:18:16 +02:00
|
|
|
* Revision 1.2 2002/05/19 05:18:16 steve
|
|
|
|
|
* Add callbacks for vpiNamedEvent objects.
|
|
|
|
|
*
|
2002-05-18 04:34:11 +02:00
|
|
|
* Revision 1.1 2002/05/18 02:34:11 steve
|
|
|
|
|
* Add vpi support for named events.
|
|
|
|
|
*
|
|
|
|
|
* Add vpi_mode_flag to track the mode of the
|
|
|
|
|
* vpi engine. This is for error checking.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|