Skip to content

Commit

Permalink
Shifted to using autotools
Browse files Browse the repository at this point in the history
  • Loading branch information
NilanjanaLodh committed Aug 26, 2017
1 parent 55b5ef5 commit 62e4b47
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 64 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ print_backend_cups
.gdb_history
gmon.out
Makefile.in
.gitignore
aclocal.m4
Makefile
*/Makefile
depcomp
install-sh
missing
aclocal.*
compile
autom4*
config.log
config.status
configure
data/org.openprinting.Backend.CUPS.service
src/.deps
53 changes: 0 additions & 53 deletions Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
AUTOMAKE_OPTIONS = foreign
SUBDIRS = src data
34 changes: 34 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([COMMON-PRINT-BACKEND-CUPS],[1.0],[[email protected]])
AM_INIT_AUTOMAKE([-Wall foreign])
AC_CONFIG_SRCDIR([src/print_backend_cups.c])

# Check for a C compiler
AC_PROG_CC


# Checks for backend library
PKG_CHECK_MODULES([CPDBackend],[CPDBackend])
PKG_CHECK_MODULES([GIO],[gio-2.0])
PKG_CHECK_MODULES([GIOUNIX],[gio-unix-2.0])
PKG_CHECK_MODULES([GLIB],[glib-2.0])

# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h cups/cups.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC

# The Dbus service directory
AC_DEFINE_UNQUOTED(DBUS_SERVICES_DIR, "/usr/share/dbus-1/services", [Where services dir for DBUS is])

#The info directory which will be read by the frontend
AC_DEFINE_UNQUOTED(INFO_DIR, "/usr/share/print-backends", [The directory consulted by the frontends])

AC_OUTPUT([Makefile src/Makefile data/Makefile])
13 changes: 13 additions & 0 deletions data/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Dbus service file
servicedir = /usr/share/dbus-1/services
service_in_files = org.openprinting.Backend.CUPS.service.in
service_DATA = $(service_in_files:.service.in=.service)

$(service_DATA): $(service_in_files) Makefile
@sed -e "s|\@bindir\@|$(bindir)|" $<> $@

info_backenddir = /usr/share/print-backends
info_backend_DATA = org.openprinting.Backend.CUPS

clean-local:
rm -rf $(service_DATA)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[D-BUS Service]
Name=org.openprinting.Backend.CUPS
Exec=/usr/bin/print-backends/cups
Exec=@bindir@/print_backend_cups
12 changes: 12 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bin_PROGRAMS = print_backend_cups
print_backend_cups_SOURCES = print_backend_cups.c backend_helper.c
print_backend_cups_CPPFLAGS = $(CPDBackend_CFLAGS)
print_backend_cups_CPPFLAGS += $(GLIB_CFLAGS)
print_backend_cups_CPPFLAGS += $(GIO_CFLAGS)
print_backend_cups_CPPFLAGS += $(GIOUNIX_CFLAGS)

print_backend_cups_LDADD = $(CPDBackend_LIBS)
print_backend_cups_LDADD += -lcups -lpthread -lm -lcrypt
print_backend_cups_LDADD += $(GLIB_LIBS)
print_backend_cups_LDADD += $(GIO_LIBS)
print_backend_cups_LDADD += $(GIOUNIX_LIBS)
19 changes: 12 additions & 7 deletions src/backend_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ BackendObj *get_new_BackendObj()
b->num_frontends = 0;
b->obj_path = NULL;
b->default_printer = NULL;
return b;
}

/** Don't free the returned value; it is owned by BackendObj */
Expand Down Expand Up @@ -82,9 +83,11 @@ void add_frontend(BackendObj *b, const char *dialog_name)
void remove_frontend(BackendObj *b, const char *dialog_name)
{
Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name));
g_hash_table_remove(b->dialogs, dialog_name);
b->num_frontends--;

if (d)
{
g_hash_table_remove(b->dialogs, dialog_name);
b->num_frontends--;
}
g_message("Removed Frontend entry for %s", dialog_name);
}
gboolean no_frontends(BackendObj *b)
Expand All @@ -93,7 +96,7 @@ gboolean no_frontends(BackendObj *b)
return TRUE;
return FALSE;
}
Dialog *find_dialog(BackendObj *b , const char* dialog_name)
Dialog *find_dialog(BackendObj *b, const char *dialog_name)
{
Dialog *d = (Dialog *)(g_hash_table_lookup(b->dialogs, dialog_name));
return d;
Expand Down Expand Up @@ -673,10 +676,9 @@ int print_file(PrinterCUPS *p, const char *file_path, int num_settings, GVariant
num_options = cupsAddOption(option_name, option_value, num_options, &options);
}
char *file_name = extract_file_name(file_path);
ipp_status_t job_status;
int job_id = 0;
job_status = cupsCreateDestJob(p->http, p->dest, p->dinfo,
&job_id, file_name, num_options, options);
cupsCreateDestJob(p->http, p->dest, p->dinfo,
&job_id, file_name, num_options, options);
if (job_id)
{
/** job creation was successful ,
Expand Down Expand Up @@ -801,6 +803,7 @@ Dialog *get_new_Dialog()
d->printers = g_hash_table_new_full(g_str_hash, g_str_equal,
(GDestroyNotify)free_string,
(GDestroyNotify)free_PrinterCUPS);
return d;
}

void free_Dialog(Dialog *d)
Expand Down Expand Up @@ -1052,6 +1055,8 @@ char *translate_job_state(ipp_jstate_t state)
return JOB_STATE_STOPPED;
case IPP_JSTATE_COMPLETED:
return JOB_STATE_COMPLETED;
default:
return "NA";
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/print_backend_cups.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ gpointer list_printers(gpointer _dialog_name)
_dialog_name);

g_message("Exiting thread for dialog at %s\n", dialog_name);
return NULL;
}

int send_printer_added(void *_dialog_name, unsigned flags, cups_dest_t *dest)
Expand Down Expand Up @@ -279,6 +280,7 @@ static gboolean on_handle_print_file(PrintBackend *interface,
g_message("No frontends connected .. exiting backend.\n");
exit(EXIT_SUCCESS);
}
return TRUE;
}

static gboolean on_handle_get_all_options(PrintBackend *interface,
Expand All @@ -290,8 +292,6 @@ static gboolean on_handle_get_all_options(PrintBackend *interface,
PrinterCUPS *p = get_printer_by_name(b, dialog_name, printer_name);
Option *options;
int count = get_all_options(p, &options);
int i;

GVariantBuilder *builder;
GVariant *variant;
builder = g_variant_builder_new(G_VARIANT_TYPE("a(ssia(s))"));
Expand Down Expand Up @@ -374,7 +374,7 @@ static gboolean on_handle_replace(PrintBackend *interface,
{
g_hash_table_steal(b->dialogs, previous_name);
g_hash_table_insert(b->dialogs, get_string_copy(dialog_name), d);
g_message("Replaced %s --> %s\n", previous_name , dialog_name);
g_message("Replaced %s --> %s\n", previous_name, dialog_name);
}
print_backend_complete_replace(interface, invocation);
return TRUE;
Expand Down

0 comments on commit 62e4b47

Please sign in to comment.