source: trunk/third/bonobo/bonobo/bonobo-persist-stream.c @ 16750

Revision 16750, 6.3 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16749, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * bonobo-persist-stream.c: PersistStream implementation.  Can be used as a
4 * base class, or directly for implementing objects that use PersistStream.
5 *
6 * Author:
7 *   Miguel de Icaza (miguel@kernel.org)
8 *
9 * Copyright 1999 Helix Code, Inc.
10 */
11#include <config.h>
12#include <gtk/gtksignal.h>
13#include <gtk/gtkmarshal.h>
14#include <bonobo/bonobo-exception.h>
15#include <bonobo/bonobo-persist-stream.h>
16
17#define PARENT_TYPE BONOBO_PERSIST_TYPE
18
19/* Parent GTK object class */
20static BonoboPersistClass *bonobo_persist_stream_parent_class;
21
22static CORBA_boolean
23impl_is_dirty (PortableServer_Servant servant, CORBA_Environment * ev)
24{
25        BonoboObject *object = bonobo_object_from_servant (servant);
26        BonoboPersistStream *pstream = BONOBO_PERSIST_STREAM (object);
27
28        return pstream->is_dirty;
29}
30
31static void
32impl_load (PortableServer_Servant servant,
33           Bonobo_Stream stream,
34           Bonobo_Persist_ContentType type,
35           CORBA_Environment *ev)
36{
37        BonoboObject *object = bonobo_object_from_servant (servant);
38        BonoboPersistStream *ps = BONOBO_PERSIST_STREAM (object);
39       
40        if (ps->load_fn != NULL)
41                (*ps->load_fn)(ps, stream, type, ps->closure, ev);
42        else {
43                GtkObjectClass *oc = GTK_OBJECT (ps)->klass;
44                BonoboPersistStreamClass *class = BONOBO_PERSIST_STREAM_CLASS (oc);
45
46                if (class->load)
47                        (*class->load)(ps, stream, type, ev);
48                else
49                        CORBA_exception_set (
50                                ev, CORBA_USER_EXCEPTION,
51                                ex_Bonobo_NotSupported, NULL);
52        }
53}
54
55static void
56impl_save (PortableServer_Servant servant,
57           Bonobo_Stream stream,
58           Bonobo_Persist_ContentType type,
59           CORBA_Environment *ev)
60{
61        BonoboObject *object = bonobo_object_from_servant (servant);
62        BonoboPersistStream *ps = BONOBO_PERSIST_STREAM (object);
63       
64        if (ps->save_fn != NULL)
65                (*ps->save_fn)(ps, stream, type, ps->closure, ev);
66        else {
67                GtkObjectClass *oc = GTK_OBJECT (ps)->klass;
68                BonoboPersistStreamClass *class = BONOBO_PERSIST_STREAM_CLASS (oc);
69
70                if (class->save)
71                        (*class->save)(ps, stream, type, ev);
72                else
73                        CORBA_exception_set (
74                                ev, CORBA_USER_EXCEPTION,
75                                ex_Bonobo_NotSupported, NULL);
76        }
77
78        ps->is_dirty = FALSE;
79}
80
81static CORBA_long
82impl_get_size_max (PortableServer_Servant servant, CORBA_Environment * ev)
83{
84        BonoboObject *object = bonobo_object_from_servant (servant);
85        BonoboPersistStream *ps = BONOBO_PERSIST_STREAM (object);
86        GtkObjectClass *oc = GTK_OBJECT (object)->klass;
87        BonoboPersistStreamClass *class = BONOBO_PERSIST_STREAM_CLASS (oc);
88
89
90        if (ps->max_fn != NULL)
91                return (*ps->max_fn)(ps, ps->closure, ev);
92
93        return (*class->get_size_max)(BONOBO_PERSIST_STREAM (object), ev);
94}
95
96static CORBA_long
97bonobo_persist_stream_size_unknown (BonoboPersistStream *ps,
98                                    CORBA_Environment *ev)
99{
100        return -1;
101}
102
103static Bonobo_Persist_ContentTypeList *
104get_content_types (BonoboPersist *persist, CORBA_Environment *ev)
105{
106        BonoboPersistStream *ps = BONOBO_PERSIST_STREAM (persist);
107
108        if (ps->types_fn)
109                return ps->types_fn (ps, ps->closure, ev);
110        else
111                return bonobo_persist_generate_content_types (1, "");
112}
113
114static void
115bonobo_persist_stream_class_init (BonoboPersistStreamClass *klass)
116{
117        BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS (klass);
118        POA_Bonobo_PersistStream__epv *epv = &klass->epv;
119
120        bonobo_persist_stream_parent_class = gtk_type_class (PARENT_TYPE);
121
122        /* Override and initialize methods */
123        klass->save = NULL;
124        klass->load = NULL;
125        klass->get_size_max = bonobo_persist_stream_size_unknown;
126
127        persist_class->get_content_types = get_content_types;
128
129        epv->load       = impl_load;
130        epv->save       = impl_save;
131        epv->getMaxSize = impl_get_size_max;
132        epv->isDirty    = impl_is_dirty;
133}
134
135static void
136bonobo_persist_stream_init (BonoboPersistStream *ps)
137{
138        /* nothing to do */
139}
140
141BONOBO_X_TYPE_FUNC_FULL (BonoboPersistStream,
142                           Bonobo_PersistStream,
143                           PARENT_TYPE,
144                           bonobo_persist_stream);
145
146/**
147 * bonobo_persist_stream_construct:
148 * @ps: A BonoboPersistStream object
149 * @load_fn: Loading routine
150 * @save_fn: Saving routine
151 * @closure: Data passed to IO routines.
152 *
153 * Initializes the BonoboPersistStream object.  The load and save
154 * operations for the object are performed by the provided @load_fn
155 * and @save_fn callback functions, which are passed @closure when
156 * they are invoked.  If either @load_fn or @save_fn is %NULL, the
157 * corresponding operation is performed by the class load and save
158 * routines.
159 *
160 * Returns: The initialized BonoboPersistStream object.
161 */
162BonoboPersistStream *
163bonobo_persist_stream_construct (BonoboPersistStream       *ps,
164                                 BonoboPersistStreamIOFn    load_fn,
165                                 BonoboPersistStreamIOFn    save_fn,
166                                 BonoboPersistStreamMaxFn   max_fn,
167                                 BonoboPersistStreamTypesFn types_fn,
168                                 void                      *closure)
169{
170        g_return_val_if_fail (ps != NULL, NULL);
171        g_return_val_if_fail (BONOBO_IS_PERSIST_STREAM (ps), NULL);
172
173        ps->load_fn = load_fn;
174        ps->save_fn = save_fn;
175        ps->max_fn = max_fn;
176        ps->types_fn = types_fn;
177        ps->closure = closure;
178       
179        return ps;
180}
181
182/**
183 * bonobo_persist_stream_new:
184 * @load_fn: Loading routine
185 * @save_fn: Saving routine
186 * @max_fn: get_max_size routine
187 * @types_fn: get_content_types routine
188 * @closure: Data passed to IO routines.
189 *
190 * Creates a new BonoboPersistStream object. The various operations
191 * for the object are performed by the provided callback functions,
192 * which are passed @closure when they are invoked. If any callback is
193 * %NULL, the corresponding operation is performed by the class load
194 * and save routines.
195 *
196 * Returns: the newly-created BonoboPersistStream object.
197 */
198BonoboPersistStream *
199bonobo_persist_stream_new (BonoboPersistStreamIOFn    load_fn,
200                           BonoboPersistStreamIOFn    save_fn,
201                           BonoboPersistStreamMaxFn   max_fn,
202                           BonoboPersistStreamTypesFn types_fn,
203                           void                      *closure)
204{
205        BonoboPersistStream *ps;
206
207        ps = gtk_type_new (bonobo_persist_stream_get_type ());
208
209        bonobo_persist_stream_construct (ps, load_fn, save_fn,
210                                         max_fn, types_fn, closure);
211
212        return ps;
213}
214
215/**
216 * bonobo_persist_stream_set_dirty:
217 * @ps: A BonoboPersistStream object
218 * @dirty: A boolean value representing whether the object is dirty or not
219 *
220 * This routine sets the dirty bit for the PersistStream object.
221 */
222void
223bonobo_persist_stream_set_dirty (BonoboPersistStream *pstream, gboolean dirty)
224{
225        g_return_if_fail (pstream != NULL);
226        g_return_if_fail (BONOBO_IS_PERSIST_STREAM (pstream));
227
228        pstream->is_dirty = dirty;
229}
Note: See TracBrowser for help on using the repository browser.