4c1c7a6ea0d8728e9ebb62edc1442c56e78864ba
[yazpp-moved-to-github.git] / zoom / zconn.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/zconn.cpp,v 1.7 2005-05-03 16:21:16 mike Exp $
2
3 // Z39.50 Connection class
4
5 #include "zoom.h"
6
7
8 namespace ZOOM {
9     connection::connection(const std::string &hostname, int portnum) {
10         const char *line_printer_size_hostname = hostname.c_str();
11         //###cerr << "opening " << hostname << ":" << portnum << "\n";
12         c = ZOOM_connection_new(line_printer_size_hostname, portnum);
13         //###cerr << "opened, got " << c << "\n";
14
15         int errcode;
16         const char *errmsg;     // unused: carries same info as `errcode'
17         const char *addinfo;
18         if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) {
19             //###cerr << "oops: no connect, errcode=" << errcode << "\n";
20             ZOOM_connection_destroy(c);
21             throw bib1Exception(errcode, addinfo);
22         }
23     }
24
25     std::string connection::option(const std::string &key) const {
26         const char* val = ZOOM_connection_option_get(c, key.c_str());
27         return (val) ? val : std::string();
28     }
29
30     bool connection::option(const std::string &key, const std::string &val) {
31         // No way to tell whether ZOOM_connection_option_set() accepts key
32         ZOOM_connection_option_set(c, key.c_str(), val.c_str());
33         return true;
34     }
35
36     connection::~connection() {
37         ZOOM_connection_destroy(c);
38     }
39 }