Skip to content

Commit

Permalink
astcc: Update to compile with libcami 0.3.0.
Browse files Browse the repository at this point in the history
* Dynamically link to libcami
* Use ami_session variable
  • Loading branch information
InterLinked1 committed Dec 27, 2023
1 parent c2ecd81 commit ab1ed59
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
pwd
ls -la
git clone https://github.com/InterLinked1/cami.git
cp -r cami/include .
cp cami/cami.c .
cd cami
sudo make
sudo make install
cd ..
make
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ EXE = astcc
LIBS = -lm
RM = rm -f

MAIN_OBJ := cami.o astcc.o
MAIN_OBJ := astcc.o

all : main

%.o: %.c
$(CC) $(CFLAGS) -c $^

main : $(MAIN_OBJ)
$(CC) $(CFLAGS) -o $(EXE) $(LIBS) *.o -ldl
$(CC) $(CFLAGS) -o $(EXE) $(LIBS) *.o -ldl -lcami

clean :
$(RM) *.i *.o
$(RM) *.i *.o $(EXE)

.PHONY: all
.PHONY: main
Expand Down
19 changes: 13 additions & 6 deletions astcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
#include <errno.h>
#include <assert.h>

#include "include/cami.h"
#include "include/cami_actions.h"
#include <cami/cami.h>
#include <cami/cami_actions.h>

/*! \brief Use device names rather than full channel names for operations. Comment this out if you don't want this. */
#define DEVICE_NAME_ONLY
Expand Down Expand Up @@ -122,7 +122,7 @@ static int operator_ringback(const char *channel)
}

/*! \brief Callback function executing asynchronously when new events are available */
static void ami_callback(struct ami_event *event)
static void ami_callback(struct ami_session *ami, struct ami_event *event)
{
int res = 0;
const char *disp, *channel, *eventname = ami_keyvalue(event, "Event");
Expand All @@ -132,6 +132,8 @@ static void ami_callback(struct ami_event *event)
char device_name[64];
#endif

(void) ami;

if (strcmp(eventname, "CoinDisposition")) {
goto cleanup; /* Don't care about anything else. */
}
Expand Down Expand Up @@ -187,9 +189,10 @@ static void ami_callback(struct ami_event *event)
ami_event_free(event); /* Free event when done with it */
}

static void simple_disconnect_callback(void)
static void simple_disconnect_callback(struct ami_session *ami)
{
/* Start with a newline, since we don't know where we were. */
(void) ami;
fprintf(stderr, "\nAMI was forcibly disconnected...\n");
exit(EXIT_FAILURE); /* This will kill the program. */
}
Expand All @@ -211,6 +214,7 @@ int main(int argc,char *argv[])
char ami_host[92] = "127.0.0.1"; /* Default to localhost */
char ami_username[64] = "";
char ami_password[64] = "";
struct ami_session *ami;

while ((c = getopt(argc, argv, getopt_settings)) != -1) {
switch (c) {
Expand Down Expand Up @@ -249,10 +253,11 @@ int main(int argc,char *argv[])
return -1;
}

if (ami_connect(ami_host, 0, ami_callback, simple_disconnect_callback)) {
ami = ami_connect(ami_host, 0, ami_callback, simple_disconnect_callback);
if (!ami) {
return -1;
}
if (ami_action_login(ami_username, ami_password)) {
if (ami_action_login(ami, ami_username, ami_password)) {
fprintf(stderr, "Failed to log in with username %s\n", ami_username);
return -1;
}
Expand All @@ -262,5 +267,7 @@ int main(int argc,char *argv[])
usleep(60000000);
}

ami_disconnect(ami);
ami_destroy(ami);
return 0;
}

0 comments on commit ab1ed59

Please sign in to comment.