Programming in C (AMI)

I want to write a la client part for Asterisk, which will use a connection with Manager. Are there any simple examples in C that could be used as a starting point? Compile and run? The search did not give anything like that.

Well, have you looked at:

http://advancedcodingconcepts.blogspot.com/2011/02/asterisk-manager-interface-
c.html

(Yes, I know C++ is not C, but it may contain useful ideas nonetheless)

Disclaimer: I have no experience with any of the above; they simply turned up
as a result of a Google search for “Asterisk AMI client written in C”

Maybe those will help point you in a useful direction.

Out of interest, why do you want to start such a project written in C, rather
than a language with far more developed string and text manipulation
capabilities such as Perl or Python?

Antony.

1 Like

Event-driven programming is complicated enough, even without the quirks of AMI, that you would want to avoid a low-level language like C if you can help it. This is why async/await programming with coroutines has become such a popular language feature lately.

1 Like

I want to try to do this on D by connecting a C/C++ library that will allow using the API.

You realize that (nearly) all the public Asterisk APIs communicate through TCP or Unix socket connections, with no C/C+±specific libraries involved?

Yes. What exactly do you mean?

Cooperative scheduling is not a new idea. IBM’s CICS used it in the 1970s, and I think 16 bit Windows did. The concept of coroutines is probably even earlier. Here you need cooperative scheduling, not just coroutines.

In the modern async paradigm, the two go together like the proverbial horse and carriage. Thus, Python includes the asyncio cooperative scheduling framework in its standard library, built on top of the “stackless” async/await coroutine facility that is now part of the language.

asyncio does not just define an event loop, it defines an event loop API. This means you can plug in alternative event loops in place of the default one. For example, every GUI framework already provides its own event loop, and by providing an asyncio-compatible wrapper for same, you can incorporate asynchronous code into your GUI app. And by conforming to a standard API, that asynchronous code can be written in an event-loop-agnostic fashion.

This may not be so important in a back-end server app. But even there, perhaps you want a higher-performance alternative event loop, like uvloop.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.