Conversation
e2a560c to
c07e4fa
Compare
937a8ae to
27b0f69
Compare
console/src/bin/modules_cli.rs
Outdated
| let flipper = flipper::Flipper::attach(); | ||
| let led = flipper::fsm::led::Led::new(&flipper); | ||
| led.rgb(red, green, blue); | ||
| let flipper = flipper::Flipper::attach_hostname("localhost"); |
There was a problem hiding this comment.
Please make sure you change this back to regular attach, and let's both try to be more mindful of this, it's a mistake I find myself making a lot too :)
languages/rust/src/lf.rs
Outdated
| } | ||
| let ret = libflipper::lf_invoke(flipper.device, module.as_ptr(), index, T::lf_type(), arglist); | ||
| args.map(|args| | ||
| for arg in args.iter() { |
There was a problem hiding this comment.
"Map" functions are generally not intended to have side effects, you can get rid of that outer loop and just use:
for arg in args.iter() {
// ...
}
languages/rust/src/lf.rs
Outdated
| /// let output: u8 = invoke(&flipper, &module, 0, args); | ||
| /// ``` | ||
| pub fn lf_invoke<T: LfReturnable>(flipper: &Flipper, module: &ModuleFFI, index: u8, args: Args) -> T { | ||
| pub fn invoke<T: LfReturnable>(module: &str, index: u8, args: Option<Args>) -> T { |
There was a problem hiding this comment.
With this API, the rust bindings have no means of specifying which Flipper device they would like to use, only the "default" one specified by libflipper will ever be used. Before we wrap this up I would like to add in the capability of creating module instances which are paired to a specific Flipper device.
languages/rust/src/lf.rs
Outdated
| } | ||
| let ret = libflipper::lf_push(flipper.device, module.as_ptr(), index, data.as_ptr() as *const c_void, data.len() as u32, arglist); | ||
| args.map(|args| | ||
| for arg in args.iter() { |
There was a problem hiding this comment.
Same comment as above, should remove the outer "args.map" block and just use
for args in args.iter() {
// ...
}
languages/rust/src/lf.rs
Outdated
| } | ||
| let ret = libflipper::lf_pull(flipper.device, module.as_ptr(), index, buffer.as_mut_ptr() as *mut c_void, buffer.len() as u32, arglist); | ||
| args.map(|args| | ||
| for arg in args.iter() { |
There was a problem hiding this comment.
Same comment as above, should remove the outer "args.map" block and just use
for args in args.iter() {
// ...
}
languages/rust/src/lib.rs
Outdated
| #![deny(unused_import_braces)] | ||
| #![deny(unused_qualifications)] | ||
| #![deny(warnings)] | ||
| //#![deny(warnings)] |
There was a problem hiding this comment.
Please make sure you put this back when you're done :)
languages/rust/src/lib.rs
Outdated
| /// is used when communicating with libflipper to specify which | ||
| /// device functions should be executed on. | ||
| device: _lf_device, | ||
| device: _lf_device |
There was a problem hiding this comment.
I tend to like keeping the trailing commas on multi line lists like structs. If you remember to set this back that'd be cool.
languages/rust/src/fsm/led.rs
Outdated
| ModuleFFI, | ||
| _lf_module, | ||
| }; | ||
| pub struct Led; |
There was a problem hiding this comment.
I think we need to find some way to provide both an instance-level API and a module-level (similar to Java static) API such that the module level Led::rgb uses the default device and the instance-level led.rgb will use a specific device.
languages/rust/src/lf.rs
Outdated
| use ::{ModuleFFI, _lf_module}; | ||
| use std::ffi::CString; | ||
|
|
||
| pub type _lf_device = *const c_void; |
There was a problem hiding this comment.
I'm wondering whether the _lf_device type should just be c_void so that in the lf_invoke signature it's clearer that it's a pointer by having lf_invoke(device: *const _lf_device, ...)
There was a problem hiding this comment.
That is a good point. Should I change that?
| fn from(ret: LfReturn) -> Self { ret.0 as u64 } | ||
| } | ||
|
|
||
| pub fn current_device() -> _lf_device { |
There was a problem hiding this comment.
I don't think we should have a public function which returns a raw pointer. This should either be pub(crate) or we should find a way to do without this entirely.
languages/rust/src/lib.rs
Outdated
|
|
||
| impl Flipper { | ||
| pub fn attach() -> Self { | ||
| pub fn attach() -> _lf_device { |
There was a problem hiding this comment.
The _lf_device type shouldn't appear in the public API at all. If it needs to exist, it should be stored as a private field in a struct.
runtime/include/flipper/types.h
Outdated
| #define LF_WEAK __attribute__((weak)) | ||
|
|
||
| #ifdef __clang__ | ||
| #define LF_FUNC(MODULE) __attribute__((section("__TEXT,.lm."MODULE), used)) |
There was a problem hiding this comment.
Can you add a space between "__TEXT,.lm." and MODULE? When this header is imported in C++, this breaks, because MODULE is interpreted as a literal suffix
bc5228b to
861a0cf
Compare
bd71c2d to
cfce0bd
Compare
cfce0bd to
36e0be8
Compare
Necessary for compatibility with gcc.
|
ASF time! Soon! |
Fixes compatibility issues with dyld on Ubuntu 18.04.
Not ready to merge.
Implement a dynamic loader across libflipper and the device. Goal: Resolve symbols from higher level languages to make it easier to write bindings.
Changes
This PR basically removes the need to worry about a
struct _lf_module *in user-land. Although this data type still exists, it is internal to libflipper and shouldn't be touched from the outside.The signatures of
lf_invoke,lf_push,lf_pullare now as follows:struct _lf_device *as the first parameter.struct _lf_module *, they now accept achar *for the module parameter. This is the name of the module that is to be invoked, pushed, or pulled on.lf_bindhas gone bye-byeThere is no need for
lf_bindanymore! When an invoke is performed, libflipper will automatically do whatlf_binddid behind the scenes. The user doesn't have to worry about it anymore.So to change the language bindings:
struct _lf_module *.lf_bind.