source: trunk/SapphireFrappliance/FRAppliance/SapphireImportHelper.h @ 1090

Revision 1090, 6.5 KB checked in by gbooker, 4 years ago (diff)

Corrected import helper to correctly work with background importers

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#import "SapphireImporterDataMenu.h"
22
23@protocol SapphireImporterBackgroundProtocol;
24@class SapphireImporterDataMenu, SapphireAllImporter, SapphireFileMetaData;
25
26/*!
27 * @brief The type of import requested
28 */
29typedef enum {
30        IMPORT_TYPE_FILE_DATA,          /*!< @brief Just import file data, not everything */
31        IMPORT_TYPE_ALL_DATA,           /*!< @brief Import everything */
32}ImportType;
33
34/*!
35 * @brief The protocol for a file import data
36 *
37 * 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.
38 */
39@protocol SapphireImportFileProtocol <NSObject>
40/*!
41 * @brief Get the file to import
42 *
43 * @return The path to file to import
44 */
45- (bycopy NSString *)path;
46
47/*!
48 * @brief Get the informer
49 *
50 * 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.
51 *
52 * @return The informer
53 */
54- (id <SapphireImporterBackgroundProtocol>)informer;
55
56/*!
57 * @brief Get the import type
58 *
59 * @return The import Type
60 */
61- (ImportType)importType;
62@end
63
64/*!
65 * @brief The import client protocol
66 *
67 * This is the protocol for the client.  It is the interface for the server to use for its child
68 */
69@protocol SapphireImportClient <NSObject>
70/*!
71 * @brief Start the queue on the client
72 */
73- (oneway void)startQueue;
74
75/*!
76 * @brief Tell the child it may quit
77 */
78- (oneway void)exitChild;
79@end
80
81/*!
82 * @brief The import server protocol
83 *
84 * This is the protocol for the server.  It is the interface for the client to use for its server
85 */
86@protocol SapphireImportServer <NSObject>
87/*!
88 * @brief Get the next import data
89 *
90 * @return The next import data
91 */
92- (id <SapphireImportFileProtocol>)nextFile;
93
94/*!
95 * @brief Sets the client for the server
96 *
97 * This is called by the client once it is ready to process data.
98 *
99 * @param aClient The client
100 */
101- (oneway void)setClient:(id <SapphireImportClient>)aClient;
102
103/*!
104 * @brief The client has finished importing
105 *
106 * @param changes The dictionary of changes
107 * @param update YES if data was imported, NO otherwise
108 */
109- (void)importCompleteWithChanges:(bycopy NSDictionary *)changes updated:(BOOL)updated;
110@end
111
112/*!
113 * @brief The generic import helper (used by both the server and client)
114 *
115 * 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.
116 */
117@interface SapphireImportHelper : NSObject{
118}
119/*!
120 * @brief Get the shared object
121 *
122 * @param context The managed object context
123 * @return The shared object
124 */
125+ (SapphireImportHelper *)sharedHelperForContext:(NSManagedObjectContext *)moc;
126
127/*!
128 * @brief Release the shared object
129 *
130 * When called on the server (should never be called on the client), it will both release the helper object, and exit the client
131 */
132+ (void)relinquishHelper;
133
134/*!
135 * @brief Release the shared object
136 *
137 * When called on the server (should never be called on the client), it will both release the helper object, and exit the client
138 */
139- (void)relinquishHelper;
140
141/*!
142 * @brief Import file data
143 *
144 * @param file The file to import
145 * @param inform The informer to inform of completion
146 * @return YES if the import is not backgrounded, NO otherwise
147 */
148- (BOOL)importFileData:(SapphireFileMetaData *)file inform:(id <SapphireImporterBackgroundProtocol>)inform;
149
150/*!
151 * @brief Import all data
152 *
153 * @param file The file to import
154 * @param inform The informer to inform of completion
155 */
156- (void)importAllData:(SapphireFileMetaData *)file inform:(id <SapphireImporterBackgroundProtocol>)inform;
157
158/*!
159 * @brief Remove all objects in the queue with a certain informer
160 *
161 * @param inform The informer's queued items to remove
162 */
163- (void)removeObjectsWithInform:(id <SapphireImporterBackgroundProtocol>)inform;
164
165@end
166
167/*!
168 * @brief The importer client object
169 */
170@interface SapphireImportHelperClient : SapphireImportHelper <SapphireImportClient, SapphireImporterDelegate> {
171        id <SapphireImportServer>       server;                 /*!< @brief The server*/
172        SapphireAllImporter                     *allImporter;   /*!< @brief An allimporter object for importing all data*/
173        NSManagedObjectContext          *moc;                   /*!< @brief The object context*/
174        BOOL                                            keepRunning;    /*!< @brief Keep running (for terminating run loop)*/
175        BOOL                                            importComplete; /*!< @brief The background importer completed*/
176}
177
178/*!
179 * @brief Creates a new importer client
180 *
181 * @param context The managed object context
182 * @return The new importer client
183 */
184- (id)initWithContext:(NSManagedObjectContext *)context;
185
186/*!
187 * @brief Start the child's processing
188 */
189- (void)startChild;
190
191/*!
192 * @brief Should keep running?
193 *
194 * @return YES if runloop should keep running, NO otherwise
195 */
196- (BOOL)keepRunning;
197@end
198
199/*!
200 * @brief The importer server object
201 */
202@interface SapphireImportHelperServer : SapphireImportHelper <SapphireImportServer> {
203        NSConnection                                            *serverConnection;      /*!< @brief The server's listener connection*/
204        id <SapphireImportClient>                       client;                         /*!< @brief The client*/
205        NSManagedObjectContext                          *moc;                           /*!< @brief The object context*/
206        NSMutableArray                                          *queue;                         /*!< @brief The processing queue*/
207        BOOL                                                            queueSuspended;         /*!< @brief YES if the child exists, but nothing is in the queue, NO otherwise*/
208        id <SapphireImportFileProtocol>         currentImporting;       /*!< @brief The file the child is currently processing*/
209}
210
211/*!
212 * @brief Creates a new importer server
213 *
214 * @param context The managed object context
215 * @return The new importer server
216 */
217- (id)initWithContext:(NSManagedObjectContext *)context;
218
219@end
Note: See TracBrowser for help on using the repository browser.