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

Revision 560, 6.2 KB checked in by gbooker, 7 years ago (diff)

Byebye SapphireFile? (protocol); we no longer need you *sniff*

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 update YES if data was imported, NO otherwise
105 */
106- (oneway void)importComplete:(BOOL)updated;
107@end
108
109/*!
110 * @brief The generic import helper (used by both the server and client)
111 *
112 * 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.
113 */
114@interface SapphireImportHelper : NSObject{
115}
116/*!
117 * @brief Get the shared object
118 *
119 * @param context The managed object context
120 * @return The shared object
121 */
122+ (SapphireImportHelper *)sharedHelperForContext:(NSManagedObjectContext *)moc;
123
124/*!
125 * @brief Release the shared object
126 *
127 * When called on the server (should never be called on the client), it will both release the helper object, and exit the client
128 */
129+ (void)relinquishHelper;
130
131/*!
132 * @brief Release the shared object
133 *
134 * When called on the server (should never be called on the client), it will both release the helper object, and exit the client
135 */
136- (void)relinquishHelper;
137
138/*!
139 * @brief Import file data
140 *
141 * @param file The file to import
142 * @param inform The informer to inform of completion
143 */
144- (void)importFileData:(SapphireFileMetaData *)file inform:(id <SapphireImporterBackgroundProtocol>)inform;
145
146/*!
147 * @brief Import all data
148 *
149 * @param file The file to import
150 * @param inform The informer to inform of completion
151 */
152- (void)importAllData:(SapphireFileMetaData *)file inform:(id <SapphireImporterBackgroundProtocol>)inform;
153
154/*!
155 * @brief Remove all objects in the queue with a certain informer
156 *
157 * @param inform The informer's queued items to remove
158 */
159- (void)removeObjectsWithInform:(id <SapphireImporterBackgroundProtocol>)inform;
160
161@end
162
163/*!
164 * @brief The importer client object
165 */
166@interface SapphireImportHelperClient : SapphireImportHelper <SapphireImportClient> {
167        id <SapphireImportServer>       server;                 /*!< @brief The server*/
168        SapphireAllImporter                     *allImporter;   /*!< @brief An allimporter object for importing all data*/
169        NSManagedObjectContext          *moc;                   /*!< @brief The object context*/
170        BOOL                                            keepRunning;    /*!< @brief Keep running (for terminating run loop)*/
171}
172
173/*!
174 * @brief Creates a new importer client
175 *
176 * @param context The managed object context
177 * @return The new importer client
178 */
179- (id)initWithContext:(NSManagedObjectContext *)context;
180
181/*!
182 * @brief Start the child's processing
183 */
184- (void)startChild;
185
186/*!
187 * @brief Should keep running?
188 *
189 * @return YES if runloop should keep running, NO otherwise
190 */
191- (BOOL)keepRunning;
192@end
193
194/*!
195 * @brief The importer server object
196 */
197@interface SapphireImportHelperServer : SapphireImportHelper <SapphireImportServer> {
198        NSConnection                                            *serverConnection;      /*!< @brief The server's listener connection*/
199        id <SapphireImportClient>                       client;                         /*!< @brief The client*/
200        NSManagedObjectContext                          *moc;                           /*!< @brief The object context*/
201        NSMutableArray                                          *queue;                         /*!< @brief The processing queue*/
202        BOOL                                                            queueSuspended;         /*!< @brief YES if the child exists, but nothing is in the queue, NO otherwise*/
203        id <SapphireImportFileProtocol>         currentImporting;       /*!< @brief The file the child is currently processing*/
204}
205
206/*!
207 * @brief Creates a new importer server
208 *
209 * @param context The managed object context
210 * @return The new importer server
211 */
212- (id)initWithContext:(NSManagedObjectContext *)context;
213
214@end
Note: See TracBrowser for help on using the repository browser.