home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <Types.h>
- #include <SIOUX.h>
- #include <MP.h>
-
-
- static void
- sendString(MPQueueID queue, char *string) {
- /*
- Send the string through the queue one character at a time.
- */
- while (*string) {
- (void) MPNotifyQueue(queue, (void *) *string, 0, 0);
- string++;
- }
-
- (void) MPNotifyQueue(queue, (void *) '\0', 0, 0); /* Send the final null character. */
- }
-
-
- static void
- receiveString(MPQueueID queue, char *string) {
- /*
- Reassemble a string being transferred over the queue and return it to the caller.
- */
- void
- *first, /* The first word of the message. */
- *second, /* The second word of the message. */
- *third; /* The third word of the message. */
-
- for (;;) {
- (void) MPWaitOnQueue(queue, &first, &second, &third, kDurationForever);
- *string = (char) first;
-
- if (*string == '\0') {
- return;
- }
-
- string++;
- }
- }
-
-
- static OSStatus
- HelloWorld(void *parameter) {
- MPQueueID
- queue = parameter;
-
- sendString(queue, "Hello, World!");
-
- return noErr;
- }
-
-
- static int
- failure(char *annotation, char *routine, OSStatus status) {
- printf("Uh oh. %s%s%s returned %s [%d].\n",
- (annotation) ? annotation : "",
- (routine) ? routine : "",
- (routine) ? "()" : "A routine",
- _MPStatusCString(status),
- status);
-
- return 1;
- }
-
-
- int
- main(void) {
- OSStatus
- status; /* We'll use this to test the outcome of each MP function. */
- MPQueueID
- terminationQueue, /* This queue will report the completion of the task. */
- communicationQueue; /* This queue will be used to communicate between the app and the task. */
- MPTaskID
- task; /* This will be the ID of the task we create. */
- char
- myString[100];
-
- SIOUXSettings.asktosaveonclose = 0;
-
- if (!MPLibraryIsLoaded()) {
- printf("Can't run without the \"%s\" shared library.\n", MPLibraryName);
-
- return 1;
- }
-
- status = MPCreateQueue(&terminationQueue); /* Create the queue which will report the completion of the task. */
- if (status != noErr) {
- return failure("Cannot create the termination queue:\n ", "MPCreateQueue", status);
- }
-
- status = MPCreateQueue(&communicationQueue); /* Create the queue we'll use to communicate with. */
- if (status != noErr) {
- (void) MPDeleteQueue(terminationQueue);
-
- return failure("Cannot create the communication queue:\n ", "MPCreateQueue", status);
- }
-
- status = MPCreateTask(HelloWorld, /* This is the task function. */
- communicationQueue, /* This is the parameter to the task function. */
- kMPUseDefaultStackSize, /* We'll use whatever the MP system software gives us. */
- terminationQueue, /* We'll use this to sense task completion. */
- 0, /* We won't use the first part of the termination message. */
- 0, /* We won't use the second part of the termination message. */
- kMPNormalTaskOptions, /* Use the normal task options. (Currently this *must* be zero!) */
- &task); /* Here's where the ID of the new task will go. */
- if (status != noErr) {
- (void) MPDeleteQueue(terminationQueue);
- (void) MPDeleteQueue(communicationQueue);
-
- return failure(0, "MPCreateTask", status);
- }
-
- receiveString(communicationQueue, myString);
- printf("%s\n", myString);
-
- /* Wait for the task to complete: */
- status = MPWaitOnQueue(terminationQueue, 0, 0, 0, kDurationForever);
- if (status != noErr) {
- (void) failure("While waiting for task completion:\n ", "MPWaitOnQueue", status);
- }
-
- status = MPDeleteQueue(terminationQueue);
- if (status != noErr) {
- (void) failure("Can't delete the termination queue:\n ", "MPDeleteQueue", status);
- }
-
- status = MPDeleteQueue(communicationQueue);
- if (status != noErr) {
- (void) failure("Can't delete the communication queue:\n ", "MPDeleteQueue", status);
- }
-
- return 0;
- }
-