-## $Id: Makefile.am,v 1.15 2005-10-12 23:30:43 adam Exp $
-
-MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
+## $Id: Makefile.am,v 1.16 2005-10-13 12:28:55 adam Exp $
+MAINTAINERCLEANFILES = Makefile.in config.in config.hpp
AM_CXXFLAGS = $(YAZPPINC) $(XSLT_CFLAGS)
YP2_INCHPP = session.hpp package.hpp filter.hpp router.hpp
bin_PROGRAMS =
-check_PROGRAMS = test_filter1 test_filter2 \
- test_session1 test_session2 \
- test_thread_pool_observer test_boost_threads test_boost_time
+check_PROGRAMS = \
+ test_package1 \
+ test_filter1 test_filter2 \
+ test_session1 test_session2 \
+ test_thread_pool_observer \
+ test_boost_threads test_boost_time
noinst_PROGRAMS = p2
TESTS=$(check_PROGRAMS)
+test_package1_SOURCES=test_package1.cpp $(YP2_INCHPP)
test_filter1_SOURCES=test_filter1.cpp $(YP2_INCHPP)
test_filter2_SOURCES=test_filter2.cpp $(YP2_INCHPP)
test_session1_SOURCES=test_session1.cpp $(YP2_INCHPP)
LDADD= $(YAZPPLALIB) $(XSLT_LIBS)
-
-test_filter1_LDADD = $(LDADD) -lboost_unit_test_framework
-test_filter2_LDADD = $(LDADD) -lboost_unit_test_framework
-test_session1_LDADD = $(LDADD) -lboost_unit_test_framework
-test_session2_LDADD = $(LDADD) -lboost_unit_test_framework
-test_boost_threads_LDADD = $(LDADD) -lboost_unit_test_framework
-test_boost_time_LDADD = $(LDADD) -lboost_unit_test_framework
-test_thread_pool_observer_LDADD = $(LDADD) -lboost_unit_test_framework
+TLDADD = $(LDADD) -lboost_unit_test_framework
+
+test_filter1_LDADD = $(TLDADD)
+test_filter2_LDADD = $(TLDADD)
+test_session1_LDADD = $(TLDADD)
+test_session2_LDADD = $(TLDADD)
+test_boost_threads_LDADD = $(TLDADD)
+test_boost_time_LDADD = $(TLDADD)
+test_thread_pool_observer_LDADD = $(TLDADD)
+test_package1_LDADD = $(TLDADD)
# doxygen target
dox:
#include <stdexcept>
#include <yaz++/gdu.h>
+#include "router.hpp"
+#include "filter.hpp"
#include "session.hpp"
namespace yp2 {
} type;
std::string address; // UNIX+TCPIP
int port; // TCPIP only
+ public:
+ Origin() : type(API) {};
};
class Package {
public:
-
-
- Package(yp2::Session &session, yp2::Origin &origin)
- : m_session(session), m_origin(origin),
- m_filter(0), m_router(0), m_data(0) {}
-
- /// send Package to it's next Filter defined in Router
- Package & move() {
- m_filter = m_router->move(m_filter, this);
- if (m_filter)
- return m_filter->process(*this);
- else
- return *this;
- }
-
-
- /// access session - left val in assignment
- yp2::Session & session() {
- return m_session;
- }
-
- /// get function - right val in assignment
- unsigned int data() const {
- return m_data;
- }
-
- /// set function - left val in assignment
- unsigned int & data() {
- return m_data;
- }
-
- /// set function - can be chained
- Package & data(const unsigned int & data){
- m_data = data;
- return *this;
- }
-
-
- /// get function - right val in assignment
- Origin origin() const {
- return m_origin;
- }
-
- /// set function - left val in assignment
- Origin & origin() {
- return m_origin;
- }
-
- /// set function - can be chained
- Package & origin(const Origin & origin){
- m_origin = origin;
- return *this;
- }
-
-
- //Router router() const {
- // return m_router;
- //}
-
- //Router & router() {
- // return m_router;
- //}
-
- /// set function - can be chained
- Package & router(const Router &router){
- m_filter = 0;
- m_router = &router;
- return *this;
- }
-
-
- private:
- Session m_session;
-// unsigned long int m_session_id;
-// bool m_session_close;
- Origin m_origin;
-
- const Filter *m_filter;
- const Router *m_router;
- unsigned int m_data;
-
- yazpp_1::GDU m_request_gdu;
- yazpp_1::GDU m_response_gdu;
- };
-
-
-
+
+ Package(yp2::Session &session, yp2::Origin &origin)
+ : m_session(session), m_origin(origin),
+ m_filter(0), m_router(0), m_data(0) {}
+
+ /// send Package to it's next Filter defined in Router
+ Package & move() {
+ m_filter = m_router->move(m_filter, this);
+ if (m_filter)
+ return m_filter->process(*this);
+ else
+ return *this;
+ }
+
+ /// access session - left val in assignment
+ yp2::Session & session() {
+ return m_session;
+ }
+
+ /// get function - right val in assignment
+ unsigned int data() const {
+ return m_data;
+ }
+
+ /// set function - left val in assignment
+ unsigned int & data() {
+ return m_data;
+ }
+
+ /// set function - can be chained
+ Package & data(const unsigned int & data){
+ m_data = data;
+ return *this;
+ }
+
+
+ /// get function - right val in assignment
+ Origin origin() const {
+ return m_origin;
+ }
+
+ /// set function - left val in assignment
+ Origin & origin() {
+ return m_origin;
+ }
+
+ /// set function - can be chained
+ Package & origin(const Origin & origin){
+ m_origin = origin;
+ return *this;
+ }
+
+ Package & router(const Router &router){
+ m_filter = 0;
+ m_router = &router;
+ return *this;
+ }
+
+ private:
+ Session m_session;
+ Origin m_origin;
+
+ const Filter *m_filter;
+ const Router *m_router;
+ unsigned int m_data;
+
+ yazpp_1::GDU m_request_gdu;
+ yazpp_1::GDU m_response_gdu;
+ };
}
#endif
#include <boost/thread/mutex.hpp>
namespace yp2 {
-
+
class Session
{
//typedef unsigned long type;
public:
-
- /// create new session with new unique id
- Session() {
+
+ /// create new session with new unique id
+ Session() {
boost::mutex::scoped_lock scoped_lock(m_mutex);
++m_global_id;
m_id = m_global_id;
m_close = false;
};
-
- /// copy session including old id
- Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {};
-
- //Session& operator=(const Session &);
+
+ /// copy session including old id
+ Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {};
+
+ Session& operator=(const Session &s) {
+ if (this != &s)
+ {
+ m_id = s.m_id;
+ m_close = s.m_close;
+ }
+ return *this;
+ }
unsigned long id() const {
return m_id;
bool is_closed() const {
return m_close;
};
-
+
/// mark session closed, can not be unset
void close() {
m_close = true;
};
-
- private:
-
+
+ private:
+
unsigned long int m_id;
bool m_close;
-
+
/// static mutex to lock static m_id
static boost::mutex m_mutex;
--- /dev/null
+
+#include "config.hpp"
+#include <iostream>
+#include <stdexcept>
+
+#include "package.hpp"
+
+#define BOOST_AUTO_TEST_MAIN
+#include <boost/test/auto_unit_test.hpp>
+
+using namespace boost::unit_test;
+
+BOOST_AUTO_TEST_CASE( test_package1_1 )
+{
+ try {
+ yp2::Origin origin;
+ yp2::Session session;
+ yp2::Package package1(session, origin);
+
+ yp2::Package package2(package1.session(), origin);
+
+ BOOST_CHECK_EQUAL(package1.session().id(), package2.session().id());
+ }
+ catch ( ... ) {
+ BOOST_CHECK (false);
+ }
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */