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