home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 418.lha / OdinLibrary_v1.11 / odindemo2.c < prev    next >
C/C++ Source or Header  |  1990-09-01  |  2KB  |  87 lines

  1. /****************************************************************
  2.   odindemo2.c
  3.   Created 11-jul-90 by Peter Oerbak
  4.   Shows off some features of the odin.library V1.11
  5.   This is in the public domain.
  6. *****************************************************************/
  7.  
  8. #include    "exec/types.h"
  9. #include    "exec/semaphores.h"
  10. #include    "exec/tasks.h"
  11. #include    "stdio.h"
  12. #include    "odin.h"
  13.  
  14. struct OdinBase    *OpenLibrary();
  15.  
  16. struct SignalSemaphore    ss;
  17.  
  18. #define CR(s) ObtainSemaphore(&ss); { s } ReleaseSemaphore(&ss);
  19.  
  20. typedef struct {
  21.     Envelope    e;
  22.     char        *windowname;
  23.     int        num;
  24. } Packet;
  25.  
  26. #define p_sizeof (long)sizeof(Packet)
  27. #define PACKNAME "A packet"
  28.  
  29. struct OdinBase *OdinBase;
  30.  
  31. Envelope *new_process(p)
  32. Packet *p;
  33. {
  34.     FILE    *f;
  35.  
  36.     CR(
  37.         f = fopen(p->windowname,"w");
  38.         fprintf(f,"Hello there.\n");
  39.     )
  40.  
  41.     Delay(100L);
  42.     CR(fprintf(f,"bye,bye\n");)
  43.     CR(fclose(f);)
  44.     return (Envelope *)p;
  45. }
  46.  
  47. main()
  48. {
  49.     Packet        *p;
  50.     struct Task    *t;
  51.     Envelope    *env;
  52.  
  53.     if(!(OdinBase = OpenLibrary("ram:odin.library",0L))) {
  54.         printf("No odin library!\n");
  55.         exit(20);
  56.     }
  57.     printf("odin.library open\n");
  58.     InitSemaphore(&ss);
  59.     printf("semaphore inited\n");
  60.     p = (Packet *)CreateEnvelope(PACKNAME,p_sizeof);
  61.     if(!p) {
  62.         printf("no memory for packet\n");
  63.         CloseLibrary(OdinBase);
  64.         exit(20);
  65.     }
  66.     printf("packet created\n");
  67.     p->e.e_proc   = new_process;
  68.     p->num        = 0;
  69.     p->windowname = "CON:10/10/300/200/Process";
  70.     t = Eval(p,0L,4000L,EVAL_PROCESS);
  71.     if(!t) {
  72.         printf("couldn't start new process with Eval()\n");
  73.         DisposeEnvelope(p);
  74.         CloseLibrary(OdinBase);
  75.         exit(20);
  76.     }
  77.     CR(printf("new process started\n");)
  78.     do {
  79.         CR(printf("polling.\n");)
  80.         env = PollNamedEnvelope(PACKNAME);
  81.     } while(!env);
  82.     printf("got envelope\n");
  83.     DisposeEnvelope(env);
  84.     CloseLibrary(OdinBase);
  85. }
  86.  
  87.