Page 5 of 7

Re: Troubles in Commodity-land

Posted: Sun Dec 06, 2015 8:27 pm
by chris
tboeckel wrote:
chris wrote:but I can't really be bothered to argue about it and the bugtracker won't let me add to or re-open the bug anyway.
Did you try to login? Your account is approved. As such you are able to comment and to reopen tickets. But that requires a successfull login. Otherwise everything is forbidden or at least will require moderation by us. Lots of other persons have no problems to comment and to reopen tickets. I don't think you are an exception from the rule here.
Pretty sure I was logged in, but I may not have been. Anyway, it's probably more useful to follow the discussion here.

Re: Troubles in Commodity-land

Posted: Sun Dec 06, 2015 9:05 pm
by trixie
@chris
Yes, definitely something that can't be enabled/disabled is not a commodity.
I'll try to update the wiki with some more specific information about what a commodity is, and what types of program should (not) be implemented as a commodity.

@xenic
I'll try not to be too restrictive in doing that :-)

@OldFart
In the wiki I have now fixed the three wrong rawmouse qualifier strings for which you and xenic have found correct replacements:
http://wiki.amigaos.net/wiki/Commoditie ... on_Strings
Still no replacement for "relativemouse", though. :-( I guess you've tried "mouse_relative" already? :-)

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 12:03 pm
by OldFart
@trixie

After a few days of absence, I discovered this thread to have grown a few pages with quite some interesting remarks and suggestions.

In the meantime for my further investigation and comprehension of the matter, I took the HotKey.c example from the wiki, made it suitable for OS4 and used it as a testbed for my further experiments. Here's the code:

Code: Select all

/*
** HotKey.c - Simple hot key commodity
*/

#include <exec/libraries.h>
#include <libraries/commodities.h>
#include <dos/dos.h>
 
#include <proto/exec.h>
#include <proto/commodities.h>
#include <proto/dos.h>

#define EVT_HOTKEY 1L

#define CX_FILTERPATTERN "rawkey control esc"
 
struct NewBroker newbroker = {  NB_VERSION
                             , "Amiga HotKey"
                             , "A Simple HotKey"
                             , "A simple hot key commodity"
                             ,  NBU_UNIQUE | NBU_NOTIFY
                             , 0
                             , 0
                             , NULL
                             , 0
                             };
 
 
int main(int argc, char **argv)
{
  IDOS->Printf("INFO : Setup commodity...\n");

  /*
  ** A port is added to struct NewBroker:
  */

  newbroker.nb_Port = IExec->AllocSysObject(ASOT_PORT, TAG_END);

  if (newbroker.nb_Port != NULL)
   {
    CxObj *broker = ICommodities->CxBroker(&newbroker, NULL);

    /*
    ** The port's signal number is retrieved
    ** and used to construct a signal flag:
    */
    uint32 cxsigflag = 1L << newbroker.nb_Port->mp_SigBit;
 
    if (broker != NULL)
     {
      /*
      ** A filter is set up in order
      ** to retrieve the input events
      ** we are looking for, as specified
      ** in CX_FILTERPATTERN:
      */
      CxObj *filter  = CxFilter(CX_FILTERPATTERN),
            *sender,
            *translate;
      int32 CxErr;

      if (filter != NULL)
       {
        /*
        ** The filter is attached to the broker:
        */
        ICommodities->AttachCxObj(broker, filter);
 
        /*
        ** Subsequently a sender is constructed,
        ** te signal the broker when an inputevent
        ** has occurred.
        ** The sender is subsequently attached to
        ** the filter object:
        */
   
        if (sender = CxSender(newbroker.nb_Port, EVT_HOTKEY))
         {
          ICommodities->AttachCxObj(filter, sender);
 
          /*
          ** Finally, a translator object is constructed
          ** and added to the chain of objects. Translator
          ** objects should be the last in the chain.
          ** Giving it a 'NULL'-value makes the translator
          ** stops the filtered-out inputevents from going
          ** further through the input event stream, which
          ** would be of little use:
          */
          if (translate = CxTranslate(NULL))
           {
            ICommodities->AttachCxObj(filter, translate);
 
            CxErr = ICommodities->CxObjError(filter);

            if (CxErr == 0)
             {
              CxMsg *msg;
              uint32 msgid,
                     msgtype,
                     sigrcvd;

              ICommodities->ActivateCxObj(broker, 1L);
              BOOL Done = FALSE;
              IDOS->Printf("INFO : Here we go...\n");

              while (Done == FALSE)
               {
                sigrcvd = IExec->Wait(SIGBREAKF_CTRL_C | cxsigflag);
  
                while (msg = (CxMsg *)IExec->GetMsg(newbroker.nb_Port))
                 {
                  msgid   = ICommodities->CxMsgID(msg);
                  msgtype = ICommodities->CxMsgType(msg);
                  IExec->ReplyMsg((struct Message *)msg);
 
                  switch (msgtype)
                   {
                    case CXM_IEVENT:
                     {
                      IDOS->Printf("A CXM_EVENT, ");
 
                      switch(msgid)
                       {
                        case EVT_HOTKEY: /* We got the message from the sender CxObject */
                         {
                          IDOS->Printf("You hit the HotKey.\n");

                          break;
                         }

                        default:
                         {
                          IDOS->Printf("unknown.\n");
                         }
                       }
 
                      break;
                     }

                    case CXM_COMMAND:
                     {
                      IDOS->Printf("A command: ");

                      switch(msgid)
                       {
                        case CXCMD_DISABLE:
                         {
                          IDOS->Printf("CXCMD_DISABLE\n");
                          ICommodities->ActivateCxObj(broker, 0L);

                          break;
                         }
 
                        case CXCMD_ENABLE:
                         {
                          IDOS->Printf("CXCMD_ENABLE\n");
                          ICommodities->ActivateCxObj(broker, 1L);

                          break; 
                         }

                        case CXCMD_KILL:
                         {
                          IDOS->Printf("CXCMD_KILL\n");
                          Done = TRUE;

                          break;
                         }

                        case CXCMD_UNIQUE:
                         {
                          IDOS->Printf("CXCMD_UNIQUE\n");
                          Done = TRUE;

                          break;
                         }

                        default:
                         {
                          IDOS->Printf("Unknown msgid\n");
                         }
                       }

                      break;
                     }

                    default:
                     {
                      IDOS->Printf("Unknown msgtype\n");
                     }
                   }
  
                  if (sigrcvd & SIGBREAKF_CTRL_C)
                   {
                    Done = TRUE;
                    IDOS->Printf("CTRL C signal break\n");
                   }
                 }
               }

              /*
              ** Cleanup the list of possible remaining messages from
              ** the broker's messageport, by replying those messages.
              ** Failing to do so, MIGHT result in a number of pending
              ** messages, which will NEVER get an answer and so remain
              ** in their message queue, thereby just eating memory:
              */

              while (msg = (CxMsg *)IExec->GetMsg(newbroker.nb_Port))
               {
                IExec->ReplyMsg((struct Message *)msg);
               }
             }
            else
             {
              IDOS->Printf("ERROR: %ld\n", CxErr);
             }
           }
         }
       }

      ICommodities->DeleteCxObjAll(broker);
     }

    IExec->FreeSysObject(ASOT_PORT, newbroker.nb_Port);
   }
 
  return 0;
}
From the commodities.library I took the following sets of Keywords & Qualifiers:

Code: Select all

CONST_STRPTR KeyWord[] = {"DISKINSERTED"
                   ,"DISKREMOVED"
                   ,"EVENT"
                   ,"NEWPOINTERPOS"
                   ,"NEWPREFS"
                   ,"POINTERPOS"
                   ,"RAWKEY"
                   ,"RAWMOUSE"
                   ,"TIMER"
                   , NULL
                   };

CONST_STRPTR Qualifier[] = {"CAPSLOCK"
                     ,"CAPS_LOCK"
                     ,"CONTROL"
                     ,"CTRL"
                     ,"LALT"
                     ,"LAMIGA"
                     ,"LBUTTON"
                     ,"LCOMMAND"
                     ,"LEFTBUTTON"
                     ,"LEFT_ALT"
                     ,"LEFT_AMIGA"
                     ,"LEFT_BUTTON"
                     ,"LEFT_COMMAND"
                     ,"LEFT_SHIFT"
                     ,"LSHIFT"
                     ,"MBUTTON"
                     ,"MIDBUTTON"
                     ,"MIDDLEBUTTON"
                     ,"MIDDLE_BUTTON"
                     ,"NUMERICPAD"
                     ,"NUMERIC_PAD"
                     ,"NUMPAD"
                     ,"NUM_PAD"
                     ,"RALT"
                     ,"RAMIGA"
                     ,"RBUTTON"
                     ,"RCOMMAND"
                     ,"RELATIVEMOUSE"
                     ,"REPEAT"
                     ,"RIGHTBUTTON"
                     ,"RIGHT_ALT"
                     ,"RIGHT_AMIGA"
                     ,"RIGHT_BUTTON"
                     ,"RIGHT_COMMAND"
                     ,"RIGHT_SHIFT"
                     ,"RSHIFT"
                     ,"ALT"
                     ,"CAPS"
                     ,"SHIFT"
                     ,"UPSTROKE"
                     ,"MOUSE_4THPRESS"
                     ,"MOUSE_5THPRESS"
                     ,"MOUSE_LEFTPRESS"
                     ,"MOUSE_MIDDLEPRESS"
                     ,"MOUSE_RIGHTPRESS"
                     ,"BACKSPACE"
                     ,"BREAK"
                     ,"COMMA"
                     ,"CURSOR_DOWN"
                     ,"CURSOR_LEFT"
                     ,"CURSOR_RIGHT"
                     ,"CURSOR_UP"
                     ,"DEL"
                     ,"DELETE"
                     ,"DOWN"
                     ,"END"
                     ,"ENTER"
                     ,"ESC"
                     ,"ESCAPE"
                     ,"F1"
                     ,"F10"
                     ,"F11"
                     ,"F12"
                     ,"F2"
                     ,"F3"
                     ,"F4"
                     ,"F5"
                     ,"F6"
                     ,"F7"
                     ,"F8"
                     ,"F9"
                     ,"HELP"
                     ,"HOME"
                     ,"INSERT"
                     ,"LEFT"
                     ,"MEDIA_NEXT"
                     ,"MEDIA_PLAY"
                     ,"MEDIA_PREV"
                     ,"MEDIA_REPEAT"
                     ,"MEDIA_SHUFFLE"
                     ,"MEDIA_STOP"
                     ,"PAGE_DOWN"
                     ,"PAGE_UP"
                     ,"PAUSE"
                     ,"PRINTSCREEN"
                     ,"RETURN"
                     ,"RIGHT"
                     ,"SPACEBAR"
                     ,"TAB"
                     ,"UP"
                     , NULL
                     };
I'll try and have every keyword attach to every qualifier and see whether that produces a viable CxFilter by checking the errorcode it sets.

I enjoyed following this thread and see what and where it has lead to!

OldFart

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 1:21 pm
by trixie
@OldFart
I'll try and have every keyword attach to every qualifier and see whether that produces a viable CxFilter by checking the errorcode it sets.
Great! In the meantime I'll put the adapted Hotkey.c example in the wiki if you don't mind.

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 1:34 pm
by OldFart
@trixie

No, i don't mind the revised HotKey-example to be included in the wiki.

Here's the (rather lengthy) list of possible combinations of keywords and qualifiers:

Code: Select all

Possible combinations of keywords and qualifiers:

KeyWord(s):
DiskInserted
DiskRemoved
Event
NewPointerPos
NewPrefs
PointerPos
Timer

These keywords accept the following (or no) qualifiers:
                      "CAPSLOCK"
                     ,"CAPS_LOCK"
                     ,"CONTROL"
                     ,"CTRL"
                     ,"LALT"
                     ,"LAMIGA"
                     ,"LBUTTON"
                     ,"LCOMMAND"
                     ,"LEFTBUTTON"
                     ,"LEFT_ALT"
                     ,"LEFT_AMIGA"
                     ,"LEFT_BUTTON"
                     ,"LEFT_COMMAND"
                     ,"LEFT_SHIFT"
                     ,"LSHIFT"
                     ,"MBUTTON"
                     ,"MIDBUTTON"
                     ,"MIDDLEBUTTON"
                     ,"MIDDLE_BUTTON"
                     ,"NUMERICPAD"
                     ,"NUMERIC_PAD"
                     ,"NUMPAD"
                     ,"NUM_PAD"
                     ,"RALT"
                     ,"RAMIGA"
                     ,"RBUTTON"
                     ,"RCOMMAND"
                     ,"RELATIVEMOUSE"
                     ,"REPEAT"
                     ,"RIGHTBUTTON"
                     ,"RIGHT_ALT"
                     ,"RIGHT_AMIGA"
                     ,"RIGHT_BUTTON"
                     ,"RIGHT_COMMAND"
                     ,"RIGHT_SHIFT"
                     ,"RSHIFT"
                     ,"ALT"
                     ,"CAPS"
                     ,"SHIFT"
                     ,"UPSTROKE"
-------------------------------------------------------

KeyWord(s):
RawKey

These keywords accept the following (or no) qualifiers:

                      "BACKSPACE"
                     ,"BREAK"
                     ,"COMMA"
                     ,"CURSOR_DOWN"
                     ,"CURSOR_LEFT"
                     ,"CURSOR_RIGHT"
                     ,"CURSOR_UP"
                     ,"DEL"
                     ,"DELETE"
                     ,"DOWN"
                     ,"END"
                     ,"ENTER"
                     ,"ESC"
                     ,"ESCAPE"
                     ,"F1"
                     ,"F10"
                     ,"F11"
                     ,"F12"
                     ,"F2"
                     ,"F3"
                     ,"F4"
                     ,"F5"
                     ,"F6"
                     ,"F7"
                     ,"F8"
                     ,"F9"
                     ,"HELP"
                     ,"HOME"
                     ,"INSERT"
                     ,"LEFT"
                     ,"MEDIA_NEXT"
                     ,"MEDIA_PLAY"
                     ,"MEDIA_PREV"
                     ,"MEDIA_REPEAT"
                     ,"MEDIA_SHUFFLE"
                     ,"MEDIA_STOP"
                     ,"PAGE_DOWN"
                     ,"PAGE_UP"
                     ,"PAUSE"
                     ,"PRINTSCREEN"
                     ,"RETURN"
                     ,"RIGHT"
                     ,"SPACEBAR"
                     ,"TAB"
                     ,"UP"
-------------------------------------------------------

KeyWord(s):
RawMouse

These keywords accept the following (or no) qualifiers:

                      "MOUSE_4THPRESS"
                     ,"MOUSE_5THPRESS"
                     ,"MOUSE_LEFTPRESS"
                     ,"MOUSE_MIDDLEPRESS"
                     ,"MOUSE_RIGHTPRESS"
At this moment not all combinations make equally great sense to me, but time and experiences will tell soon enough.


N.b.:
In the Function Reference listing, at the end of the wiki pages on the subject, the function CxTranslate() is mentioned twice. When you're at it...


OldFart

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 8:15 pm
by xenic
@OldFart
I was in the process of updating the HotKey.c example myself before I noticed that you had posted your code.

I looked at your example code and have a couple of comments:
1. This code doesn't look right even though it may work:

Code: Select all

CxObj *filter  = CxFilter(CX_FILTERPATTERN),
					*sender,
					*translate;
In the original RKM manuals, the old developers CDs and the OS4 WIKI the filter is assigned like this:

Code: Select all

     CxObj *filter = CxFilter(CX_FILTERPATTERN);
I think the structure of a CxObj is not specifically defined in the includes because CxObjs are designed
to be created by Commodities functions and macros in a transparent way.

2. The original examples disable SASC ctrl-c which I think should be replaced with:

Code: Select all

	signal(SIGINT, SIG_IGN);
It's my understanding that any program that handles ctrl-c (SIGBREAKF_CTRL_C) itself should
disable C library handling of ctrl-c. I've read that unless you set up a specific handler for the C
library to use when it intercepts a break (ctrl-c) the program can exit without releasing resources.

I could easily be wrong in the above comments and would welcome any corrections. Please don't take
my comments in a negative way; I'm just trying to help.

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 8:30 pm
by OldFart
@xenic

Code: Select all

CxObj *filter  = CxFilter(CX_FILTERPATTERN),
               *sender,
               *translate;
This could be rewritten by and have the same meaning:

Code: Select all

CxObj *filter,
               *sender,
               *translate;

filter = CxFilter(CX_FILTERPATTERN);
In the first instance 'filter' is being initialised when declared, quite a common practice. Initialisation is followed suit with two more declarations. As far as I know, this is legal practice and should therefore not cause any problems.

Code: Select all

signal(SIGINT, SIG_IGN);
If this is true then I have learned a bit more today then I had expected.
Please don't take my comments in a negative way; I'm just trying to help.
Don't worry: I am not easily offended. Really not.

It is a great thing that knowledge, and what is being passed for it, can be and is shared in these fora. Together we are so much stronger.

OldFart

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 8:37 pm
by broadblues
1. This code doesn't look right even though it may work:

Code: Select all

CxObj *filter  = CxFilter(CX_FILTERPATTERN),
					*sender,
					*translate;
That's perfectly valid code, albeit not quite the way I'd have written it for readabilty.

Would you say:

Code: Select all

int a = 1,b,c;
was invalid?

2. The original examples disable SASC ctrl-c which I think should be replaced with:

Code: Select all

	signal(SIGINT, SIG_IGN);
That is the way to do it in newlib yes.
It's my understanding that any program that handles ctrl-c (SIGBREAKF_CTRL_C) itself should
disable C library handling of ctrl-c. I've read that unless you set up a specific handler for the C
library to use when it intercepts a break (ctrl-c) the program can exit without releasing resources.
But the code above doesn't do anything where CTRL-C could be handled by the C-library (typical CTRL-C is only tested for when executing stdio functions, but his code doesn't acll any C-Library functions at all as far as I can see, (startup code doesn't count)) so in context of that simple program he is okay.

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 9:09 pm
by OldFart
@broadblues

The code got a bit garbled and cluttered while it reached this forum. I had the intention to have the asterisks (*) of the variables line-up in one and the same column. I hope this is better:

Code: Select all

CxObj *filter  = CxFilter(CX_FILTERPATTERN),
      *sender,
      *translate;
Would you say:

Code: Select all

int a = 1,b,c;
was invalid?
No, absolutely not! It is perfectly valid code, but I tend to avoid c.q. rework such code to show one variable per line. For sake of readabillity, you know... ;-)

About the break signal stuff:
I was somehow lead to believe that the startup-code as supplied by the SDK was dealing with this matter.

OldFart

Re: Troubles in Commodity-land

Posted: Mon Dec 07, 2015 10:30 pm
by xenic
broadblues wrote:

Code: Select all

CxObj *filter  = CxFilter(CX_FILTERPATTERN),
					*sender,
					*translate;
That's perfectly valid code, albeit not quite the way I'd have written it for readabilty.
Duh. I misread the code. You're right.
But the code above doesn't do anything where CTRL-C could be handled by the C-library (typical CTRL-C is only tested for when executing stdio functions, but his code doesn't acll any C-Library functions at all as far as I can see, (startup code doesn't count)) so in context of that simple program he is okay.
If it's true that CTRL-C is only trapped by stdio functions then I guess it's unnecessary to disable it.