Process.c 2.7 KB

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