home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / DOserver.m < prev    next >
Encoding:
Text File  |  1997-04-14  |  6.9 KB  |  251 lines

  1. //************************************************************************
  2. //
  3. //    DOserver.m.  
  4. //
  5. //        Distributed Objects server which communicates with MODEM tool
  6. //        during Manual dial.
  7. //
  8. //            by    Felipe A. Rodriguez        
  9. //
  10. //    This code is supplied "as is" the author makes no warranty as to its 
  11. //    suitability for any purpose.  This code is free and may be distributed 
  12. //    in accordance with the terms of the:
  13. //        
  14. //            GNU GENERAL PUBLIC LICENSE
  15. //            Version 2, June 1991
  16. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  17. //             675 Mass Ave, Cambridge, MA 02139, USA
  18. //
  19. //************************************************************************
  20.  
  21. #import "GKdefs.h"
  22. #import "DOserver.h"
  23. #import "OptionsEditor.h"
  24. #import "HLDelegate.h"
  25. #import "Coordinator.h"
  26. #import "SwapView.h"
  27. #import <appkit/nextstd.h>
  28. #import <remote/NXProxy.h>
  29.  
  30.  
  31. @implementation DOserver
  32.  
  33. //************************************************************************
  34. //
  35. //        show Dialer panel 
  36. //
  37. //************************************************************************
  38.  
  39. - showDialPanel 
  40. {
  41.     if(!gatePanel)
  42.         [NXApp loadNibSection:"Inspector.nib" owner:self withNames:NO];
  43.     [theInspector inspectName:"FirstInspector"];        // swap inspectors
  44.     [gatePanel setFrameUsingName:"gatePanel"];            // remem loc/size
  45.     [gatePanel setFrameAutosaveName:"gatePanel"];        // remem loc/size
  46.     [gatePanel makeKeyAndOrderFront:self];    
  47.     [phoneNumField setStringValue:NXGetDefaultValue([NXApp appName],     
  48.                                                         "lastNumDialed")];
  49.     [phoneNumField selectText:self];
  50.     
  51.     return self;
  52. }
  53. //*****************************************************************************
  54. //
  55. //         called when GateTool's mach port becomes invalid 
  56. //
  57. //*****************************************************************************
  58.  
  59. - senderIsInvalid:sender 
  60. {
  61.     if(gatePanel)
  62.         [gatePanel close];
  63.     if(!connecting)                            // if not starting pppd, cleanup
  64.         [delegate DOFinished];
  65.     connecting = NO;                        // pppd will be started yes/NO
  66.     
  67.     return self;
  68. }
  69. //*****************************************************************************
  70. //
  71. //         send to the gatetool server the phone num to dial 
  72. //
  73. //*****************************************************************************
  74.  
  75. - Dial:sender  
  76. {
  77. char dialStr[56] = {"SEND "};
  78.  
  79.     shouldExit = NO;                        
  80.     strncat(dialStr, NXGetDefaultValue([NXApp appName], "dialPrefix"), 8);
  81.     strcat(dialStr, [phoneNumField stringValue]);
  82.         // store last num dialed in defaults database
  83.     if(!NXWriteDefault([NXApp appName], "lastNumDialed", 
  84.                                                 [phoneNumField stringValue]))
  85.         [[NXApp delegate] showAlert:"ddbWriteError"];
  86.     [gateToolProxy enScript:strcat(dialStr, " ")];
  87.     [theInspector inspectName:"SecondInspector"];        // swap inspectors
  88.  
  89.     return self;
  90. }
  91. //*****************************************************************************
  92. //
  93. //         send to the gatetool server quit tip instruction 
  94. //
  95. //*****************************************************************************
  96.  
  97. - cancelDial:sender  
  98. {
  99. char minBuffer[] = {" "};
  100.     
  101.     shouldExit = YES;                        
  102.     minBuffer[0] = CINTR;
  103.     [gateToolProxy writePty:minBuffer];
  104.  
  105.     return self;
  106. }
  107. //*****************************************************************************
  108. //
  109. //         send to the gatetool server quit tip instruction 
  110. //
  111. //*****************************************************************************
  112.  
  113. - hangUp:sender  
  114. {
  115. char prefix[16] = {"PASS "}, minBuffer[3] = {"b "}, dialStr[16];
  116.     
  117.     minBuffer[0] = CEOF;
  118.     strcpy(dialStr, prefix);
  119.     [gateToolProxy enScript:strcat(dialStr, minBuffer)];
  120.     [theInspector inspectName:"FirstInspector"];        // swap inspectors
  121.  
  122.     return self;
  123. }
  124. //*****************************************************************************
  125. //
  126. //         quit tip and launch pppd so that it can attach to serial port 
  127. //
  128. //*****************************************************************************
  129.  
  130. - Attach:sender  
  131. {
  132.     shouldExit = YES;                        
  133.     connecting = YES;                                // pppd will be started
  134.     [gateToolProxy unlockSerialPort];
  135.     [gateToolProxy enScript:"PASS ~. "];
  136.     [delegate linkWithFile:NULL];    
  137.  
  138.     return self;
  139. }
  140. //*****************************************************************************
  141. //
  142. //         self activate 
  143. //
  144. //*****************************************************************************
  145.  
  146. - activateGateKeeper  
  147. {
  148. NXConnection *    myConnection;
  149.  
  150.     [NXApp activateSelf:YES];
  151.     gateToolProxy = [NXConnection connectToName:"GateToolServer"];
  152.     if(gateToolProxy)            // use a protocol for DO efficiency 
  153.         {
  154.         [gateToolProxy setProtocolForProxy:@protocol(serverProtocol)];
  155.                 // return local NXconnection so that we can register for     
  156.                 // invalidation of the proxy's port
  157.         myConnection = [gateToolProxy connectionForProxy];
  158.         [myConnection registerForInvalidationNotification:self];
  159.         }
  160.  
  161.     return self;
  162. }
  163. //*****************************************************************************
  164. //
  165. //         return modem initialization str to use in manual Dial 
  166. //
  167. //*****************************************************************************
  168.  
  169. - (const char *)modemInit  
  170. {
  171. char dialStr[MAXPATHLEN + 1] = {"SEND "};
  172.  
  173.     strncat(dialStr, NXGetDefaultValue([NXApp appName], DIALINIT), 
  174.                                                 MAXPATHLEN - strlen(dialStr));
  175.     strncat(dialStr, " EXPECT OK ", MAXPATHLEN - strlen(dialStr));
  176.  
  177.     return dialStr;
  178. }
  179. //*****************************************************************************
  180. //
  181. //         return the name of modem's serial port  
  182. //
  183. //*****************************************************************************
  184.  
  185. - (const char *)modemPort  
  186. {
  187. int fd;
  188.                                                 // if it exists
  189.     if(fd = open("/etc/ppp/options", O_RDONLY) != -1)    
  190.         {        
  191.         close(fd);                                // parse global options file
  192.         [[[NXApp delegate] optionsEditor] parseOptions:"/etc/ppp/options"];
  193.         }
  194.                                 // parse selected Gatedoc options file
  195.     return [[[[NXApp delegate] optionsEditor] parseOptions:
  196.                                 [[[NXApp delegate] hotListDelegate] 
  197.                                             selGateDocOptionsPath]] devName];
  198. }
  199. //*****************************************************************************
  200. //
  201. //         return the DTE speed of the serial port  
  202. //
  203. //*****************************************************************************
  204.  
  205. - (const char *)modemSpeed  
  206. {
  207. int fd;
  208.                                                 // if it exists
  209.     if(fd = open("/etc/ppp/options", O_RDONLY) != -1)    
  210.         {        
  211.         close(fd);                                // parse global options file
  212.         [[[NXApp delegate] optionsEditor] parseOptions:"/etc/ppp/options"];
  213.         }
  214.                                 // parse selected Gatedoc options file
  215.     return [[[[NXApp delegate] optionsEditor] parseOptions:
  216.                                 [[[NXApp delegate] hotListDelegate] 
  217.                                             selGateDocOptionsPath]] speed];
  218. }
  219. //*****************************************************************************
  220. //
  221. //         return whether MODEM should exit
  222. //
  223. //*****************************************************************************
  224.  
  225. - (BOOL)shouldExit 
  226. {
  227.     return shouldExit;
  228. }
  229.  
  230. - setDelegate:anObject
  231. {
  232.     delegate = anObject;
  233.     connecting = NO;                        // pppd will be started yes/NO
  234.     
  235.     return self;
  236. }
  237.  
  238. - free:sender
  239. {
  240.     if(gatePanel)
  241.         {
  242.         [gatePanel close];
  243.         [gatePanel free];
  244.         }
  245.  
  246.     return [super free];
  247. }
  248.  
  249. @end
  250.  
  251.