source: branches/CoreData/SapphireFrappliance/FRAppliance/SapphireImportHelper.h @ 801

Revision 801, 6.3 KB checked in by gbooker, 5 years ago (diff)

Added mechanism for another process to send changes to the primary holder of the db. This gets around the multiple writers problem in Core Data. Also added test mechanism as well as adding XML import to the helper.

Line 
1/*
2 * SapphireImportHelper.h
3 * Sapphire
4 *
5 * Created by Graham Booker on Dec. 8, 2007.
6 * Copyright 2007 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21@protocol SapphireImporterBackgroundProtocol;
22@class SapphireImporterDataMenu, SapphireAllImporter, SapphireFileMetaData;
23
24/*!
25 * @brief The type of import requested
26 */
27typedef enum {
28        IMPORT_TYPE_FILE_DATA,          /*!< @brief Just import file data, not everything */
29        IMPORT_TYPE_ALL_DATA,           /*!< @brief Import everything */
30}ImportType;
31
32/*!
33 * @brief The protocol for a file import data
34 *
35 * This object is a protocol of data to import.  It has the metadata as well as what kind of import to od.  Finally, it has an object to inform when the import is complete.
36 */
37@protocol SapphireImportFileProtocol <NSObject>
38/*!
39 * @brief Get the file to import
40 *
41 * @return The path to file to import
42 */
43- (bycopy NSString *)path;
44
45/*!
46 * @brief Get the informer
47 *
48 * The informer is the object which should be informed once import is complete.  This is used for UI or scheduling the next file to import.  Called by the server, not the client.
49 *
50 * @return The informer
51 */
52- (id <SapphireImporterBackgroundProtocol>)informer;
53
54/*!
55 * @brief Get the import type
56 *
57 * @return The import Type
58 */
59- (ImportType)importType;
60@end
61
62/*!
63 * @brief The import client protocol
64 *
65 * This is the protocol for the client.  It is the interface for the server to use for its child
66 */
67@protocol SapphireImportClient <NSObject>
68/*!
69 * @brief Start the queue on the client
70 */
71- (oneway void)startQueue;
72
73/*!
74 * @brief Tell the child it may quit
75 */
76- (oneway void)exitChild;
77@end
78
79/*!
80 * @brief The import server protocol
81 *
82 * This is the protocol for the server.  It is the interface for the client to use for its server
83 */
84@protocol SapphireImportServer <NSObject>
85/*!
86 * @brief Get the next import data
87 *
88 * @return The next import data
89 */
90- (id <SapphireImportFileProtocol>)nextFile;
91
92/*!
93 * @brief Sets the client for the server
94 *
95 * This is called by the client once it is ready to process data.
96 *
97 * @param aClient The client
98 */
99- (oneway void)setClient:(id <SapphireImportClient>)aClient;
100
101/*!
102 * @brief The client has finished importing
103 *
104 * @param changes The dictionary of changes
105 * @param update YES if data was imported, NO otherwise
106 */
107- (oneway void)importCompleteWithChanges:(bycopy NSDictionary *)changes updated:(BOOL)updated;
108@end
109
110/*!
111 * @brief The generic import helper (used by both the server and client)
112 *
113 * Since the client uses the same code as the server, some import operations may go through this class.  In such a case, instead of queueing up the data for a client (itself), it is processed immediately.
114 */
115@interface SapphireImportHelper : NSObject{
116}
117/*!
118 * @brief Get the shared object
119 *
120 * @param context The managed object context
121 * @return The shared object
122 */
123+ (SapphireImportHelper *)sharedHelperForContext:(NSManagedObjectContext *)moc;
124
125/*!
126 * @brief Release the shared object
127 *
128 * When called on the server (should never be called on the client), it will both release the helper object, and exit the client
129 */
130+ (void)relinquishHelper;
131
132/*!
133 * @brief Release the shared object
134 *
135 * When called on the server (should never be called on the client), it will both release the helper object, and exit the client
136 */
137- (void)relinquishHelper;
138
139/*!
140 * @brief Import file data
141 *
142 * @param file The file to import
143 * @param inform The informer to inform of completion
144 */
145- (void)importFileData:(SapphireFileMetaData *)file inform:(id <SapphireImporterBackgroundProtocol>)inform;
146
147/*!
148 * @brief Import all data
149 *
150 * @param file The file to import
151 * @param inform The informer to inform of completion
152 */
153- (void)importAllData:(SapphireFileMetaData *)file inform:(id <SapphireImporterBackgroundProtocol>)inform;
154
155/*!
156 * @brief Remove all objects in the queue with a certain informer
157 *
158 * @param inform The informer's queued items to remove
159 */
160- (void)removeObjectsWithInform:(id <SapphireImporterBackgroundProtocol>)inform;
161
162@end
163
164/*!
165 * @brief The importer client object
166 */
167@interface SapphireImportHelperClient : SapphireImportHelper <SapphireImportClient> {
168        id <SapphireImportServer>       server;                 /*!< @brief The server*/
169        SapphireAllImporter                     *allImporter;   /*!< @brief An allimporter object for importing all data*/
170        NSManagedObjectContext          *moc;                   /*!< @brief The object context*/
171        BOOL                                            keepRunning;    /*!< @brief Keep running (for terminating run loop)*/
172}
173
174/*!
175 * @brief Creates a new importer client
176 *
177 * @param context The managed object context
178 * @return The new importer client
179 */
180- (id)initWithContext:(NSManagedObjectContext *)context;
181
182/*!
183 * @brief Start the child's processing
184 */
185- (void)startChild;
186
187/*!
188 * @brief Should keep running?
189 *
190 * @return YES if runloop should keep running, NO otherwise
191 */
192- (BOOL)keepRunning;
193@end
194
195/*!
196 * @brief The importer server object
197 */
198@interface SapphireImportHelperServer : SapphireImportHelper <SapphireImportServer> {
199        NSConnection                                            *serverConnection;      /*!< @brief The server's listener connection*/
200        id <SapphireImportClient>                       client;                         /*!< @brief The client*/
201        NSManagedObjectContext                          *moc;                           /*!< @brief The object context*/
202        NSMutableArray                                          *queue;                         /*!< @brief The processing queue*/
203        BOOL                                                            queueSuspended;         /*!< @brief YES if the child exists, but nothing is in the queue, NO otherwise*/
204        id <SapphireImportFileProtocol>         currentImporting;       /*!< @brief The file the child is currently processing*/
205}
206
207/*!
208 * @brief Creates a new importer server
209 *
210 * @param context The managed object context
211 * @return The new importer server
212 */
213- (id)initWithContext:(NSManagedObjectContext *)context;
214
215@end
Note: See TracBrowser for help on using the repository browser.