2 * Copyright (c) 2002-2003 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: vpi_event.cc,v 1.11 2005/06/12 01:10:26 steve Exp $"
23 # include "vpi_priv.h"
32 static char* named_event_str(int code
, vpiHandle ref
)
34 assert((ref
->vpi_type
->type_code
==vpiNamedEvent
));
36 struct __vpiNamedEvent
*obj
= (struct __vpiNamedEvent
*)ref
;
38 char *bn
= vpi_get_str(vpiFullName
, &obj
->scope
->base
);
39 const char *nm
= obj
->name
;
41 char *rbuf
= need_result_buf(strlen(bn
) + strlen(nm
) + 1, RBUF_STR
);
46 sprintf(rbuf
, "%s.%s", bn
, nm
);
58 static vpiHandle
named_event_get_handle(int code
, vpiHandle ref
)
60 assert((ref
->vpi_type
->type_code
==vpiNamedEvent
));
62 struct __vpiNamedEvent
*obj
= (struct __vpiNamedEvent
*)ref
;
67 return &obj
->scope
->base
;
73 static const struct __vpirt vpip_named_event_rt
= {
81 named_event_get_handle
,
88 vpiHandle
vpip_make_named_event(const char*name
, vvp_net_t
*funct
)
90 struct __vpiNamedEvent
*obj
= (struct __vpiNamedEvent
*)
91 malloc(sizeof(struct __vpiNamedEvent
));
93 obj
->base
.vpi_type
= &vpip_named_event_rt
;
94 obj
->name
= vpip_name_string(name
);
95 obj
->scope
= vpip_peek_current_scope();
103 * This function runs the callbacks for a named event. All the
104 * callbacks are listed in the callback member of the event handle,
105 * this function scans that list.
107 * This also handles the case where the callback has been removed. The
108 * vpi_remove_cb doesn't actually remove any callbacks, it marks them
109 * as cancelled by clearing the cb_rtn function. This function reaps
110 * those marked handles when it scans the list.
112 void vpip_run_named_event_callbacks(vpiHandle ref
)
114 assert((ref
->vpi_type
->type_code
==vpiNamedEvent
));
116 struct __vpiNamedEvent
*obj
= (struct __vpiNamedEvent
*)ref
;
118 struct __vpiCallback
*next
= obj
->callbacks
;
119 struct __vpiCallback
*prev
= 0;
121 struct __vpiCallback
*cur
= next
;
124 if (cur
->cb_data
.cb_rtn
!= 0) {
125 callback_execute(cur
);
128 } else if (prev
== 0) {
129 obj
->callbacks
= next
;
131 vpi_free_object(&cur
->base
);
134 assert(prev
->next
== cur
);
137 vpi_free_object(&cur
->base
);
143 * $Log: vpi_event.cc,v $
144 * Revision 1.11 2005/06/12 01:10:26 steve
145 * Remove useless references to functor.h
147 * Revision 1.10 2004/12/11 02:31:30 steve
148 * Rework of internals to carry vectors through nexus instead
149 * of single bits. Make the ivl, tgt-vvp and vvp initial changes
152 * Revision 1.9 2003/05/04 20:43:36 steve
153 * Event callbacks support vpi_remove_cb.
155 * Revision 1.8 2003/04/23 03:09:25 steve
156 * VPI Access to named events.
158 * Revision 1.7 2003/03/06 04:32:00 steve
159 * Use hashed name strings for identifiers.
161 * Revision 1.6 2003/02/02 01:40:24 steve
162 * Five vpi_free_object a default behavior.
164 * Revision 1.5 2002/08/12 01:35:08 steve
165 * conditional ident string using autoconfig.
167 * Revision 1.4 2002/07/12 18:23:30 steve
168 * Use result buf for event and scope names.
170 * Revision 1.3 2002/07/05 17:14:15 steve
171 * Names of vpi objects allocated as vpip_strings.
173 * Revision 1.2 2002/05/19 05:18:16 steve
174 * Add callbacks for vpiNamedEvent objects.
176 * Revision 1.1 2002/05/18 02:34:11 steve
177 * Add vpi support for named events.
179 * Add vpi_mode_flag to track the mode of the
180 * vpi engine. This is for error checking.