00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef INCL_JABBEROO_COMPONENT_H
00033 #define INCL_JABBEROO_COMPONENT_H
00034
00035 #include <jabberoofwd.h>
00036
00037 #include <judo.hpp>
00038 #include <sigc++/object.h>
00039 #include <sigc++/signal.h>
00040
00041 #include <string>
00042 #include <list>
00043 #include <map>
00044 #include <XPath.h>
00045 #include <packet.hh>
00046
00047 namespace jabberoo {
00048
00049 class ComponentSession:
00050 public judo::ElementStreamEventListener, public judo::ElementStream, public SigC::Object
00051 {
00052 public:
00053 enum ConnectionState
00054 {
00055 csNotConnected,
00056 csAwaitingAuth,
00057 csConnected
00058 };
00059
00060 ComponentSession();
00061 virtual ~ComponentSession();
00062
00063 const std::string& getComponentID() const
00064 { return _componentID; }
00065
00066 ConnectionState getState() const
00067 { return _connState; }
00068
00069 void connect(const std::string& server, const std::string& componentID,
00070 const std::string& password);
00071
00072 void disconnect();
00073
00074 judo::XPath::Query* registerXPath(const std::string& query, ElementCallbackFunc f);
00075
00076 void unregisterXPath(judo::XPath::Query* id);
00077
00078 ComponentSession& operator>>(const char* buffer) { push(buffer, strlen(buffer)); return *this; }
00079 ComponentSession& operator<<(const Packet& p) { evtTransmitXML(p.toString().c_str()); return *this;}
00080 ComponentSession& operator<<(const char* buffer) { evtTransmitXML(buffer); return *this;}
00081 virtual void push(const char* data, int datasz);
00082
00083
00084 SigC::Signal1<void, const char*, SigC::Marshal<void> > evtTransmitXML;
00085 SigC::Signal0<void, SigC::Marshal<void> > evtConnected;
00086 protected:
00087 virtual void onDocumentStart(judo::Element* t);
00088 virtual void onElement(judo::Element* t);
00089 virtual void onCDATA(judo::CDATA* c);
00090 virtual void onDocumentEnd();
00091
00092 private:
00093 std::string _server;
00094 std::string _componentID;
00095 std::string _password;
00096 std::string _SessionID;
00097 ConnectionState _connState;
00098 std::list<judo::XPath::Query*> _XPaths;
00099 std::map<judo::XPath::Query*, ElementCallbackFunc> _XPCallbacks;
00100 };
00101
00102 }
00103 #endif //INCL_JABBEROO_COMPONENT_H