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