Add an option to print discoveried ports,
if the transport add-on support this feature. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39188 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
SubDir HAIKU_TOP src tests add-ons print transports ;
|
||||
|
||||
UsePrivateHeaders shared print ;
|
||||
|
||||
SimpleTest print_transport_loader : main.cpp : be $(TARGET_LIBSUPC++) ;
|
||||
|
||||
|
||||
@@ -1,27 +1,70 @@
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Directory.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <File.h>
|
||||
#include <image.h>
|
||||
#include <DataIO.h>
|
||||
#include <Directory.h>
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <image.h>
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
#include <PrintTransportAddOn.h>
|
||||
|
||||
static struct option longopts[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "list-ports", no_argument, NULL, 'p' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
|
||||
static void
|
||||
usage(int argc, char** argv)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: %s [OPTIONS...] transport-addon-name [file to send]\n"
|
||||
"\n"
|
||||
" -p, --list-ports print ports detected by the transport add-on\n"
|
||||
" -v, --verbose tell me more. Use multiple times for more details\n"
|
||||
" -h, --help display this help and exit\n"
|
||||
"\n", argv[0]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
image_id addon = -1;
|
||||
char *transport;
|
||||
int c;
|
||||
bool list_ports = false;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <transport add-on name> [<file to print>]\n", argv[0]);
|
||||
return B_ERROR;
|
||||
while ((c = getopt_long(argc, argv, "hvp", longopts, 0)) > 0) {
|
||||
switch (c) {
|
||||
case 'p':
|
||||
list_ports = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
default:
|
||||
usage(argc, argv);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
new BApplication("application/x-vnd-OBOS-print_transport_tester");
|
||||
if (argc != 1) {
|
||||
usage(argc, argv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
transport = argv[1];
|
||||
new BApplication("application/x-vnd-Haiku-print_transport_tester");
|
||||
|
||||
image_id addon = -1;
|
||||
char *transport = argv[0];
|
||||
|
||||
printf("Looking for %s transport addon:\n", transport);
|
||||
|
||||
@@ -54,19 +97,42 @@ int main (int argc, char *argv[])
|
||||
transport, path.Path());
|
||||
|
||||
// get init & exit proc
|
||||
BDataIO* (*init_proc)(BMessage*);
|
||||
void (*exit_proc)(void);
|
||||
BDataIO* (*transport_init_proc)(BMessage*) = NULL;
|
||||
void (*transport_exit_proc)(void) = NULL;
|
||||
status_t (*list_transport_ports)(BMessage*) = NULL;
|
||||
int* transport_features_ptr = NULL;
|
||||
|
||||
get_image_symbol(addon, "init_transport", B_SYMBOL_TYPE_TEXT, (void **) &init_proc);
|
||||
get_image_symbol(addon, "exit_transport", B_SYMBOL_TYPE_TEXT, (void **) &exit_proc);
|
||||
get_image_symbol(addon, "init_transport", B_SYMBOL_TYPE_TEXT, (void **) &transport_init_proc);
|
||||
get_image_symbol(addon, "exit_transport", B_SYMBOL_TYPE_TEXT, (void **) &transport_exit_proc);
|
||||
|
||||
if (init_proc == NULL || exit_proc == NULL) {
|
||||
get_image_symbol(addon, B_TRANSPORT_LIST_PORTS_SYMBOL, B_SYMBOL_TYPE_TEXT,
|
||||
(void **) &list_transport_ports);
|
||||
get_image_symbol(addon, B_TRANSPORT_FEATURES_SYMBOL, B_SYMBOL_TYPE_DATA,
|
||||
(void **) &transport_features_ptr);
|
||||
|
||||
if (transport_init_proc == NULL || transport_exit_proc == NULL) {
|
||||
// transport add-on has not the proper interface
|
||||
printf("Invalid print transport add-on API!\n");
|
||||
unload_add_on(addon);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
if (list_ports) {
|
||||
printf("Ports list:\n");
|
||||
|
||||
if (list_transport_ports == NULL)
|
||||
printf("Transport \"%s\" don't support this feature!\n", transport);
|
||||
else {
|
||||
BMessage ports;
|
||||
snooze(1000000); // give some time for ports discovery
|
||||
status_t status = (*list_transport_ports)(&ports);
|
||||
if (status == B_OK)
|
||||
ports.PrintToStream();
|
||||
else
|
||||
printf("failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("Initing %s: ", transport);
|
||||
|
||||
// now, initialize the transport add-on
|
||||
@@ -74,7 +140,7 @@ int main (int argc, char *argv[])
|
||||
BMessage msg('TRIN');
|
||||
// TODO: create on the fly a temporary printer folder for testing purpose only
|
||||
msg.AddString("printer_file", "/boot/home/config/settings/printers/test");
|
||||
BDataIO *io = (*init_proc)(&msg);
|
||||
BDataIO *io = (*transport_init_proc)(&msg);
|
||||
|
||||
if (io) {
|
||||
printf("done.\nTransport parameters msg =>\n");
|
||||
@@ -102,9 +168,9 @@ int main (int argc, char *argv[])
|
||||
} // data valid file
|
||||
} // optional data file
|
||||
|
||||
if (exit_proc) {
|
||||
if (transport_exit_proc) {
|
||||
printf("Exiting %s...\n", transport);
|
||||
(*exit_proc)();
|
||||
(*transport_exit_proc)();
|
||||
}
|
||||
|
||||
unload_add_on(addon);
|
||||
@@ -112,3 +178,4 @@ int main (int argc, char *argv[])
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user