From 492cc1eed8d6d885d18f2a5720cfc75d544113d1 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Mon, 2 Apr 2007 17:40:54 +0000 Subject: More QPID-243 * Moved most of the C++ make into src/Makefile.am * There is still a separate src/tests/Makefile.am git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@524847 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/Makefile.am | 170 +++++++++++++++++++++++++++++++++++- cpp/src/client/ClientConnection.cpp | 156 +++++++++++++++++++++++++++++++++ cpp/src/client/Connection.cpp | 156 --------------------------------- cpp/src/tests/Makefile.am | 4 +- 4 files changed, 324 insertions(+), 162 deletions(-) create mode 100644 cpp/src/client/ClientConnection.cpp delete mode 100644 cpp/src/client/Connection.cpp (limited to 'cpp/src') diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index 22bcd5c554..d8c294c48d 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -1,4 +1,9 @@ -SUBDIRS = broker . client tests gen +include gen/gen-src.mk + +# This is gmake specific +genBUILT_SOURCES = $(addprefix $(gen)/, $(generated_sources) $(generated_headers)) + +SUBDIRS = . tests AM_CXXFLAGS = $(WARNING_CFLAGS) @@ -7,7 +12,7 @@ INCLUDES = \ $(APR_CXXFLAGS) qpidd_LDADD = \ - broker/libqpidbroker.la \ + libqpidbroker.la \ libqpidcommon.la sbin_PROGRAMS = qpidd @@ -23,6 +28,7 @@ apr_src = \ $(apr)/LFSessionContext.cpp \ $(apr)/Socket.cpp \ $(apr)/Thread.cpp + apr_hdr = \ $(apr)/APRBase.h \ $(apr)/APRPool.h \ @@ -37,7 +43,8 @@ posix_src = \ $(posix)/Thread.cpp \ $(posix)/check.cpp \ $(posix)/EventChannel.cpp \ - $(posix)/EventChannelThreads.cpp + $(posix)/EventChannelThreads.cpp + posix_hdr = \ $(posix)/check.h \ $(posix)/EventChannel.h \ @@ -49,8 +56,11 @@ platform_hdr = $(apr_hdr) framing = framing gen = gen +broker = broker +client = client + +lib_LTLIBRARIES = libqpidcommon.la libqpidbroker.la libqpidclient.la -lib_LTLIBRARIES = libqpidcommon.la libqpidcommon_la_LIBADD = \ $(APR_LIBS) \ $(LIB_DLOPEN) \ @@ -96,6 +106,108 @@ libqpidcommon_la_SOURCES = \ sys/Time.cpp \ sys/ProducerConsumer.cpp +libqpidbroker_la_LDFLAGS = -version-info $(LIBTOOL_VERSION_INFO_ARG) +libqpidbroker_la_SOURCES = \ + $(broker)/AccumulatedAck.cpp \ + $(broker)/AccumulatedAck.h \ + $(broker)/AutoDelete.cpp \ + $(broker)/AutoDelete.h \ + $(broker)/Binding.h \ + $(broker)/Broker.cpp \ + $(broker)/Broker.h \ + $(broker)/BrokerAdapter.cpp \ + $(broker)/BrokerAdapter.h \ + $(broker)/BrokerSingleton.cpp \ + $(broker)/BrokerSingleton.h \ + $(broker)/BrokerChannel.cpp \ + $(broker)/BrokerChannel.h \ + $(broker)/BrokerExchange.h \ + $(broker)/BrokerMessage.cpp \ + $(broker)/BrokerMessage.h \ + $(broker)/BrokerMessageMessage.cpp \ + $(broker)/BrokerMessageMessage.h \ + $(broker)/BrokerQueue.cpp \ + $(broker)/BrokerQueue.h \ + $(broker)/Configuration.cpp \ + $(broker)/Configuration.h \ + $(broker)/Connection.cpp \ + $(broker)/Connection.h \ + $(broker)/ConnectionFactory.cpp \ + $(broker)/ConnectionFactory.h \ + $(broker)/ConnectionToken.h \ + $(broker)/Consumer.h \ + $(broker)/Content.h \ + $(broker)/DeletingTxOp.cpp \ + $(broker)/DeletingTxOp.h \ + $(broker)/Deliverable.h \ + $(broker)/DeliverableMessage.cpp \ + $(broker)/DeliverableMessage.h \ + $(broker)/DeliveryRecord.cpp \ + $(broker)/DeliveryRecord.h \ + $(broker)/DirectExchange.cpp \ + $(broker)/DirectExchange.h \ + $(broker)/ExchangeRegistry.cpp \ + $(broker)/ExchangeRegistry.h \ + $(broker)/FanOutExchange.cpp \ + $(broker)/FanOutExchange.h \ + $(broker)/HeadersExchange.cpp \ + $(broker)/HeadersExchange.h \ + $(broker)/InMemoryContent.cpp \ + $(broker)/InMemoryContent.h \ + $(broker)/LazyLoadedContent.cpp \ + $(broker)/LazyLoadedContent.h \ + $(broker)/MessageBuilder.cpp \ + $(broker)/MessageBuilder.h \ + $(broker)/MessageHandlerImpl.cpp \ + $(broker)/MessageHandlerImpl.h \ + $(broker)/MessageStore.h \ + $(broker)/MessageStoreModule.cpp \ + $(broker)/MessageStoreModule.h \ + $(broker)/NameGenerator.cpp \ + $(broker)/NameGenerator.h \ + $(broker)/NullMessageStore.cpp \ + $(broker)/NullMessageStore.h \ + $(broker)/Persistable.h \ + $(broker)/PersistableExchange.h \ + $(broker)/PersistableMessage.h \ + $(broker)/PersistableQueue.h \ + $(broker)/Prefetch.h \ + $(broker)/QueuePolicy.cpp \ + $(broker)/QueuePolicy.h \ + $(broker)/QueueRegistry.cpp \ + $(broker)/QueueRegistry.h \ + $(broker)/RecoverableMessage.h \ + $(broker)/RecoverableQueue.h \ + $(broker)/RecoveryManager.h \ + $(broker)/RecoveryManagerImpl.cpp \ + $(broker)/RecoveryManagerImpl.h \ + $(broker)/Reference.cpp \ + $(broker)/Reference.h \ + $(broker)/TopicExchange.cpp \ + $(broker)/TopicExchange.h \ + $(broker)/TransactionalStore.h \ + $(broker)/TxAck.cpp \ + $(broker)/TxAck.h \ + $(broker)/TxBuffer.cpp \ + $(broker)/TxBuffer.h \ + $(broker)/TxOp.h \ + $(broker)/TxPublish.cpp \ + $(broker)/TxPublish.h + +libqpidclient_la_LIBADD = libqpidcommon.la +libqpidclient_la_LDFLAGS = -version-info $(LIBTOOL_VERSION_INFO_ARG) +libqpidclient_la_SOURCES = \ + $(client)/ClientConnection.cpp \ + $(client)/ClientChannel.cpp \ + $(client)/ClientExchange.cpp \ + $(client)/ClientQueue.cpp \ + $(client)/BasicMessageChannel.cpp \ + $(client)/Connector.cpp \ + $(client)/IncomingMessage.cpp \ + $(client)/MessageListener.cpp \ + $(client)/ResponseHandler.cpp \ + $(client)/ReturnedMessageHandler.cpp + nobase_pkginclude_HEADERS = \ $(gen)/AMQP_HighestVersion.h \ $(platform_hdr) \ @@ -124,6 +236,20 @@ nobase_pkginclude_HEADERS = \ $(framing)/amqp_framing.h \ $(framing)/amqp_types.h \ $(framing)/Proxy.h \ + $(client)/AckMode.h \ + $(client)/ClientChannel.h \ + $(client)/ClientExchange.h \ + $(client)/ClientMessage.h \ + $(client)/ClientQueue.h \ + $(client)/Connection.h \ + $(client)/Connector.h \ + $(client)/IncomingMessage.h \ + $(client)/MessageChannel.h \ + $(client)/BasicMessageChannel.h \ + $(client)/MessageListener.h \ + $(client)/MethodBodyInstances.h \ + $(client)/ResponseHandler.h \ + $(client)/ReturnedMessageHandler.h \ shared_ptr.h \ Exception.h \ ExceptionHolder.h \ @@ -145,6 +271,42 @@ nobase_pkginclude_HEADERS = \ sys/TimeoutHandler.h \ sys/ProducerConsumer.h +# This is gmake specific +nobase_pkginclude_HEADERS += $(addprefix $(gen)/, $(generated_headers)) + +# Distribute the generated sources, at least for now, since +# the generator code is in java. +EXTRA_DIST += $(genBUILT_SOURCES) +DISTCLEANFILES = $(genBUILT_SOURCES) $(gen)/timestamp $(gen)/gen-src.mk + +# Don't attempt to run the code generator unless configure has set +# CAN_GENERATE_CODE, indicating that the amqp.xml and tools needed +# to run the code generator are available. +# +if CAN_GENERATE_CODE + +gentools_dir = $(srcdir)/../gentools +spec_dir = $(srcdir)/../../specs + +# FIXME aconway 2007-01-04: Enabling Basic class until +# new messaging class is ready to replace it. +# spec = $(spec_dir)/amqp.0-9.xml $(spec_dir)/amqp-errata.0-9.xml $(spec_dir)/amqp-nogen.0-9.xml +spec = $(spec_dir)/amqp.0-9.xml $(spec_dir)/amqp-errata.0-9.xml + +gentools_srcdir = $(gentools_dir)/src/org/apache/qpid/gentools + +$(BUILT_SOURCES) $(gen)/timestamp: $(spec) $(java_sources) $(cxx_templates) Makefile.am + rm -f $(genBUILT_SOURCES) + cd $(gentools_srcdir) && rm -f *.class && $(JAVAC) *.java + $(JAVA) -cp $(gentools_dir)/src org.apache.qpid.gentools.Main \ + -c -o $(gen) -t $(gentools_dir)/templ.cpp $(spec) + touch $(gen)/timestamp + +$(gen)/gen-src.mk: $(gen)/timestamp + cd $(gen) + $(gen)/make-gen-src-mk.sh $(gentools_dir) $(gentools_srcdir) > $@-t + mv $@-t $@ +endif # Force build during dist phase so help2man will work. dist-hook: $(lib_LTLIBRARIES) $(sbin_PROGRAMS) diff --git a/cpp/src/client/ClientConnection.cpp b/cpp/src/client/ClientConnection.cpp new file mode 100644 index 0000000000..365311ab37 --- /dev/null +++ b/cpp/src/client/ClientConnection.cpp @@ -0,0 +1,156 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include +#include +#include + +#include "Connection.h" +#include "ClientChannel.h" +#include "ClientMessage.h" +#include "../QpidError.h" +#include +#include +#include "MethodBodyInstances.h" +#include + +using namespace qpid::framing; +using namespace qpid::sys; + + +namespace qpid { +namespace client { + +const std::string Connection::OK("OK"); + +Connection::Connection( + bool _debug, uint32_t _max_frame_size, + framing::ProtocolVersion _version +) : channelIdCounter(0), version(_version), max_frame_size(_max_frame_size), + defaultConnector(version, _debug, _max_frame_size), + isOpen(false), debug(_debug) +{ + setConnector(defaultConnector); +} + +Connection::~Connection(){} + +void Connection::setConnector(Connector& con) +{ + connector = &con; + connector->setInputHandler(this); + connector->setTimeoutHandler(this); + connector->setShutdownHandler(this); + out = connector->getOutputHandler(); +} + +void Connection::open( + const std::string& host, int port, + const std::string& uid, const std::string& pwd, const std::string& vhost) +{ + if (isOpen) + THROW_QPID_ERROR(INTERNAL_ERROR, "Channel object is already open"); + connector->connect(host, port); + channels[0] = &channel0; + channel0.open(0, *this); + channel0.protocolInit(uid, pwd, vhost); + isOpen = true; +} + +void Connection::shutdown() { + close(); +} + +void Connection::close( + ReplyCode code, const string& msg, ClassId classId, MethodId methodId +) +{ + if(isOpen) { + // TODO aconway 2007-01-29: Exception handling - could end up + // partly closed with threads left unjoined. + isOpen = false; + channel0.sendAndReceive( + new ConnectionCloseBody( + getVersion(), code, msg, classId, methodId)); + + using boost::bind; + for_each(channels.begin(), channels.end(), + bind(&Channel::closeInternal, + bind(&ChannelMap::value_type::second, _1))); + channels.clear(); + connector->close(); + } +} + +void Connection::openChannel(Channel& channel) { + ChannelId id = ++channelIdCounter; + assert (channels.find(id) == channels.end()); + assert(out); + channels[id] = &channel; + channel.open(id, *this); +} + +void Connection::erase(ChannelId id) { + channels.erase(id); +} + +void Connection::received(AMQFrame* frame){ + // FIXME aconway 2007-01-25: Mutex + ChannelId id = frame->getChannel(); + Channel* channel = channels[id]; + // FIXME aconway 2007-01-26: Exception thrown here is hanging the + // client. Need to review use of exceptions. + if (channel == 0) + THROW_QPID_ERROR( + PROTOCOL_ERROR+504, + (boost::format("Invalid channel number %g") % id).str()); + try{ + channel->handleBody(frame->getBody()); + }catch(const qpid::QpidError& e){ + channelException( + *channel, dynamic_cast(frame->getBody().get()), e); + } +} + +void Connection::send(AMQFrame* frame) { + out->send(frame); +} + +void Connection::channelException( + Channel& channel, AMQMethodBody* method, const QpidError& e) +{ + int code = (e.code >= PROTOCOL_ERROR) ? e.code - PROTOCOL_ERROR : 500; + string msg = e.msg; + if(method == 0) + channel.close(code, msg); + else + channel.close( + code, msg, method->amqpClassId(), method->amqpMethodId()); +} + +void Connection::idleIn(){ + connector->close(); +} + +void Connection::idleOut(){ + out->send(new AMQFrame(version, 0, new AMQHeartbeatBody())); +} + +}} // namespace qpid::client diff --git a/cpp/src/client/Connection.cpp b/cpp/src/client/Connection.cpp deleted file mode 100644 index 365311ab37..0000000000 --- a/cpp/src/client/Connection.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -#include -#include -#include - -#include "Connection.h" -#include "ClientChannel.h" -#include "ClientMessage.h" -#include "../QpidError.h" -#include -#include -#include "MethodBodyInstances.h" -#include - -using namespace qpid::framing; -using namespace qpid::sys; - - -namespace qpid { -namespace client { - -const std::string Connection::OK("OK"); - -Connection::Connection( - bool _debug, uint32_t _max_frame_size, - framing::ProtocolVersion _version -) : channelIdCounter(0), version(_version), max_frame_size(_max_frame_size), - defaultConnector(version, _debug, _max_frame_size), - isOpen(false), debug(_debug) -{ - setConnector(defaultConnector); -} - -Connection::~Connection(){} - -void Connection::setConnector(Connector& con) -{ - connector = &con; - connector->setInputHandler(this); - connector->setTimeoutHandler(this); - connector->setShutdownHandler(this); - out = connector->getOutputHandler(); -} - -void Connection::open( - const std::string& host, int port, - const std::string& uid, const std::string& pwd, const std::string& vhost) -{ - if (isOpen) - THROW_QPID_ERROR(INTERNAL_ERROR, "Channel object is already open"); - connector->connect(host, port); - channels[0] = &channel0; - channel0.open(0, *this); - channel0.protocolInit(uid, pwd, vhost); - isOpen = true; -} - -void Connection::shutdown() { - close(); -} - -void Connection::close( - ReplyCode code, const string& msg, ClassId classId, MethodId methodId -) -{ - if(isOpen) { - // TODO aconway 2007-01-29: Exception handling - could end up - // partly closed with threads left unjoined. - isOpen = false; - channel0.sendAndReceive( - new ConnectionCloseBody( - getVersion(), code, msg, classId, methodId)); - - using boost::bind; - for_each(channels.begin(), channels.end(), - bind(&Channel::closeInternal, - bind(&ChannelMap::value_type::second, _1))); - channels.clear(); - connector->close(); - } -} - -void Connection::openChannel(Channel& channel) { - ChannelId id = ++channelIdCounter; - assert (channels.find(id) == channels.end()); - assert(out); - channels[id] = &channel; - channel.open(id, *this); -} - -void Connection::erase(ChannelId id) { - channels.erase(id); -} - -void Connection::received(AMQFrame* frame){ - // FIXME aconway 2007-01-25: Mutex - ChannelId id = frame->getChannel(); - Channel* channel = channels[id]; - // FIXME aconway 2007-01-26: Exception thrown here is hanging the - // client. Need to review use of exceptions. - if (channel == 0) - THROW_QPID_ERROR( - PROTOCOL_ERROR+504, - (boost::format("Invalid channel number %g") % id).str()); - try{ - channel->handleBody(frame->getBody()); - }catch(const qpid::QpidError& e){ - channelException( - *channel, dynamic_cast(frame->getBody().get()), e); - } -} - -void Connection::send(AMQFrame* frame) { - out->send(frame); -} - -void Connection::channelException( - Channel& channel, AMQMethodBody* method, const QpidError& e) -{ - int code = (e.code >= PROTOCOL_ERROR) ? e.code - PROTOCOL_ERROR : 500; - string msg = e.msg; - if(method == 0) - channel.close(code, msg); - else - channel.close( - code, msg, method->amqpClassId(), method->amqpMethodId()); -} - -void Connection::idleIn(){ - connector->close(); -} - -void Connection::idleOut(){ - out->send(new AMQFrame(version, 0, new AMQHeartbeatBody())); -} - -}} // namespace qpid::client diff --git a/cpp/src/tests/Makefile.am b/cpp/src/tests/Makefile.am index 1b4b65fb4f..89f3cfb9f9 100644 --- a/cpp/src/tests/Makefile.am +++ b/cpp/src/tests/Makefile.am @@ -89,9 +89,9 @@ libdlclose_noop_la_SOURCES = dlclose_noop.c abs_builddir = @abs_builddir@ extra_libs = $(CPPUNIT_LIBS) -lib_client = $(abs_builddir)/../client/libqpidclient.la +lib_client = $(abs_builddir)/../libqpidclient.la lib_common = $(abs_builddir)/../libqpidcommon.la -lib_broker = $(abs_builddir)/../broker/libqpidbroker.la +lib_broker = $(abs_builddir)/../libqpidbroker.la gen.mk: Makefile.am ( \ -- cgit v1.2.1