Index: src/libicalcap/Makefile.am =================================================================== RCS file: /home/cvs/projects/libical/src/libicalcap/Makefile.am,v retrieving revision 1.1 retrieving revision 1.3 diff -u -r1.1 -r1.3 --- src/libicalcap/Makefile.am 12 May 2004 08:53:09 -0000 1.1 +++ src/libicalcap/Makefile.am 14 May 2004 09:43:09 -0000 1.3 @@ -21,9 +21,15 @@ # # #====================================================================== +if WITH_CXX +cxx_lib=libicalcap_cxx.la +cxx_headers=icalcap_session_cxx.h icalcap_channel_cxx.h +else +cxx_lib= +cxx_headers= +endif - -lib_LTLIBRARIES = libicalcap.la +lib_LTLIBRARIES = libicalcap.la $(cxx_lib) noinst_LTLIBRARIES = libicalcap-static.la libicalcap_static_la_SOURCES = $(libicalcap_la_SOURCES) @@ -39,6 +45,7 @@ -DWITH_RR $(RRCAP_CFLAGS) libicalcap_la_LDFLAGS = $(RRCAP_LIBS) -version-info 0:0:0 +libicalcap_cxx_la_LDFLAGS = $(RRCAP_LIBS) -version-info 0:0:0 libicalcap_la_SOURCES = \ @@ -56,6 +63,16 @@ icalcap_session_impl.h \ icalcap_utils.c +if WITH_CXX +libicalcap_cxx_la_SOURCES = \ + $(libicalcap_la_SOURCES) \ + icalcap_session_cxx.cpp \ + icalcap_session_cxx.h \ + icalcap_channel_cxx.cpp \ + icalcap_channel_cxx.h +endif + + libicalcapincludedir = $(includedir) libicalcapinclude_HEADERS = \ @@ -65,7 +82,8 @@ icalcap_server.h \ icalcap_server_impl.h \ icalcap_session.h \ - icalcap_session_impl.h + icalcap_session_impl.h \ + $(cxx_headers) noinst_PROGRAMS = client Index: src/libicalcap/icalcap_channel_cxx.cpp =================================================================== RCS file: src/libicalcap/icalcap_channel_cxx.cpp diff -N src/libicalcap/icalcap_channel_cxx.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libicalcap/icalcap_channel_cxx.cpp 10 Jun 2004 13:34:54 -0000 1.2 @@ -0,0 +1,70 @@ +#include "vcomponent.h" +#include "icalcap_session_cxx.h" +#include "icalcap_channel_cxx.h" + +extern "C" { +#include "icalcap_impl.h" +#include "icalcap_message_impl.h" +}; + +/* Constructor */ +ICalCapChannel::ICalCapChannel(icalcap_session* sess) { + iccc = icalcap_session_start_rr(sess, NULL); +} + +/* Copy-Constructor */ +ICalCapChannel::ICalCapChannel(const ICalCapChannel& channel) { + iccc = channel.iccc; +} + +/* Destructor */ +ICalCapChannel::~ICalCapChannel() { + if (iccc != NULL) { + icalcap_stop_rr(iccc); + } +} + +/* Operators */ +ICalCapChannel& ICalCapChannel::operator=(const ICalCapChannel& channel) throw(icalcaperrorenum) { + if (this == &channel) return *this; + + if (iccc != NULL) { + iccc = channel.iccc; + if (!iccc) throw ICALCAP_ERROR_INTERNAL; + } + + return *this; +} + +void +ICalCapChannel::close() { + if (iccc != NULL) { + icalcap_stop_rr(iccc); + iccc = NULL; + } +} + +void +ICalCapChannel::send(VComponent* vcomp) throw (icalcaperrorenum) { + if (vcomp == NULL) throw ICALCAP_ERROR_ARGUMENT; + + icalcap_message *capmsg = icalcap_message_new(iccc, *vcomp); + if (icalcap_message_send_reply_rr(capmsg)) { + throw ICALCAP_ERROR_SEND; + } +} + +VComponent* +ICalCapChannel::receive(void) throw (icalcaperrorenum) { + return new VComponent(); +} + +VComponent* +ICalCapChannel::sync_send(VComponent* vcomp, int timeout) throw (icalcaperrorenum) { + if (vcomp == NULL) throw ICALCAP_ERROR_SEND; + + icalcap_message *capmsg = icalcap_message_new(iccc, *vcomp); + icalcomponent *reply = icalcap_message_sync_send_rr(capmsg, timeout); + return new VComponent(reply); +} + Index: src/libicalcap/icalcap_channel_cxx.h =================================================================== RCS file: src/libicalcap/icalcap_channel_cxx.h diff -N src/libicalcap/icalcap_channel_cxx.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libicalcap/icalcap_channel_cxx.h 10 Jun 2004 13:34:54 -0000 1.2 @@ -0,0 +1,36 @@ +#ifndef __ICALCAP_CHANNEL_CXX_H__ +#define __ICALCAP_CHANNEL_CXX_H__ + +#include "icalcap_session_cxx.h" + +extern "C" { +#include "icalcap.h" +#include "icalcap_session.h" +}; + + + +class ICalCapChannel { +public: + /* Constructor */ + ICalCapChannel(icalcap_session* sess); + /* Copy-Constructor */ + ICalCapChannel(const ICalCapChannel& channel); + + /* Destructor */ + ~ICalCapChannel(); + + /* Operators */ + ICalCapChannel& ICalCapChannel::operator=(const ICalCapChannel& channel) throw(icalcaperrorenum); + + /* Methods */ + void close(void); + void send(VComponent* vcomp) throw (icalcaperrorenum); + VComponent* receive(void) throw (icalcaperrorenum); + VComponent* sync_send(VComponent* vcomp, int timeout) throw (icalcaperrorenum); + + +private: + icalcap* iccc; +}; +#endif /* __ICALCAP_CHANNEL_CXX_H__ */ Index: src/libicalcap/icalcap_session_cxx.cpp =================================================================== RCS file: src/libicalcap/icalcap_session_cxx.cpp diff -N src/libicalcap/icalcap_session_cxx.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libicalcap/icalcap_session_cxx.cpp 10 Jun 2004 14:58:08 -0000 1.3 @@ -0,0 +1,82 @@ +#include "vcomponent.h" +#include "icalcap_session_cxx.h" +#include "icalcap_channel_cxx.h" + +#include "string.h" + +/* Constructor */ +ICalCapSession::ICalCapSession() throw(icalcaperrorenum) : iccs(icalcap_session_new_rr()) { + if (!iccs) throw ICALCAP_ERROR_INTERNAL; +} + +/* Copy-Constructor */ +ICalCapSession::ICalCapSession(ICalCapSession& sess) throw(icalcaperrorenum) : iccs(sess.iccs) { + if (!iccs) { + iccs = icalcap_session_new_rr(); + } + if (!iccs) throw ICALCAP_ERROR_INTERNAL; +} + +/* Destructor */ +ICalCapSession::~ICalCapSession() { + if (iccs) { + icalcap_session_disconnect_rr(iccs); + iccs = NULL; + } +} + +/* Operators */ +ICalCapSession& ICalCapSession::operator=(const ICalCapSession& sess) throw(icalcaperrorenum) { + if (this == &sess) return *this; + + if (iccs != NULL) { + iccs = sess.iccs; + if (!iccs) throw ICALCAP_ERROR_INTERNAL; + } + + return *this; +} + + +/* Methods */ +#ifndef JNI_ENABLED +void +ICalCapSession::connect(const char *hostname, const int port) throw(icalcaperrorenum) { + if (!icalcap_session_connect(iccs, hostname, port)) { + throw ICALCAP_ERROR_CONNECT; + } +} + +void +ICalCapSession::login(const char *username, const char *authname, + const char *password) throw(icalcaperrorenum) { + if (!icalcap_session_login(iccs, username, authname, password)) { + throw ICALCAP_ERROR_LOGIN; + } +} +#else /* JNI_ENABLED */ +int +ICalCapSession::connect(const char *hostname, const int port) { + return icalcap_session_connect(iccs, hostname, port); +} + +int +ICalCapSession::login(const char *username, const char *authname, + const char *password) { + return icalcap_session_login(iccs, username, authname, password); +} +#endif /* JNI_ENABLED */ + +void +ICalCapSession::disconnect() { + if (iccs) { + icalcap_session_disconnect_rr(iccs); + iccs = NULL; + } +} + + +ICalCapChannel* +ICalCapSession::openChannel(void) throw (icalcaperrorenum) { + return new ICalCapChannel(iccs); +} Index: src/libicalcap/icalcap_session_cxx.h =================================================================== RCS file: src/libicalcap/icalcap_session_cxx.h diff -N src/libicalcap/icalcap_session_cxx.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libicalcap/icalcap_session_cxx.h 10 Jun 2004 14:58:08 -0000 1.3 @@ -0,0 +1,51 @@ +#ifndef __ICALCAP_SESSION_CXX_H__ +#define __ICALCAP_SESSION_CXX_H__ + +extern "C" { +#include "icalcap.h" +#include "icalcap_session.h" +#include "icalcap_session_impl.h" +}; + +class ICalCapChannel; + +typedef enum { + ICALCAP_ERROR_NONE, /* used to have NONE as int 0 */ + ICALCAP_ERROR_INTERNAL, + ICALCAP_ERROR_ARGUMENT, + ICALCAP_ERROR_CONNECT, + ICALCAP_ERROR_LOGIN, + ICALCAP_ERROR_CHANNEL, + ICALCAP_ERROR_SEND, + ICALCAP_ERROR_RECEIVE +} icalcaperrorenum; + +class ICalCapSession { +public: + /* Constructor */ + ICalCapSession() throw (icalcaperrorenum); + ICalCapSession(ICalCapSession& sess) throw (icalcaperrorenum); + /* Destructor equals disconnect */ + ~ICalCapSession(); + + /* Operators */ + ICalCapSession& operator=(const ICalCapSession&) throw (icalcaperrorenum); + + /* methods */ +#ifndef JNI_ENABLED + void connect(const char *hostname, const int port) throw (icalcaperrorenum); + void login(const char *username, const char *authname, + const char *password) throw (icalcaperrorenum); +#else /* JNI_ENABLED */ + int connect(const char *hostname, const int port); + int login(const char *username, const char *authname, + const char *password); +#endif /* JNI_ENABLED */ + void disconnect(void); + + /* Factory method */ + ICalCapChannel* openChannel(void) throw (icalcaperrorenum); +private: + icalcap_session* iccs; +}; +#endif /* __ICALCAP_SESSION_CXX_H__ */