Conversation
|
Reworked the PR to split the backends into separate classes to make the code more readable. |
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.
| } | ||
| #endif | ||
|
|
||
| delete[] m_sensorState; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Should m_sensorCount should be set to 0 here?
There was a problem hiding this comment.
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.
pvuorela
left a comment
There was a problem hiding this comment.
Some quick comments, didn't have time to go through all yet.
| ****************************************************************************/ | ||
|
|
||
| #ifndef HybrisBackendHal_H | ||
| #define HybrisBackendHal_H |
There was a problem hiding this comment.
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.
| public: | ||
| HybrisBackendHal(HybrisManager *manager, QObject *parent = 0); | ||
| ~HybrisBackendHal(); | ||
| void initialize(); |
There was a problem hiding this comment.
Bonus points for marking override on the reimplemented methods.
| 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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
The backends should all inherit HybrisBackend, thus not need any casting? Applies to all getBackend().
|
|
||
| HybrisBackend *getBackend(HybrisManager *manager) | ||
| { | ||
| HybrisBackend *backend = NULL; |
There was a problem hiding this comment.
Bonus points for nullptr.
pvuorela
left a comment
There was a problem hiding this comment.
Bunch of more comments.
| gbinder_remote_reply_unref(reply); | ||
| gbinder_local_request_unref(req); | ||
| if (m_backend) { | ||
| m_backend->cleanup(); |
There was a problem hiding this comment.
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?
| int m_sensorCount; | ||
| }; | ||
|
|
||
| HybrisBackend *getBackend(HybrisManager *manager); |
There was a problem hiding this comment.
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.
| HybrisBackend(HybrisManager *manager, QObject *parent = 0); | ||
| virtual void initialize() = 0; | ||
| virtual void cleanup() = 0; | ||
| virtual int sensorCount(); |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
This exists? And dtors as = 0 in general would be strange.
|
|
||
| class HybrisManager; | ||
|
|
||
| class HybrisBackend : public QObject |
There was a problem hiding this comment.
Is there actually any use for the QObject inheritance? Not spotting signals nor slots, and the instance is explicitly deleted, not needing parenting.
No description provided.