summaryrefslogtreecommitdiffhomepage
path: root/mixmvc/mvc.c
blob: dcd254f31c3538eb88ac9aea7c94368ba3e598dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
}