diff options
Diffstat (limited to 'mixmvc')
| -rw-r--r-- | mixmvc/.cvsignore | 3 | ||||
| -rw-r--r-- | mixmvc/Makefile.am | 19 | ||||
| -rw-r--r-- | mixmvc/mix_vm_subject.c | 68 | ||||
| -rw-r--r-- | mixmvc/mix_vm_subject.h | 49 | ||||
| -rw-r--r-- | mixmvc/mvc.c | 69 | ||||
| -rw-r--r-- | mixmvc/mvc.h | 105 | 
6 files changed, 313 insertions, 0 deletions
| diff --git a/mixmvc/.cvsignore b/mixmvc/.cvsignore new file mode 100644 index 0000000..e995588 --- /dev/null +++ b/mixmvc/.cvsignore @@ -0,0 +1,3 @@ +.deps +Makefile +Makefile.in diff --git a/mixmvc/Makefile.am b/mixmvc/Makefile.am new file mode 100644 index 0000000..f252f4b --- /dev/null +++ b/mixmvc/Makefile.am @@ -0,0 +1,19 @@ +## Process this file with automake to produce Makefile.in + +# Copyright (C) 2001 Free Software Foundation, Inc. +#   +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without  +# modifications, as long as this notice is preserved. +#  +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +SUBDIRS = . +INCLUDES = -I$(includedir) -DG_LOG_DOMAIN=\"libmixmvc\" + +noinst_LIBRARIES = libmixmvc.a +libmixmvc_a_SOURCES = mvc.h mvc.c \ +                      mix_vm_subject.h mix_vm_subject.c + diff --git a/mixmvc/mix_vm_subject.c b/mixmvc/mix_vm_subject.c new file mode 100644 index 0000000..1c7e5d8 --- /dev/null +++ b/mixmvc/mix_vm_subject.c @@ -0,0 +1,68 @@ +/* -*-c-*- -------------- mix_vm_subject.c : + * Implementation of the functions declared in mix_vm_subject.h + * ------------------------------------------------------------------ + *  Last change: Time-stamp: "01/02/13 02:19:34 jose" + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + *   + * This program is free software; you can redistribute it and/or modify + * it 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. + *   + */ + + +#include "mix_vm_subject.h" + +/* the mix virtual machine subject */ +struct mix_vm_subject_t  +{ +  subject_t parent; +  mix_vm_t *vm; +}; + +/* the notify callback */ +static void +mix_vm_notify_ (subject_t *sub, data_t *data)  +{ +} + +/* create a new mix_vm_subject */ +mix_vm_subject_t * +mix_vm_subject_new (void) +{ +  mix_vm_subject_t *result = g_new (mix_vm_subject_t, 1); +  subject_init ((subject_t *)result); +  ((subject_t *)result)->notify = mix_vm_notify_; +  result->vm = mix_vm_new (); +  return result; +} + +/* delete */ +void +mix_vm_subject_delete (mix_vm_subject_t *sub) +{ +  g_return_if_fail (sub != NULL); +  subject_clean ((subject_t *)sub); +  mix_vm_delete (sub->vm); +  g_free (sub); +} + +/* get the mix_vm in the subject */ +mix_vm_t * +mix_vm_subject_get_vm (const mix_vm_subject_t *sub)  +{ +  g_return_val_if_fail (sub != NULL, NULL); +  return sub->vm; +} + diff --git a/mixmvc/mix_vm_subject.h b/mixmvc/mix_vm_subject.h new file mode 100644 index 0000000..07d2118 --- /dev/null +++ b/mixmvc/mix_vm_subject.h @@ -0,0 +1,49 @@ +/* -*-c-*- ---------------- mix_vm_subject.h : + * A virtual machine subject (model) + * ------------------------------------------------------------------ + *  Last change: Time-stamp: <01/02/13 02:18:50 jose> + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + *   + * This program is free software; you can redistribute it and/or modify + * it 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. + *   + */ + + +#ifndef MIX_VM_SUBJECT_H +#define MIX_VM_SUBJECT_H + +#include <mixlib/mix_vm.h> +#include "mvc.h" + +/* the mix virtual machine subject */ +typedef struct mix_vm_subject_t mix_vm_subject_t; + +/* create a new mix_vm_subject */ +extern mix_vm_subject_t * +mix_vm_subject_new (void); + +/* delete */ +extern void +mix_vm_subject_delete (mix_vm_subject_t *sub); + +/* get the mix_vm in the subject */ +extern mix_vm_t * +mix_vm_subject_get_vm (const mix_vm_subject_t *sub); + + + +#endif /* MIX_VM_SUBJECT_H */ + diff --git a/mixmvc/mvc.c b/mixmvc/mvc.c new file mode 100644 index 0000000..dcd254f --- /dev/null +++ b/mixmvc/mvc.c @@ -0,0 +1,69 @@ +/* -*-c-*- -------------- mvc.c : + * Implementation of the functions declared in mvc.h + * ------------------------------------------------------------------ + *  Last change: Time-stamp: "01/02/13 02:17:37 jose" + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + *   + * This program is free software; you can redistribute it and/or modify + * it 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. + *   + */ + + + +#include "mvc.h" + +/* clean up a subject */ +void +subject_clean (subject_t *sub)  +{ +  g_return_if_fail (sub != NULL); +  g_slist_free (sub->observers); +} + +/* add a new observer */ +void +subject_add_observer (subject_t *sub, observer_t *obs)  +{ +  g_return_if_fail (sub != NULL); +  g_return_if_fail (obs != NULL); +  sub->observers = g_slist_append (sub->observers, (gpointer)obs); +  obs->subject = sub; +} + +/* remove an observer */ +void +subject_remove_observer (subject_t *sub, observer_t *obs) +{ +  g_return_if_fail (sub != NULL); +  g_return_if_fail (obs != NULL); +  sub->observers = g_slist_remove (sub->observers, (gpointer)obs); +} + +/* observer notifier callback */ +static void +update_callback (gpointer obs, gpointer data)  +{ +  ((observer_t *)obs)->update((observer_t *)obs, data); +} + +/* notify all observers of a change */ +void +subject_update_observers (subject_t *sub, data_t *data) +{ +  g_return_if_fail (sub != NULL); +  g_slist_foreach (sub->observers, update_callback, data); +} + diff --git a/mixmvc/mvc.h b/mixmvc/mvc.h new file mode 100644 index 0000000..6371a27 --- /dev/null +++ b/mixmvc/mvc.h @@ -0,0 +1,105 @@ +/* -*-c-*- ---------------- mvc.h : + * This header defines basic types supporting the MVC pattern + * ------------------------------------------------------------------ + *  Last change: Time-stamp: <01/02/13 02:16:08 jose> + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, Inc. + *   + * This program is free software; you can redistribute it and/or modify + * it 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. + *   + */ + + +#ifndef MVC_H +#define MVC_H + +#include <glib.h> + +/* the subject which is observed (the model) */ +typedef struct subject_t subject_t; + +/* subject's observer (the view) */ +typedef struct observer_t observer_t; + +/* list of observers (maintained by the subject) */ +typedef GSList observer_list_t; + +/* data used in callbacks */ +typedef void data_t; + +/* (virtual) function used by subject on each observer to notify an update */ +typedef void (*update_callback_t)(observer_t *obs, data_t *data); + +/* (virtual) function used by observers to notify subject of a change */ +typedef void (*notify_callback_t)(subject_t *subj, data_t *data); + +/* base subject type, containing a notify callback to be invoked +   by observers */ +struct subject_t +{ +  notify_callback_t notify;	/* notify callback used by observers */ +  observer_list_t *observers;	/* the list of current observers */ +}; + +/* base observer type, containing an update callback (to be invoked by +   the subject) and a pointer to the observed subject +*/ +struct observer_t +{ +  update_callback_t update;	/* update callback used by subject */ +  subject_t *subject;		/* observed subject */ +}; + + +/* subject interface */ +/* init a subject */ +#define subject_init(sub)			\ +do {						\ +  (sub)->notify = NULL;				\ +  (sub)->observers = NULL;			\ +} while (FALSE) + +/* clean up a subject */ +extern void +subject_clean (subject_t *sub); + +/* add a new observer */ +extern void +subject_add_observer (subject_t *sub, observer_t *obs); + +/* remove an observer */ +extern void +subject_remove_observer (subject_t *sub, observer_t *obs); + +/* notify all observers of a change */ +extern void +subject_update_observers (subject_t *sub, data_t *data); + +/* observer interface */ +/* init an observer */ +#define observer_init(obs)			\ +do {						\ +  (obs)->update = NULL;				\ +  (obs)->subject = NULL;			\ +} while (FALSE) +   +/* macro used by observers to notify their subject of a change */ +#define observer_notify_subject(obs, data)				\ +    (*((observer_t *)obs->subject->notify)((observer_t *)obs->subject,	\ +					   (data_t *)data)) + +        +#endif /* MVC_H */ + | 
