Reputation: 1834
I am currently working on a REST API written in C And i would love to hear a second opinion on my current architecture and how it could be refactored.
So basically it's a audio streaming platform with 2 types of calls - sync and async. We are building it upon janus, more specifically audiobridge plugin.
The problem: Our current janus_audiobridge
file has grown too big and its pretty hard to navigate trough it(around 5K lines of code in a single file). So i decided its time for a refactor.
My current solution and problems with it: My idea was to seperate sync and async calls in to 2 seperate files. This way all the stuff for mixing audio and rtp forwards would be in the main janus_audiobridge
file and the actual endpoints would be seperate.
But the problem with this approach is that sync/async calls still use the structs and static variables from the main janus_audiobridge
file. So i would have to pass them into the handler methods. Which is quite ugly.
How would you architect this kind of system?
Thanks!
Upvotes: 0
Views: 44
Reputation: 176
A quick-and-dirty solution would be to declare the variable in one of the two sources files as normal and declare it as extern in the other file. This way both files can refer to the same variable but you only have one declaration.
The better way in my opinion is to look at how other libraries handle this. The first argument to function call is usually a pointer to an internal structure that holds all the information you would put in a global. This adds one argument to most functions but is just a pointer. This avoids problems with declaring globals and makes your code reusable for different contexts at once (multiple clients or multiple endpoints) in a single process.
Upvotes: 1