Add tools to the Workbench Tools menu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

broker.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. ToolsMenu - Add tools to the Workbench Tools menu
  3. Copyright (C) 2015, 2018 Kim Fastrup Larsen
  4. This program is free software: you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation, either ver-
  7. sion 3 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be use-
  9. ful, but WITHOUT ANY WARRANTY; without even the implied war-
  10. ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public Li-
  13. cense along with this program. If not, see
  14. <http://www.gnu.org/licenses/>.
  15. The author can be contacted on <kimflarsen@hotmail.com>
  16. */
  17. #include <dos/dos.h>
  18. #include <libraries/commodities.h>
  19. #include <clib/commodities_protos.h>
  20. #include <clib/exec_protos.h>
  21. #ifdef USE_PRAGMAS
  22. #include <proto/commodities.h>
  23. #include <proto/exec.h>
  24. #endif
  25. #include <stdlib.h>
  26. #include <strings.h>
  27. #define CATCOMP_NUMBERS
  28. #include "args.h"
  29. #include "broker.h"
  30. #include "catalog.h"
  31. #include "common.h"
  32. #include "cx.h"
  33. #include "error.h"
  34. #include "strings.h"
  35. static struct MsgPort *broker_port;
  36. static CxObj *broker;
  37. ULONG broker_set_up()
  38. {
  39. struct NewBroker new_broker;
  40. LONG error;
  41. CxObj *filter;
  42. if ((broker_port = CreateMsgPort()) == NULL)
  43. exit(RETURN_FAIL);
  44. memset(&new_broker, 0, sizeof new_broker);
  45. new_broker.nb_Version = NB_VERSION;
  46. new_broker.nb_Name = APP_NAME;
  47. new_broker.nb_Title = TITLE;
  48. new_broker.nb_Descr = get_string(MSG_DESCRIPTION);
  49. new_broker.nb_Unique = NBU_UNIQUE | NBU_NOTIFY;
  50. new_broker.nb_Flags = COF_SHOW_HIDE;
  51. new_broker.nb_Pri = args.cx_priority;
  52. new_broker.nb_Port = broker_port;
  53. if ((broker = CxBroker(&new_broker, &error)) == NULL)
  54. exit((error == CBERR_DUP) ? RETURN_OK : RETURN_FAIL);
  55. if ((filter = CxFilter(args.cx_popkey)) == NULL)
  56. exit(RETURN_FAIL);
  57. AttachCxObj(broker, filter);
  58. AttachCxObj(filter, CxSender(broker_port, 0));
  59. AttachCxObj(filter, CxTranslate(NULL));
  60. if ((error = CxObjError(filter)) != 0) {
  61. if (error == COERR_BADFILTER) {
  62. error_message(get_string(MSG_ERR_HOTKEY), NULL);
  63. exit(RETURN_ERROR);
  64. } else
  65. exit(RETURN_FAIL);
  66. }
  67. ActivateCxObj(broker, 1);
  68. return 1UL << broker_port->mp_SigBit;
  69. }
  70. static void handle_command(ULONG msg_id)
  71. {
  72. switch (msg_id) {
  73. case CXCMD_DISABLE:
  74. ActivateCxObj(broker, 0);
  75. cx_disable();
  76. break;
  77. case CXCMD_ENABLE:
  78. ActivateCxObj(broker, 1);
  79. cx_enable();
  80. break;
  81. case CXCMD_KILL:
  82. cx_quit();
  83. break;
  84. case CXCMD_UNIQUE:
  85. case CXCMD_APPEAR:
  86. cx_show();
  87. break;
  88. case CXCMD_DISAPPEAR:
  89. cx_hide();
  90. break;
  91. }
  92. }
  93. void broker_handle_signal()
  94. {
  95. CxMsg *msg;
  96. ULONG msg_type, msg_id;
  97. while ((msg = (CxMsg *) GetMsg(broker_port)) != NULL) {
  98. msg_type = CxMsgType(msg);
  99. msg_id = CxMsgID(msg);
  100. ReplyMsg((struct Message *) msg);
  101. switch (msg_type) {
  102. case CXM_IEVENT:
  103. /* Must be Hot Key event */
  104. cx_show();
  105. break;
  106. case CXM_COMMAND:
  107. handle_command(msg_id);
  108. break;
  109. }
  110. }
  111. }
  112. void broker_clean_up()
  113. {
  114. if (broker != NULL)
  115. DeleteCxObjAll(broker);
  116. delete_port(broker_port);
  117. }