chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] more 'foreign' questions


From: Kon Lovett
Subject: Re: [Chicken-users] more 'foreign' questions
Date: Wed, 27 Mar 2019 09:04:29 -0700

i haven’t used the bind egg  but the documentation "General Operation” section 
beginining with "Structure and union definitions …” seems relevant.

it rolls access routines, ex: mosquitto_message-mid, mosquitto_message-payload, 
...

#;1> (import bind)
; loading /usr/local/chicken/5/lib/chicken/10/bind.import.so ...
; loading /usr/local/chicken/5/lib/chicken/10/chicken.foreign.import.so ...
; loading /usr/local/chicken/5/lib/chicken/10/bind-translator.so ...
; loading /usr/local/chicken/5/lib/chicken/10/matchable.so ...
; loading /usr/local/chicken/5/lib/chicken/10/bind.so ...

#;2> ,x* (bind* "struct mosquitto_message{
          int mid;
          char *topic;
          void *payload;
          int payloadlen;
          int qos;
          ___bool retain;
        };”)
(##core#begin
  (##core#declare
    (foreign-declare
      "#define ___fixnum           int\n#define ___number           
double\n#define ___bool             int\n#define ___byte             
char\n#define ___scheme_value     C_word\n#define ___scheme_pointer   void 
*\n#define ___blob             void *\n#define ___pointer_vector   void 
**\n#define ___symbol           char *\n#define ___safe\n#define ___declare(x, 
y)\n#define ___specialize\n#define ___abstract\n#define ___discard\n#define 
___in\n#define ___out\n#define ___inout\n#define ___mutable\n#define 
___length(var)\n#define ___pointer\n#define ___u32              C_u32\n#define 
___s32              C_s32\n#define ___u64              C_u64\n#define ___s64    
          C_s64"
      "struct mosquitto_message{\n          int mid;\n          char *topic;\n  
        void *payload;\n          int payloadlen;\n          int qos;\n         
 ___bool retain;\n        };"
      "\n"))
  (##core#begin
    (##core#begin
      (##core#ensure-toplevel-definition mosquitto_message-mid)
      (##core#set!
        mosquitto_message-mid
        (foreign-lambda*
          integer
          (((c-pointer (struct "mosquitto_message")) s))
          "return(s->mid);")))
    (##core#begin
      (##core#ensure-toplevel-definition mosquitto_message-topic)
      (##core#set!
        mosquitto_message-topic
        (foreign-lambda*
          c-string
          (((c-pointer (struct "mosquitto_message")) s))
          "return(s->topic);")))
    (##core#begin
      (##core#ensure-toplevel-definition mosquitto_message-payload)
      (##core#set!
        mosquitto_message-payload
        (foreign-lambda*
          (c-pointer void)
          (((c-pointer (struct "mosquitto_message")) s))
          "return(s->payload);")))
    (##core#begin
      (##core#ensure-toplevel-definition mosquitto_message-payloadlen)
      (##core#set!
        mosquitto_message-payloadlen
        (foreign-lambda*
          integer
          (((c-pointer (struct "mosquitto_message")) s))
          "return(s->payloadlen);")))
    (##core#begin
      (##core#ensure-toplevel-definition mosquitto_message-qos)
      (##core#set!
        mosquitto_message-qos
        (foreign-lambda*
          integer
          (((c-pointer (struct "mosquitto_message")) s))
          "return(s->qos);")))
    (##core#begin
      (##core#ensure-toplevel-definition mosquitto_message-retain)
      (##core#set!
        mosquitto_message-retain
        (foreign-lambda*
          bool
          (((c-pointer (struct "mosquitto_message")) s))
          "return(s->retain);")))
    (##core#begin
      (##core#ensure-toplevel-definition make-mosquitto_message)
      (##core#set!
        make-mosquitto_message
        (foreign-lambda*
          (c-pointer (struct "mosquitto_message"))
          ((integer mid)
           (c-string topic)
           ((c-pointer void) payload)
           (integer payloadlen)
           (integer qos)
           (bool retain))
          "struct mosquitto_message *tmp_ =  (struct mosquitto_message 
*)C_malloc(sizeof(struct mosquitto_message));\ntmp_->mid = mid;\ntmp_->topic = 
topic;\ntmp_->payload = payload;\ntmp_->payloadlen = payloadlen;\ntmp_->qos = 
qos;\ntmp_->retain = retain;\nreturn(tmp_);;\n")))))

> On Mar 27, 2019, at 8:06 AM, Christoph Lange <address@hidden> wrote:
> 
> After I now managed quite a lot of my interfacing to the mqtt library, I'm 
> stuck with the following:
> 
> I have the following definition of  a message struct, which I in fact get 
> back a pointer to, from a callback:
> 
> (bind* "struct mosquitto_message{
>           int mid;
>           char *topic;
>           void *payload;
>           int payloadlen;
>           int qos;
>           ___bool retain;
>         };")
> 
> When I print what I get in Scheme it says something along the line of 
> #<pointer 0x562b13f1ee58>. Though the library frees the memory, it will -- 
> according to manual -- only do so after the callback returns. So within the 
> callback, I should be able to access / print it's content. Just how?! How do 
> I access the different fields in that struct? Especially the payload?
> 
> /Christoph
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/chicken-users




reply via email to

[Prev in Thread] Current Thread [Next in Thread]