root/trunk/FRII/app/ds-chooser.cc

Revision 10, 2.9 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 // Show a chooser & let the user select an analysis to load from a
17 // Cartwheel server.
18
19 #include <iostream>
20 #include <unistd.h>
21 #include <string>
22
23 #include <FL/Fl_Preferences.H>
24
25 #include "load_canal.hh"
26 #include "load_sister.hh"
27
28 int main(int argc, char * argv[])
29 {
30   // set defaults
31
32   int ch;
33   char * server = "woodward.caltech.edu";
34   int port = 80;
35   char * location = "/canal/services/canal_svc/";
36   char * username = "admin";
37   char * password = "admin";
38   bool password_was_set = false;
39
40   //
41   // parse command line arguments.
42   //
43
44   while(1) {
45     ch = getopt(argc, argv, "?hs:i:u:p:");
46
47     if (ch == -1) {
48       break;
49     }
50     switch(ch) {
51     case 's':                   // server
52       server = optarg;
53       break;
54     case 'i':                   // port
55       port = atoi(optarg);
56       break;
57     case 'u':                   // user
58       username = optarg;
59       break;
60     case 'p':                   // password
61       password = optarg;
62       password_was_set = true;
63       break;
64     case '?':
65     case 'h':
66     default:
67       printf("\nUsage:\n\t%s [ -s server ] [ -i port ] [ -u user ] [ -p password ]\n\n", argv[0]);
68       exit(-1);
69     }
70   }
71
72   //
73   // Load in password by server/location/port, if specified, using the
74   // preferences system.
75   //
76
77   Fl_Preferences p(Fl_Preferences::USER, "family.caltech.edu", "FRII");
78
79   char path[500], * value = NULL;
80   sprintf(path, "%s@%s,%d", username, server, port);
81
82   if (password_was_set) {
83     p.set(path, password);
84     p.flush();
85   } else {
86     printf("(Using stored or default password for user '%s'.)\n", username);
87   }
88   p.get(path, value, password);
89
90   //
91   // OK, now run the various things.
92   //
93
94   sister::init();
95   canal::init();
96   init_chooser();
97
98   printf("Connecting to remote Cartwheel server\n\n");
99   printf("\thttp://%s:%d%s\n\n", server, port, location);
100   printf("as user '%s'...\n\n", username);
101
102   // connect to the remote Cartwheel server.
103   try {
104     canal::xmlrpcAPI * api = new canal::xmlrpcAPI(server, port, location);
105
106     api->authenticate(username, value);
107  
108     if (api->is_authenticated()) {
109       printf("Successful!  Starting chooser.\n");
110     } else {
111       printf("ERROR!  Cannot log in with given username; exiting.\n");
112       exit(-1);
113     }
114
115     // build a chooser & let that run everything.
116     canal_chooser(api);
117
118   } catch (canal::exception& e) {
119     std::cerr << "canal API error: " << e.msg << std::endl;
120   }
121
122   free(value);
123
124   exit(0);
125 }
Note: See TracBrowser for help on using the browser.