Hi guys!
OK, reaching out for some help here.
I am having all kinds of trouble with OSDeclareDefaultStructors.
I have seriously been at this for nearly a week now and have come to the conclusion that I need to reach out for help from people that are more experience using Xcode.
I believe entirely that my issue is just that I can't for whatever reason see how to set up includes and libraries and things like that.
I have this line: OSDeclareDefaultStructors(NukeVirtualGamepad)
No matter what I do, Xcode will not recognize OSDeclareDefaultStructors.
The project builds a DriverKit > Driver extension.
I have literally tried absolutely everything with this. I am at a loss for words. I even set up a new blank project and it still will not recognize OSDeclareDefaultStructors.
I did a lot of research and it looks like expo needs OSDeclareDefaultStructors in order for the extension to build with a binary in it instead of being just a codeless extension.
Here is the code with the issue:
#pragma once
#include <DriverKit/OSMetaClass.h> #include <HIDDriverKit/IOUserHIDDevice.h> #include <DriverKit/OSData.h>
class NukeVirtualGamepad : public IOUserHIDDevice { OSDeclareDefaultStructors(NukeVirtualGamepad) // The problem is right here! This line! public: // Keep it minimal; no 'override' keywords since the .h types may not mark them virtual bool init(); void free();
kern_return_t Start(IOService* provider);
void Stop (IOService* provider);
OSData* newReportDescriptor();
// (Optional) helper you’ll use later to inject input matching your report
kern_return_t PostInput(uint16_t buttons, int8_t x, int8_t y);
};
I do have to mention to everyone that I am still very new with Xcode. So there is a ton that I don't know yet or might be misunderstanding.
Has anyone seen this before?
Thank you in advance.
So, let me start with the direct issue:
I have this line: OSDeclareDefaultStructors(NukeVirtualGamepad)
No matter what I do, Xcode will not recognize OSDeclareDefaultStructors.
Yes, that's correct. No matter what you do, that will never work. The problem here is that "OSDeclareDefaultStructors" is an IOKit macro used to set up IOKit objects in the kernel. It is not part of IOKit and never has been. The solution here is actually really simple, which is that you shouldn't be trying to do it at all.
That leads to here:
I did a lot of research and it looks like expo needs OSDeclareDefaultStructors in order for the extension to build with a binary in it instead of being just a codeless extension.
Did that research happen to involve AI? This is just a guess, but I suspect whatever suggested using "OSDeclareDefaultStructors" invented it by pulling the data from our IOKit documentation.
In terms of getting started with this, I would start either move over to CoreHID (see below) or start with either the keyboard or stylus HID samples, then modify them "toward" whatever you're trying to build. Getting a driver to properly load and match has always been tricky, but it's much easier to modify something that "works" instead of trying to do it from scratch.
I do have to mention to everyone that I am still very new with Xcode. So there is a ton that I don't know yet or might be misunderstanding.
Since you said the word "new", I want to include a warning here. If you're new to our platform, DriverKit is a VERY difficult place to start, probably the hardest API on our system to learn. It’s very poorly documented and basically requires you to first learn IOKit, then try to fit that knowledge into its now API set, and that’s on top of the complexity inherent in kernel development*.
*Yes, DriverKit is kernel development.
That leads me to here:
needed to get a virtual game pad
What are you actually trying to create? There are at least 3 different mechanisms for injecting events into the system including:
-
Using CGEventTap to inject high-level events into the WindowServer.
-
Using the CoreHID framework to create a virtual HID device.
-
If you REALLY wanted to, IOUSBHostControllerInterface can be used to simulate a host bus controller, which would also allow you to simulate the full USB bus, including as many HID devices as you wanted.
The last option is a bit extreme unless you're doing something particularly interesting, but 1 & 2 are both reasonable approaches that are FAR better than writing a DEXT. One thing to keep in mind here is that the main reason many existing commercial products use DEXT is that they were written before we released CoreHID.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware