rrivirr / rriv-rust

GNU General Public License v3.0
3 stars 4 forks source link

Command Callback Registration #6

Closed ZavenArra closed 1 year ago

ZavenArra commented 1 year ago

Function pointers corresponding to each command are registered with a tuple of (objectType, actionType)

Acceptance Criteria

ZavenArra commented 1 year ago
C/C++

setSensor(SensorPayload payload)
getSessor()
setActuator()
getActuator()

setupCommands(){
   rust.registerCommand( ‘sensor’, ‘get’, &getSensor)
   rust.registerCommand( ‘sensor’, set’, &setSensor)
}

RUST

struct SensorPayload {
    warmUpTime
    pinNumber
    Etc….
   // some or all of these can be null
   // we will stuff like -1 to handle nulls
}

gotMessage( payload) {
  identity = f”{payload.objectType}_{payload.commandType}”
  cFunction = commandRegistery.get(identity)

 //  map payload to the right struct for this identity
 // call the .init of this struct
//  note: all these structs are FFI’d back to C and are used in the def’n of the functions that are 
// passed as pointers
 theObjectToPassBackToC = {
    cFunction,
           payloadMappedToTheRightObject
  }
  cExecuterFunction(    theObjectToPassBackToC)
}
ZavenArra commented 1 year ago

Leave the FFI payload struct type and mapping JSON to the right struct out of this ticket.