"SfR Fresh" - the SfR Freeware/Shareware Archive 
Member "pan-0.133/pan/data-impl/add-server.cc" of archive pan-0.133.tar.gz:
As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers.
Alternatively you can here view or download the uninterpreted source code file.
That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
1 #include <config.h>
2 #include <iostream>
3 #include <glib.h>
4 #include <pan/general/string-view.h>
5 #include <pan/tasks/queue.h>
6 #include <pan/tasks/socket-impl-gio.h>
7 #include <pan/tasks/task-groups.h>
8 #include "data-impl.h"
9
10 using namespace pan;
11
12 namespace
13 {
14 GMainLoop * main_loop;
15
16 gboolean
17 check_for_tasks_done (gpointer queue_gpointer)
18 {
19 Queue * queue (static_cast<Queue*>(queue_gpointer));
20
21 queue->upkeep ();
22
23 Queue::task_states_t tasks;
24 queue->get_all_task_states (tasks);
25 if (tasks.tasks.empty())
26 g_main_loop_quit (main_loop);
27 return true;
28 }
29 };
30
31 int main (int argc, char *argv[])
32 {
33 // check the command line args
34 if (argc<3 || !atoi(argv[2])) {
35 std::cerr << "Usage: add-server hostname port [username password]" << std::endl;
36 return 0;
37 }
38
39 DataImpl data;
40
41 // ensure backend knows about this server
42 const Quark servername (data.add_new_server ());
43 const char * host (argv[1]);
44 const int port (atoi (argv[2]));
45 data.set_server_addr (servername, host, port);
46
47 const bool have_username (argc > 3);
48 const bool have_password (argc > 4);
49 StringView username, password;
50 if (have_username) username = argv[3];
51 if (have_password) password = argv[4];
52 if (have_username || have_password) {
53 std::cerr << "Username [" << username << "], password [" << password << "]\n";
54 data.set_server_auth (servername, username, password);
55 }
56
57 // initialize the queue
58 TaskArchive null_task_archive;
59 WorkerPool pool;
60 GIOChannelSocket::Creator _socket_creator;
61 Queue queue (data, null_task_archive, &_socket_creator, pool, true);
62 queue.add_task (new TaskGroups (data, servername));
63
64 // start the event loop...
65 main_loop = g_main_loop_new (NULL, false);
66 g_timeout_add (2*1000, check_for_tasks_done, &queue);
67 g_main_loop_run (main_loop);
68 return 0;
69 }