-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[overridable API] Added Tox API in a structure form. #502
Conversation
Can you add a comment about how this is supposed to be used? I don't expect users will search git history for this PR and the usage docs you wrote in the PR body. |
toxcore/tox.h
Outdated
uint16_t (*tox_self_get_tcp_port)(const Tox *tox, TOX_ERR_GET_PORT *error); | ||
} ToxApi; | ||
|
||
extern ToxApi tox_api; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are users supposed to change this global mutable variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, users are supposed to copy it to create a flavor of the API based on the original API.
I am planning to create the mid-level library that will expose ToxApi xtox_api. When used, it will allow sending arbitrarily long messages using the same interface. All clients will need to do - to use xtox_api instead of tox_api.
Made variables const. |
96c0db1
to
5939f96
Compare
Uh, do we really want toxcore to provide this? I have yet to see a library that does this. I'd say this belongs in the code base of whoever uses toxcore and needs this functionality. Also, the structhe names are shortened for some reason. |
@nurupo I am going to create such mid-level library. |
I fixed the structure names. |
Why is this better than just calling the original Tox functions from a library on top and forward all the parameters + return value? |
@sudden6 I don't understand your suggestion. Could you elaborate? tox_friend_send_message will be in both toxcore and library. How would you call it? |
I'd overwrite it with my own libraries prefix like |
Then you will have to provide all ~150 functions, when with this approach you only need to provide what you actually need. |
I understand the purpose now, thanks to qTox/qTox#4238 (comment) This doesn't seem to build right now. |
It doesn't build? What's the error? |
Please merge this for the tox defragmenter: #492 (comment) |
I'm reluctant to merge this. I see no reason why you couldn't have this struct in a separate library. What other libraries provide this kind of overriding facility? |
Please merge this PR. qTox has plugins system planned. I would like to add the type of plugin that will allow to alter the API. One application is previously proposed by me arbitrary size messaging, which I think will fit well as a plugin. But API needs to be alterable. |
@yurivict In your case, you need to reimplement qTox |
The reasons:
|
@yurivict Change toxcore API it's wrong way to do it. You can create your wrapper and force all(?) clients to use it. But client should always give an avility to use toxcore directly |
@yurivict You can write you library, which will provide few function line |
@Diadlo Plugins interface should be generic, and shouldn't operate in terms of individual functions. It can operate through the interface:
This way it is generic, expandable, and doesn't have to implement a few functions here and there. I am motivated to work on this, because I essentially have one plugin ready that is very useful IMO. But this PR needs to be merged, otherwise it just doesn't feel right to drag this into clients. |
You may don't believe, but you still need "to implement a few functions here and there" to use it inside child classes to override toxcore function Note: What if someone don't whant to use Qt or C++? This way not enough generic from this side. |
Other languages have other ways to deal with such things. APIs are normally defined in C and later other languages bind to them in their own way. And no, C apps can use it as is, without defining anything else. |
The checkbox allowing maintainers to rebase is not checked. We can't operate on this PR as is, and I'm not happy with the PR itself. I'm closing it for now. We may revisit it in the future. |
This is useful to facilitate API subclassing.
Some library may want to overload several functions, keeping the rest, like this:
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)