Process.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include "pal.h"
  4. #include "pal_debug.h"
  5. #include "api.h"
  6. int main (int argc, char ** argv, char ** envp)
  7. {
  8. char buffer1[20] = "Hello World 1", buffer2[20] = "Hello World 2";
  9. char buffer3[20], buffer4[20], buffer5[20];
  10. int ret;
  11. if (argc > 1 && !memcmp(argv[1], "Child", 6)) {
  12. pal_printf("Child Process Created\n");
  13. /* check manifest name */
  14. char manifest[30] = "";
  15. DkStreamGetName(pal_control.manifest_handle, manifest, 30);
  16. pal_printf("Loaded Manifest: %s\n", manifest);
  17. /* check arguments */
  18. pal_printf("# of Arguments: %d\n", argc);
  19. for (int i = 0 ; i < argc ; i++)
  20. pal_printf("argv[%d] = %s\n", i, argv[i]);
  21. DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
  22. if (pal_control.broadcast_stream == NULL) {
  23. pal_printf("Warning: broadcast stream is not open. "
  24. "Do you have a multicast route configured?\n");
  25. } else {
  26. ret = DkStreamRead(pal_control.broadcast_stream, 0, 20, buffer5, NULL, 0);
  27. if (ret > 0)
  28. pal_printf("Broadcast Read: %s\n", buffer5);
  29. }
  30. ret = DkStreamWrite(pal_control.parent_process, 0, 20, buffer1, NULL);
  31. if (ret > 0)
  32. pal_printf("Process Write 1 OK\n");
  33. ret = DkStreamRead(pal_control.parent_process, 0, 20, buffer4, NULL, 0);
  34. if (ret > 0)
  35. pal_printf("Process Read 2: %s\n", buffer4);
  36. } else {
  37. PAL_STR args[3] = { "Process", "Child", 0 };
  38. PAL_HANDLE children[3];
  39. for (int i = 0 ; i < 3 ; i++) {
  40. pal_printf("Creating process\n");
  41. children[i] = DkProcessCreate("file:Process", args);
  42. if (children[i]) {
  43. pal_printf("Process created %d\n", i + 1);
  44. DkStreamRead(children[i], 0, 20, buffer4, NULL, 0);
  45. }
  46. }
  47. pal_printf("Broadcasting message\n");
  48. if (pal_control.broadcast_stream == NULL) {
  49. pal_printf("Warning: broadcast stream is not open. "
  50. "Do you have a multicast route configured?\n");
  51. } else {
  52. ret = DkStreamWrite(pal_control.broadcast_stream, 0, 20, buffer1, NULL);
  53. if (ret > 0)
  54. pal_printf("Broadcast Write OK\n");
  55. }
  56. for (int i = 0 ; i < 3 ; i++)
  57. if (children[i]) {
  58. ret = DkStreamRead(children[i], 0, 20, buffer3, NULL, 0);
  59. if (ret > 0)
  60. pal_printf("Process Read 1: %s\n", buffer3);
  61. ret = DkStreamWrite(children[i], 0, 20, buffer2, NULL);
  62. if (ret > 0)
  63. pal_printf("Process Write 2 OK\n");
  64. }
  65. }
  66. return 0;
  67. }