home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP Advantage / NeXTstep_Advantage.img / YourCallServer / CallServer.m < prev    next >
Text File  |  1993-04-14  |  2KB  |  85 lines

  1. /* You may freely copy, distribute and reuse the code in this example.
  2.  * NeXT disclaims any warranty of any kind, expressed or implied, as to
  3.  * its fitness for any particular use.
  4.  */ 
  5.  
  6. #import "CallServer.h"
  7. #import "CallRecord.h"
  8.  
  9. @implementation CallServer : CallController
  10.  
  11. /* 
  12.  * Purpose: Initialize the CallServer
  13.  *
  14.  * First sends an init message to super, thereby invoking CallController's 
  15.  * version of init, which initializes the callTable HashTable.  
  16.  * Then registers and starts the server connection.  
  17.  */
  18.  
  19. - init
  20. {
  21.     [super init];
  22.     [[NXConnection registerRoot:self 
  23.     withName:"CallDataServer"] runFromAppKit];
  24.     return self;
  25. }
  26.  
  27.  
  28. /*
  29.  * Purpose: Retrieve a CallRecord for a particular name from the callTable.  
  30.  *
  31.  * This is one of the CallProvider protocol methods.
  32.  * When the client wants to look up a record for a name in the database,
  33.  * it sends this message -- through it's proxy -- to the server. 
  34.  * CallClient sends this message from its retrieveCall: method.  
  35.  *
  36.  */
  37.  
  38. - (id <CallData>)lookupCall:(const char *)fetchName
  39. {
  40.     return [callTable valueForKey:fetchName]; 
  41. }
  42.  
  43.  
  44. /*
  45.  * Purpose: Request a new record from the server 
  46.  *
  47.  * This is one of the CallProvider protocol methods.  
  48.  * Before the client fills a new record with data, it sends this message
  49.  * to request the record -- through the proxy -- to the server.  
  50.  * CallClient sends this message from its saveCall: method.  
  51.  *
  52.  */
  53.  
  54. - (id <CallData>)newRecord
  55. {
  56.     return [[CallRecord alloc] init];
  57. }
  58.  
  59.  
  60. /*
  61.  * Purpose: Save the record in the database
  62.  *
  63.  * This is one of the CallProvider protocol methods.  
  64.  * Once the client fills a new record with data, it sends this message -- 
  65.  * through the proxy -- to request that the server save it in the database.  
  66.  * CallClient sends this message from its saveCall: method.
  67.  */
  68.  
  69. - storeCall:(id <CallData>)theRecord 
  70. {
  71.     NXTypedStream *callStream;
  72.  
  73.     [callTable insertKey:[theRecord name] value:theRecord]; 
  74.     if (callStream = NXOpenTypedStreamForFile(callFilePath, NX_WRITEONLY)) {
  75.     NXWriteObject(callStream, callTable);
  76.     NXCloseTypedStream(callStream);
  77.     return self;
  78.     }
  79.     else return nil;
  80. }
  81.  
  82.  
  83.  
  84. @end
  85.