Table of Contents Previous Section

Implementing a main() Function

When you use compiled code in a WebObjects application, you have to implement your own main() function. This function creates the autorelease pool, adaptor, and application objects used in your application.

To implement a main() function:

  1. Using any text editor, open a new text file and give it a name that has the extension .m.
  2. For the Registration project, for example, create a file called Registration.m.

  3. Add the following text to the file:
  4.   #import <WebObjects/WOWebScriptApplication.h>
      #import <WebObjects/WOApplicationAdaptor.h>
      #import <foundation/NSAutoreleasePool.h>
      void main(int argc, char *argv[]) {
            NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
            WOApplicationAdaptor *adaptor = 
    
        [[[WOApplicationAdaptor alloc] init] autorelease];
            WOWebScriptApplication *application = [WOWebScriptApplication
    
             sharedInstance];
            [adaptor runWithApplication:application];
            [pool release];
            exit(0);
      }
    

    The function begins by creating an autorelease pool that's used for the automatic deallocation of objects that receive the autorelease message. Next, it creates an adaptor object that will be used to exchange data between the HTTP server and the WebObjects application object, which is created in the next statement. It then runs the adaptor and associates it with the newly created application. "Running" means that the adaptor will forward incoming requests from the server to the application and outgoing responses from the application to the server. The last statement releases the autorelease pool, which sends a release message to any object that has been added to the pool since the application began.

  5. Add the file to your project.
  6. If you're using Project Builder, you do this by dragging the file into the Other Sources suitcase in your project.

Table of Contents Next Section