/* -*-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); }