Release 1.6.4
[yazpp-moved-to-github.git] / zoom / zconn.cpp
1 // Z39.50 Connection class
2
3 #if HAVE_CONFIG_H
4 #include <config.h>
5 #endif
6 #include "zoom.h"
7
8
9 namespace ZOOM {
10     connection::connection() {
11         ZOOM_options o = ZOOM_options_create();
12         c = ZOOM_connection_create(o);
13     }
14
15     void connection::connect(const std::string &hostname, int portnum) {
16         const char *line_printer_size_hostname = hostname.c_str();
17         //###cerr << "opening " << hostname << ":" << portnum << "\n";
18         ZOOM_connection_connect(c, line_printer_size_hostname, portnum);
19         //###cerr << "opened\n";
20
21         int errcode;
22         const char *errmsg;     // unused: carries same info as `errcode'
23         const char *addinfo;
24         if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) {
25             //###cerr << "oops: no connect, errcode=" << errcode << "\n";
26             throw bib1Exception(errcode, addinfo);
27         }
28     }
29
30     connection::connection(const std::string &hostname, int portnum) {
31         ZOOM_options o = ZOOM_options_create();
32         c = ZOOM_connection_create(o);
33         connect(hostname, portnum);
34     }
35
36     std::string connection::option(const std::string &key) const {
37         const char* val = ZOOM_connection_option_get(c, key.c_str());
38         return (val) ? val : std::string();
39     }
40
41     bool connection::option(const std::string &key, const std::string &val) {
42         // No way to tell whether ZOOM_connection_option_set() accepts key
43         ZOOM_connection_option_set(c, key.c_str(), val.c_str());
44         return true;
45     }
46
47     connection::~connection() {
48         ZOOM_connection_destroy(c);
49     }
50 }
51 /*
52  * Local variables:
53  * c-basic-offset: 4
54  * c-file-style: "Stroustrup"
55  * indent-tabs-mode: nil
56  * End:
57  * vim: shiftwidth=4 tabstop=8 expandtab
58  */
59