Skip to content

Communication API

nelsonje edited this page Jan 14, 2013 · 1 revision

Message API

I see three standard uses for messages:

  1. Simple remote execution.

     {
       auto m = scopedMessage( core, 
                               [] { 
                                    fn(); 
                                  } 
                             );
       m.block_until_sent(); // optional
     }
    
  2. Remote execution with variable-sized payload. Payload is copied into message.

     {
       auto m = scopedPayloadMessage( core, 
                                      [] ( void * payload, int16_t size ) { 
                                        fn( payload, size ); 
                                      } 
                                      payload, size );
       m.block_until_sent();  // optional
     }
    
  3. Legacy message to interact with existing active messages. Args struct and payload are copied into message.

     {
       auto m = scopedLegacyMessage( core, 
                                     function_pointer,
                                     args_pointer, 
                                     payload_pointer, payload_size
                                   );
       m.block_until_sent();  // optional
     }
    

This is equivalent to

    {
      auto m = scopedPayloadMessage( core, 
                                     []( A* args, void* payload, size_t size) {
                                       function_pointer( args, sizeof(A), payload, payload_size );
                                     },
                                    args_pointer, sizeof(A),
                                    payload_pointer, payload_size
                                  );
      m.block_until_sent();  // optional
    }