Skip to content

buttplugio/buttplug-rs-ffi

master
Switch branches/tags
Code

Buttplug Rust - FFI for Other Languages

Patreon donate button Github donate button Discord Twitter

FFI Implementations from the buttplug-rs Rust Sex Toy Control Library to other langauges.

If you don't work in Rust but still want to control sex toys, you're in the right place!

Support The Project

If you find this project helpful, you can support us via Patreon or Github Sponsors! Every donation helps us afford more research materials (sex toys).

FFI Implementations

Finished FFI implementations available in this repo:

Implementations currently in the works:

  • Python
  • C/C++

Implementations we'd like to see:

  • Java/Kotlin
  • Swift
  • Idris

Implementation Details

The Buttplug Rust FFI library exposes access to the Buttplug Client API of buttplug-rs. This allows creation of both in-process (i.e. run both a Buttplug client/server in the same process, including direct hardware access) and remote (i.e. use Buttplug Client to talk via Websockets/Pipes/etc to a remote Buttplug server) Buttplug Clients. From these clients, you can scan for and get back device objects, which allow for control of devices from the language of your choice.

The usable API surface of Buttplug is fairly small. The bulk of the library consists of internal configuration, protocol translation, and hardware communication. If the FFI layer seems small, that's because it is. There really aren't that many entry points into the library itself, which luckily makes building FFI easy.

For simple type conversion purposes, the FFI layer uses protobufs. Protobufs provide a simple, fast way to deal with type differences between many languages, and due to the low frequency of message updates in buttplug (we might send 100s of messages per second in a system with multiple devices, but usually its 10s), the overhead of the conversion process isn't too expensive for us. Flatbuffers were originally considered and implemented for C#, but ended up causing developer friction on bringup. We don't really need the ability to pick out fields to parse, as we'll always be using the full message in arguments.

For more information on FFI and Rust using intermediate serialization layers, check out the following articles:

The actual FFI layer consists of a few exposed cdecl functions (see the export.rs file for method definitions) that serve as message passing interfaces in and out of the system. These functions should handle being called from different threads.

Implementation Plans

The library currently implements FFI from Rust to the following languages:

  • C#
  • JS/Typescript for web via WASM and Typescript

Our current plans are to expand to the following list of languages:

  • JS/Typescript for Node
  • Python
  • C/C++
  • Swift
  • Java
  • Go
  • Haskell

If you have any languages you would like to see supported, please file an issue and let us know.

Support

If you have questions, support is available via:

Contributing

If you would like to help provide language implementations for buttplug-rs-ffi, please create an issue or comment on a related issue in our tracker.

Please discuss any interest in providing implementations in an issue (or privately with qdot on discord or twitter DMs if you would like to stay anonymous and out of recorded info on the repo) before submitting PRs. Random PRs without matching issues and discussion are likely to be closed without merging.

License

buttplug-rs-ffi is BSD licensed.

Copyright (c) 2016-2020, Nonpolynomial Labs, LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of buttplug nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.