Skip to content

Add support for AIDL binder interface#31

Open
mlehtima wants to merge 2 commits intomasterfrom
jb61406
Open

Add support for AIDL binder interface#31
mlehtima wants to merge 2 commits intomasterfrom
jb61406

Conversation

@mlehtima
Copy link
Copy Markdown
Contributor

@mlehtima mlehtima commented Jul 6, 2025

No description provided.

Comment thread core/hybrisadaptor.cpp Outdated
Comment thread core/hybrisadaptor.cpp Outdated
Comment thread core/hybrisadaptor.cpp Outdated
Comment thread core/hybrisadaptor.cpp Outdated
@mlehtima
Copy link
Copy Markdown
Contributor Author

mlehtima commented Mar 4, 2026

Reworked the PR to split the backends into separate classes to make the code more readable.

Comment thread core/hybrisbackend.h
Comment thread core/hybrisbackend.h Outdated
mlehtima added 2 commits March 5, 2026 15:25
Don't wait for hwbinder servicemanager when checking if hidl backend is
supported. One new devices hwbinder servicemanager is not present anymore
and waiting for servicemanager would cause the service to wait forever.
Comment thread core/hybrisadaptor.cpp
}
#endif

delete[] m_sensorState;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this stuff still done when the binderDieds happen in the backends? It seems like the rest of this is copied there, but this stuff isn't done anymore. Is that an issue?

g_free((void*)m_sensorArray[i].requiredPermission.data.str);
}
delete[] m_sensorArray;
m_sensorArray = NULL;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should m_sensorCount should be set to 0 here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that would be symmetric. Now it's initialized from initialize(), cleanup() could then deinit. Though the init is in derived classes which makes this spread out on multiple files. Got myself confused for a moment as nothing in this class assigns to m_sensorCount but reads the value.

Could be slightly simpler to follow with some actual container type rather than plain array.

Copy link
Copy Markdown
Contributor

@pvuorela pvuorela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some quick comments, didn't have time to go through all yet.

Comment thread core/hybrisbackend_hal.h
****************************************************************************/

#ifndef HybrisBackendHal_H
#define HybrisBackendHal_H
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor detail but the CamelCased if guard is slightly unusual. Suspect it might have been some search & replace thing here. Some other ones also in the PR.

Comment thread core/hybrisbackend_hal.h
public:
HybrisBackendHal(HybrisManager *manager, QObject *parent = 0);
~HybrisBackendHal();
void initialize();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points for marking override on the reimplemented methods.

Comment thread core/hybrisbackend.h
virtual float resolution(int index) = 0;
virtual int setActive(int handle, bool active) = 0;
virtual int setDelay(int handle, int64_t delay_ns) = 0;
virtual void eventReaderThreadImpl() = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can underdstand Impl in e.g. class names in comparison to abstract ones, but on one method it looks strange. All the methods are "Impl" in the subclasses?

The name neither tells what it does and not sure even the thread part.

**
****************************************************************************/

#ifdef USE_BINDER
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should anything_binder.cpp be even ever compiled without USE_BINDER?

HybrisBackend *backend = NULL;
for (int i = 0; i < 5; ++i) {
if (HybrisBackendBinderAidl::isSupported()) {
backend = qobject_cast<HybrisBackend *>(new HybrisBackendBinderAidl(manager));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backends should all inherit HybrisBackend, thus not need any casting? Applies to all getBackend().


HybrisBackend *getBackend(HybrisManager *manager)
{
HybrisBackend *backend = NULL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bonus points for nullptr.

Copy link
Copy Markdown
Contributor

@pvuorela pvuorela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of more comments.

Comment thread core/hybrisadaptor.cpp
gbinder_remote_reply_unref(reply);
gbinder_local_request_unref(req);
if (m_backend) {
m_backend->cleanup();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the only external use for the backend cleanup(). Since it's followed by deletion, could just make the deletion do cleanup and have one less method in public api? Internally the backends can keep such if they need to clean up state in the middle.

Then again now it's symmetric with separate initialize() but that also seems to be called right after getBackend() so the ctors could just do that?

Comment thread core/hybrisbackend.h
int m_sensorCount;
};

HybrisBackend *getBackend(HybrisManager *manager);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a static method in HybrisBackend? Seeing the call in HybrisManager I first thought it was a method in that class and was confused for a while where it's defined.

Comment thread core/hybrisbackend.h
HybrisBackend(HybrisManager *manager, QObject *parent = 0);
virtual void initialize() = 0;
virtual void cleanup() = 0;
virtual int sensorCount();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single non-abstract virtual method is slightly peculiar. Does the trick with protected m_sensorCount but leaves me stll wondering would it be simpler if the backends just implemented keeping the count themselves. Or alternatively should this be non-virtual.

No biggie though.

Comment thread core/hybrisbackend.h
virtual int minDelay(int index) = 0;
virtual float maxRange(int index) = 0;
virtual float resolution(int index) = 0;
virtual int setActive(int handle, bool active) = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api with almost everything fetched as index might be cleaner with some sensor type returned by index and that having this sort of methods.

For another detail almost all is having index parameter but then couple things are based on handles. Then internally the code does some indexForType() -> handle() resolving. Didn't go through all but just wondering if there needs to be a handle exposed. Index is sort of handle too.

This more as suggestion rather than requirement to change.

g_free((void*)m_sensorArray[i].requiredPermission.data.str);
}
delete[] m_sensorArray;
m_sensorArray = NULL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that would be symmetric. Now it's initialized from initialize(), cleanup() could then deinit. Though the init is in derived classes which makes this spread out on multiple files. Got myself confused for a moment as nothing in this class assigns to m_sensorCount but reads the value.

Could be slightly simpler to follow with some actual container type rather than plain array.

int index = m_manager->indexForHandle(eve->sensor);
const struct sensor_t *sensor = &m_sensorArray[index];
if (sensor->flags & SENSOR_FLAG_WAKE_UP) {
return true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing but this is classic 'if (isTrue()) return true; else return false;'

Could be just "return (sensor->flags & SENSOR_FLAG_WAKE_UP);"

float maxRange(int index);
float resolution(int index);
virtual int setActive(int handle, bool active) = 0;
virtual int setDelay(int handle, int64_t delay_ns) = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point in redeclaring abstract methods in parent class as still abstract? Same for initialize() and needsReaderThread().

Q_OBJECT
public:
HybrisBackendBinder(HybrisManager *manager, QObject *parent = 0);
virtual ~HybrisBackendBinder() = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exists? And dtors as = 0 in general would be strange.

Comment thread core/hybrisbackend.h

class HybrisManager;

class HybrisBackend : public QObject
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there actually any use for the QObject inheritance? Not spotting signals nor slots, and the instance is explicitly deleted, not needing parenting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants