diff --git a/docs/deviceSpec.md b/docs/deviceAttachmentSpec.md similarity index 78% rename from docs/deviceSpec.md rename to docs/deviceAttachmentSpec.md index 80ff95c..01ef712 100644 --- a/docs/deviceSpec.md +++ b/docs/deviceAttachmentSpec.md @@ -1,4 +1,4 @@ -# Device manager: attaching sensors and actuators. +# Device Attachment Specification DSL: attaching sensors and actuators to SMO. ## Attaching sensors: @@ -14,15 +14,17 @@ basically what conventional ML/LLM/ANN developers call an ROI ("Region of Interest") extraction algorithm. An Implex algorithm is used to scan a frame of input sensor data and detect objects and patterns within it. -## Sensor device spec: +## Sensor device attachment specification: -The general format of a device-spec for a sensor is: +The general format of a device attachment specification for a sensor is: ``` -sensor-type|implexor|api(api-params)|provider(provider-params)|deviceselector +sensor-type|dev-identifier + |implexor|api(api-params)|provider(provider-params)|deviceselector ``` * `sensor-type` is always either '`+idev`' (interoceptor), '`+edev`' (extrospector), or '`+adev`' (actuator). +* `dev-identifier` is a user-defined name for this specific device instance. * `implexor` is the name of the implexor algorithm that should be used with the data that is provided by the `provider` via the `api`. * `api` is the interface that the provider uses to export perceptual data for @@ -35,9 +37,9 @@ sensor-type|implexor|api(api-params)|provider(provider-params)|deviceselector which case the parenthesis will be empty, but the parentheses must always be written out. * `device selector` is the idiosyncratic label/name used by the `provider` to - identify the specific device you want to access via that `provider`. + identify the specific device you want to attach via that `provider`. -## `API-params` and `provider-params` : +## `API-params` and `provider-params`: If there's more than one parameter item in a list of `api-params` or `provider-params`, then the individual items in a list of `api-param` or @@ -55,7 +57,7 @@ Some examples follow: ### To attach a particular window from a window manager: ``` -+edev|visual-implexor|wayland()|wayland(server-socket)|window0 ++edev|my-window|visual-implexor|wayland()|wayland(server-socket)|window0 ``` Connect to the Wayland server that's listening on `server-socket`, using the `wayland` api. Ask that Wayland server to give salmanoff read-access to all of @@ -64,7 +66,7 @@ the frames composited into the window buffer for `window0`. Use salmanoff's ### To attach a window manager's entire rendered desktop: ``` -+edev|visual-implexor|wayland()|wayland(listen-socket)|all ++edev|my-desktop|visual-implexor|wayland()|wayland(listen-socket)|all ``` In most cases, this is basically the same as attempting to attach all of the underlying GFX server's output. @@ -76,7 +78,7 @@ that Wayland server's compositor data. ### To attach all of an Xorg server's gfx output to all screens: ``` -+edev|visual-implexor|x11()|xorg(listen-socket)|all ++edev|my-xorg-display|visual-implexor|x11()|xorg(listen-socket)|all ``` Connect to the Xorg server that's listening on `listen-socket`, using the `x11` @@ -93,7 +95,7 @@ WM's output. ### To attach all of an Xorg server's gfx output to a particular screen: ``` -+edev|visual-implexor|x11()|xorg(listen-socket)|:0 ++edev|my-screen|visual-implexor|x11()|xorg(listen-socket)|:0 ``` Connect to the Xorg server that's listening on `listen-socket`, using the `x11` api. Ask that Xorg server to let Salmanoff read out all of the frames written @@ -106,7 +108,7 @@ out to display `:0`. Use salmanoff's `visual-implexor` to implex from display ### To attach a camera device by connecting directly to its Linux driver: ``` -+edev|visual-implexor|v4l()|linux()|/dev/video0 ++edev|my-camera|visual-implexor|v4l()|linux()|/dev/video0 ``` We specify that we want to use the `linux` kernel's loaded driver to connect to communicate with `/dev/video0`, via the `Video4Linux` API. We want salmanoff @@ -116,7 +118,7 @@ If `/dev/video0` is already consumed by another process, this may likely fail. ### To attach a microphone that's managed by ALSA server: ``` -+edev|audio-implexor|alsa(shmem)|alsa()|cardname ++edev|my-microphone|audio-implexor|alsa(shmem)|alsa()|cardname ``` Connect to the ALSA server via `shmem`, using the `alsa` API. Request access to @@ -125,7 +127,7 @@ the microphone function of the sound card with the name `cardname`. Use the ### To attach a thermal sensor managed by Linux: ``` -+idev|thermal-implexor|thermal-zone()|linux()|/sys/class/thermal_zone0 ++idev|my-thermal|thermal-implexor|thermal-zone()|linux()|/sys/class/thermal_zone0 ``` Use the `thermal-zone` SysFS API provided by `linux` to connect to the sensor @@ -147,18 +149,20 @@ types of devices will require different wilzor algorithms. You need to know what type of wilzor algorithm needs to be used to enable salmanoff to control your actuator device. -The general format for an actuator's device spec is: +The general format for an actuator's device attachment specification is: ``` WIP: TBD. ``` -## Device specification files: +## Device attachment specification files: -Inside of a device spec file, you can list any number of device specs. -Separate individual device specs with two consecutive h-bar characters (`||`), +Inside of a device attachment specification file, you can list any number of +device attachment specifications. +Separate individual device attachment specifications with two consecutive h-bar +characters (`||`), like this: ``` -+edev|visual-implexor|wayland()|wayland(server-socket)|window0 -|| +edev|visual-implexor|x11()|xorg(listen-socket)|all -|| +idev|thermal-implexor|thermal-zone()|linux()|/sys/class/thermal_zone0 ++edev|my-window|visual-implexor|wayland()|wayland(server-socket)|window0 +|| +edev|my-xorg-display|visual-implexor|x11()|xorg(listen-socket)|all +|| +idev|my-thermal|thermal-implexor|thermal-zone()|linux()|/sys/class/thermal_zone0 ``` diff --git a/include/user/senseDeviceSpec.h b/include/user/deviceAttachmentSpec.h similarity index 69% rename from include/user/senseDeviceSpec.h rename to include/user/deviceAttachmentSpec.h index 2170c4b..aa12028 100644 --- a/include/user/senseDeviceSpec.h +++ b/include/user/deviceAttachmentSpec.h @@ -9,24 +9,26 @@ namespace smo { namespace device { -class SenseDeviceSpec +class DeviceAttachmentSpec { public: friend std::ostream& operator<<( - std::ostream& os, const SenseDeviceSpec& spec) + std::ostream& os, const DeviceAttachmentSpec& spec) { os << spec.stringify(); return os; } - bool operator==(const SenseDeviceSpec& other) const + bool operator==(const DeviceAttachmentSpec& other) const { - return sensorType == other.sensorType && + return deviceIdentifier == other.deviceIdentifier && + sensorType == other.sensorType && provider == other.provider && deviceSelector == other.deviceSelector; } public: + std::string deviceIdentifier; char sensorType; std::string implexor; std::string api; @@ -38,8 +40,10 @@ public: std::string stringify() const { std::ostringstream os; - os << "Device: " << sensorType << ", Implexor: " - << implexor << ", API: " << api << ", API Params: ("; + os << "Device Identifier: " << deviceIdentifier + << ", Sensor Type: " << sensorType + << ", Implexor: " << implexor << ", API: " << api + << ", API Params: ("; for (const auto& param : apiParams) { os << param.first; @@ -63,11 +67,11 @@ public: } }; -class InteroceptorDeviceSpec : public SenseDeviceSpec +class InteroceptorDevAttachmentSpec : public DeviceAttachmentSpec { }; -class ExtrospectorDeviceSpec : public SenseDeviceSpec +class ExtrospectorDevAttachmentSpec : public DeviceAttachmentSpec { }; diff --git a/include/user/senseApiDesc.h b/include/user/senseApiDesc.h index d57caff..855d63c 100644 --- a/include/user/senseApiDesc.h +++ b/include/user/senseApiDesc.h @@ -1,12 +1,12 @@ #ifndef __USER_SENSE_API_LIB_H__ #define __USER_SENSE_API_LIB_H__ -#include #include -#include #include #include #include +#include +#include namespace smo { namespace sense_api { @@ -14,9 +14,9 @@ namespace sense_api { typedef int (sal_mlo_initializeIndFn)(void); typedef int (sal_mlo_finalizeIndFn)(void); typedef int (sal_mlo_attachDeviceReqFn)( - const std::shared_ptr& desc); + const std::shared_ptr& desc); typedef int (sal_mlo_detachDeviceReqFn)( - const std::shared_ptr& desc); + const std::shared_ptr& desc); /** * @brief Hooks provided by Salmanoff to senseApi libraries. diff --git a/senseApis/xcbWindow/xcbWindow.cpp b/senseApis/xcbWindow/xcbWindow.cpp index eaad492..902bb1b 100644 --- a/senseApis/xcbWindow/xcbWindow.cpp +++ b/senseApis/xcbWindow/xcbWindow.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "xcbWindow.h" @@ -55,9 +55,9 @@ std::string WindowSelector::stringify() const } AttachedWindow::AttachedWindow( - const std::shared_ptr& spec + const std::shared_ptr& spec ) - : deviceSpec(spec) + : deviceAttachmentSpec(spec) { // Validate required function pointers are available if (!xcbXorg.fns.getOrCreateConnection || @@ -106,7 +106,7 @@ AttachedWindow::AttachedWindow( } void AttachedWindow::parseWindowSelector( - const smo::device::SenseDeviceSpec& spec + const smo::device::DeviceAttachmentSpec& spec ) { // Default match type @@ -148,7 +148,7 @@ void AttachedWindow::parseWindowSelector( } } -int AttachedWindow::getRequiredParamAsInt(const smo::device::SenseDeviceSpec& spec, +int AttachedWindow::getRequiredParamAsInt(const smo::device::DeviceAttachmentSpec& spec, const std::string& paramName) { auto it = std::find_if( @@ -296,7 +296,7 @@ static int xcbWindow_finalizeInd(void) } static int xcbWindow_attachDeviceReq( - const std::shared_ptr& desc + const std::shared_ptr& desc ) { g_attachedWindows.emplace_back( @@ -309,12 +309,12 @@ static int xcbWindow_attachDeviceReq( } static int xcbWindow_detachDeviceReq( - const std::shared_ptr& spec + const std::shared_ptr& spec ) { auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(), [&spec](const std::unique_ptr& window) { - return window->getDeviceSpec() == spec; + return window->getDeviceAttachmentSpec() == spec; } ); diff --git a/senseApis/xcbWindow/xcbWindow.h b/senseApis/xcbWindow/xcbWindow.h index e3f1bc8..7093a11 100644 --- a/senseApis/xcbWindow/xcbWindow.h +++ b/senseApis/xcbWindow/xcbWindow.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include namespace xcb_window { @@ -30,23 +30,25 @@ struct WindowSelector class AttachedWindow { public: - AttachedWindow(const std::shared_ptr& spec); + AttachedWindow( + const std::shared_ptr& spec); ~AttachedWindow(); - const std::shared_ptr& getDeviceSpec() const - { return deviceSpec; } + const std::shared_ptr& + getDeviceAttachmentSpec() const + { return deviceAttachmentSpec; } const WindowSelector& getWindowSelector() const { return windowSelector; } const std::string& getActualWindowName() const { return actualWindowName; } void* getXcbConnection() const { return xcbConnectionShared.get(); } std::string stringify() const; private: - void parseWindowSelector(const smo::device::SenseDeviceSpec& spec); + void parseWindowSelector(const smo::device::DeviceAttachmentSpec& spec); int getRequiredParamAsInt( - const smo::device::SenseDeviceSpec& spec, + const smo::device::DeviceAttachmentSpec& spec, const std::string& paramName); - std::shared_ptr deviceSpec; + std::shared_ptr deviceAttachmentSpec; WindowSelector windowSelector; std::string actualWindowName; std::shared_ptr xcbConnectionShared; diff --git a/smocore/deviceManager/deviceManager.cpp b/smocore/deviceManager/deviceManager.cpp index d084c8f..9bbff07 100644 --- a/smocore/deviceManager/deviceManager.cpp +++ b/smocore/deviceManager/deviceManager.cpp @@ -11,11 +11,11 @@ namespace smo { namespace device { -std::vector> +std::vector> DeviceManager::interoceptorDeviceSpecs; -std::vector> +std::vector> DeviceManager::extrospectorDeviceSpecs; -std::vector> +std::vector> DeviceManager::senseDeviceSpecs; const std::string DeviceManager::stringifyDeviceSpecs(void) diff --git a/smocore/deviceManager/deviceSpecp.yy b/smocore/deviceManager/deviceSpecp.yy index d755d60..f5e27c4 100644 --- a/smocore/deviceManager/deviceSpecp.yy +++ b/smocore/deviceManager/deviceSpecp.yy @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #ifndef yylex @@ -46,9 +46,9 @@ void yyerror(const char *message) %union { char* str; char chr; - smo::device::SenseDeviceSpec* sensorSpec; - smo::device::InteroceptorDeviceSpec* interoceptorSpec; - smo::device::ExtrospectorDeviceSpec* extrospectorSpec; + smo::device::DeviceAttachmentSpec* sensorSpec; + smo::device::InteroceptorDevAttachmentSpec* interoceptorSpec; + smo::device::ExtrospectorDevAttachmentSpec* extrospectorSpec; std::vector>* paramVector; std::pair* param; } @@ -83,8 +83,8 @@ sensor_spec: interoceptor_spec: KEYWORD_SPECTYPE_INTEROSPECTOR PIPE spec_body { - auto spec = std::make_shared( - *static_cast($3)); + auto spec = std::make_shared( + *static_cast($3)); spec->sensorType = $1; smo::device::DeviceManager::interoceptorDeviceSpecs.push_back(spec); @@ -96,8 +96,8 @@ interoceptor_spec: extrospector_spec: KEYWORD_SPECTYPE_EXTROSPECTOR PIPE spec_body { - auto spec = std::make_shared( - *static_cast($3)); + auto spec = std::make_shared( + *static_cast($3)); spec->sensorType = $1; smo::device::DeviceManager::extrospectorDeviceSpecs.push_back(spec); @@ -108,17 +108,18 @@ extrospector_spec: ; spec_body: - STRING PIPE STRING LPAREN opt_params RPAREN PIPE STRING LPAREN opt_params RPAREN PIPE STRING { - $$ = new smo::device::SenseDeviceSpec(); - $$->sensorType = '\0'; - $$->implexor = std::string($1); - $$->api = std::string($3); - $$->apiParams = std::move(*$5); - $$->provider = std::string($8); - $$->providerParams = std::move(*$10); - $$->deviceSelector = std::string($13); - delete $5; - delete $10; + STRING PIPE STRING PIPE STRING LPAREN opt_params RPAREN PIPE STRING LPAREN opt_params RPAREN PIPE STRING { + $$ = new smo::device::DeviceAttachmentSpec(); + $$->deviceIdentifier = std::string($1); + $$->sensorType = '\0'; // This will be set by the parent rule + $$->implexor = std::string($3); + $$->api = std::string($5); + $$->apiParams = std::move(*$7); + $$->provider = std::string($10); + $$->providerParams = std::move(*$12); + $$->deviceSelector = std::string($15); + delete $7; + delete $12; } ; diff --git a/smocore/include/deviceManager/deviceManager.h b/smocore/include/deviceManager/deviceManager.h index e685c93..1c53bce 100644 --- a/smocore/include/deviceManager/deviceManager.h +++ b/smocore/include/deviceManager/deviceManager.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include namespace smo { namespace device { @@ -34,11 +34,11 @@ private: public: std::string allDeviceSpecs; - static std::vector> + static std::vector> interoceptorDeviceSpecs; - static std::vector> + static std::vector> extrospectorDeviceSpecs; - static std::vector> + static std::vector> senseDeviceSpecs; }; diff --git a/smocore/include/senseApis/senseApiManager.h b/smocore/include/senseApis/senseApiManager.h index 12cf127..69519a0 100644 --- a/smocore/include/senseApis/senseApiManager.h +++ b/smocore/include/senseApis/senseApiManager.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace smo { namespace sense_api { @@ -39,9 +39,9 @@ public: void attachAllSenseDevicesFromSpecs(void); void attachSenseDevice( - const std::shared_ptr& spec); + const std::shared_ptr& spec); void detachSenseDevice( - const std::shared_ptr& spec); + const std::shared_ptr& spec); void detachAllSenseDevices(void); std::string stringifyLibs() const; diff --git a/smocore/senseApis/senseApiManager.cpp b/smocore/senseApis/senseApiManager.cpp index 7bf11c1..bd9de5c 100644 --- a/smocore/senseApis/senseApiManager.cpp +++ b/smocore/senseApis/senseApiManager.cpp @@ -232,7 +232,7 @@ void SenseApiManager::finalizeAllSenseApiLibs(void) } void SenseApiManager::attachSenseDevice( - const std::shared_ptr& spec + const std::shared_ptr& spec ) { auto libOpt = getSenseApiLibByApiName(spec->api); @@ -253,7 +253,7 @@ void SenseApiManager::attachSenseDevice( } void SenseApiManager::detachSenseDevice( - const std::shared_ptr& spec + const std::shared_ptr& spec ) { auto libOpt = getSenseApiLibByApiName(spec->api);