/* -*- C++ -*- * Copyright (C) 2001-2003, Christof Meerwald * http://JabXPCOM.sunsite.dk */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * as published by the Free Software Foundation; version 2 dated June, * 1991. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef HEADER__JABXPCOM_SESSION__INCLUDED #define HEADER__JABXPCOM_SESSION__INCLUDED #include "jabxpcom.h" #include "io/datastream.h" #include #include #include #include #define DECLARE_WRAP_EVENT_HEAD(event) \ protected: \ class WrapEvt ## event \ : public SigC::Object \ { \ public: \ explicit WrapEvt ## event (jabISessionEvt ## event *slot); \ static void *destroy_notification(void *self); #define DECLARE_WRAP_EVENT_TAIL(event) \ private: \ nsCOMPtr slot_; \ } #define IMPLEMENT_WRAP_EVENT(cl, event) \ cl::WrapEvt ## event::WrapEvt ## event(jabISessionEvt ## event *slot) \ : slot_(slot) \ { } \ void *cl::WrapEvt ## event::destroy_notification(void *self) \ { \ delete (cl *) self; \ return NULL; \ } #define CONNECT_WRAPPED_EVENT(event, signal, slot) \ WrapEvt ## event *wrapper = new WrapEvt ## event(slot); \ wrapper->add_destroy_notify_callback(wrapper, &WrapEvt ## event::destroy_notification); \ signal.connect(SigC::slot(*wrapper, &WrapEvt ## event::On ## event)); #define JABBERSESSION_CONTRACTID "@JabXPCOM.sunsite.dk/Session;1" #define JABBERSESSION_CID \ { 0xeef98738, 0xe39d, 0x47e9, {0x86, 0x6d, 0xe7, 0xe6, 0x70, 0x5c, 0x5a, 0xe7}} class Jabber_Session_Wrapper : public jabISession, public jabIDataStream, public SigC::Object { public: NS_DECL_ISUPPORTS NS_DECL_JABISESSION NS_DECL_JABIDATASTREAM Jabber_Session_Wrapper(); virtual ~Jabber_Session_Wrapper(); /* additional members */ protected: DECLARE_WRAP_EVENT_HEAD(Connected); void OnConnected(const judo::Element &element); DECLARE_WRAP_EVENT_TAIL(Connected); DECLARE_WRAP_EVENT_HEAD(Disconnected); void OnDisconnected(); DECLARE_WRAP_EVENT_TAIL(Disconnected); DECLARE_WRAP_EVENT_HEAD(AuthError); void OnAuthError(int code, const char *data); DECLARE_WRAP_EVENT_TAIL(AuthError); DECLARE_WRAP_EVENT_HEAD(Iq); void OnIq(const judo::Element &element); DECLARE_WRAP_EVENT_TAIL(Iq); DECLARE_WRAP_EVENT_HEAD(Message); void OnMessage(const jabberoo::Message &message); DECLARE_WRAP_EVENT_TAIL(Message); DECLARE_WRAP_EVENT_HEAD(UnknownPacket); void OnUnknownPacket(const judo::Element &element); DECLARE_WRAP_EVENT_TAIL(UnknownPacket); DECLARE_WRAP_EVENT_HEAD(IqVersion); void OnIqVersion(std::string &name, std::string &version, std::string &os); DECLARE_WRAP_EVENT_TAIL(IqVersion); DECLARE_WRAP_EVENT_HEAD(IqLast); void OnIqLast(std::string &seconds); DECLARE_WRAP_EVENT_TAIL(IqLast); DECLARE_WRAP_EVENT_HEAD(Presence); void OnPresence(const jabberoo::Presence &presence, jabberoo::Presence::Type prev_type); DECLARE_WRAP_EVENT_TAIL(Presence); DECLARE_WRAP_EVENT_HEAD(PresenceRequest); void OnPresenceRequest(const jabberoo::Presence &presence); DECLARE_WRAP_EVENT_TAIL(PresenceRequest); void transmit_xml(const char *data); private: jabberoo::Session session_; nsCOMPtr output_stream_; }; #endif