diff options
author | Gordon Sim <gsim@apache.org> | 2009-08-25 17:57:34 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2009-08-25 17:57:34 +0000 |
commit | 082fa377137d1a73382a0c3f1ab22b5abe6cb485 (patch) | |
tree | 27375051e0f05a91ff63f123b2b027916840221c /cpp/include | |
parent | 28e1de98b115ebc834a1e232bfd630809689a59e (diff) | |
download | qpid-python-082fa377137d1a73382a0c3f1ab22b5abe6cb485.tar.gz |
QPID-664: Initial checkin of high level messaging api for c++
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@807731 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/include')
-rw-r--r-- | cpp/include/qpid/client/amqp0_10/Codecs.h | 61 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Address.h | 57 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Codec.h | 44 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Connection.h | 67 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Filter.h | 48 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Message.h | 90 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/MessageContent.h | 90 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/MessageListener.h | 49 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Receiver.h | 115 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Sender.h | 57 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Session.h | 99 | ||||
-rw-r--r-- | cpp/include/qpid/messaging/Variant.h | 167 |
12 files changed, 944 insertions, 0 deletions
diff --git a/cpp/include/qpid/client/amqp0_10/Codecs.h b/cpp/include/qpid/client/amqp0_10/Codecs.h new file mode 100644 index 0000000000..5ef0b9fffe --- /dev/null +++ b/cpp/include/qpid/client/amqp0_10/Codecs.h @@ -0,0 +1,61 @@ +#ifndef QPID_CLIENT_AMQP0_10_CODECS_H +#define QPID_CLIENT_AMQP0_10_CODECS_H + +/* + * + * 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 "qpid/messaging/Codec.h" + +namespace qpid { +namespace client { +namespace amqp0_10 { + + +/** + * Codec for encoding/decoding a map of Variants using the AMQP 0-10 + * map encoding. + */ +class MapCodec : public qpid::messaging::Codec +{ + public: + void encode(const qpid::messaging::Variant&, std::string&); + void decode(const std::string&, qpid::messaging::Variant&); + + static const std::string contentType; + private: +}; + +/** + * Codec for encoding/decoding a list of Variants using the AMQP 0-10 + * list encoding. + */ +class ListCodec : public qpid::messaging::Codec +{ + public: + void encode(const qpid::messaging::Variant&, std::string&); + void decode(const std::string&, qpid::messaging::Variant&); + + static const std::string contentType; + private: +}; + +}}} // namespace qpid::client::amqp0_10 + +#endif /*!QPID_CLIENT_AMQP0_10_CODECS_H*/ diff --git a/cpp/include/qpid/messaging/Address.h b/cpp/include/qpid/messaging/Address.h new file mode 100644 index 0000000000..da563a21bf --- /dev/null +++ b/cpp/include/qpid/messaging/Address.h @@ -0,0 +1,57 @@ +#ifndef QPID_MESSAGING_ADDRESS_H +#define QPID_MESSAGING_ADDRESS_H + +/* + * + * 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 <string> +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { +} + +namespace messaging { + +/** + * Represents an address to which messages can be sent and from which + * messages can be received. Often a simple name is sufficient for + * this. However this struct allows the type of address to be + * specified allowing more sophisticated treatment if necessary. + */ +struct Address +{ + std::string value; + std::string type; + + QPID_CLIENT_EXTERN Address(); + QPID_CLIENT_EXTERN Address(const std::string& address); + QPID_CLIENT_EXTERN Address(const std::string& address, const std::string& type); + QPID_CLIENT_EXTERN operator const std::string&() const; + QPID_CLIENT_EXTERN const std::string& toStr() const; + QPID_CLIENT_EXTERN operator bool() const; + QPID_CLIENT_EXTERN bool operator !() const; +}; + +QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Address& address); + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_ADDRESS_H*/ diff --git a/cpp/include/qpid/messaging/Codec.h b/cpp/include/qpid/messaging/Codec.h new file mode 100644 index 0000000000..bacec5c786 --- /dev/null +++ b/cpp/include/qpid/messaging/Codec.h @@ -0,0 +1,44 @@ +#ifndef QPID_MESSAGING_CODEC_H +#define QPID_MESSAGING_CODEC_H + +/* + * + * 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 <string> +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace messaging { + +class Variant; +/** + * + */ +class Codec +{ + public: + QPID_CLIENT_EXTERN virtual ~Codec() {} + virtual void encode(const Variant&, std::string&) = 0; + virtual void decode(const std::string&, Variant&) = 0; + private: +}; +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_CODEC_H*/ diff --git a/cpp/include/qpid/messaging/Connection.h b/cpp/include/qpid/messaging/Connection.h new file mode 100644 index 0000000000..5517e45af9 --- /dev/null +++ b/cpp/include/qpid/messaging/Connection.h @@ -0,0 +1,67 @@ +#ifndef QPID_MESSAGING_CONNECTION_H +#define QPID_MESSAGING_CONNECTION_H + +/* + * + * 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 <string> +#include "qpid/client/ClientImportExport.h" +#include "qpid/client/Handle.h" +#include "qpid/messaging/Variant.h" + +namespace qpid { +namespace client { + +template <class> class PrivateImplRef; + +} + +namespace messaging { + +class ConnectionImpl; +class Session; + +class Connection : public qpid::client::Handle<ConnectionImpl> +{ + public: + static Connection open(const std::string& url, const Variant::Map& options = Variant::Map()); + + QPID_CLIENT_EXTERN Connection(ConnectionImpl* impl = 0); + QPID_CLIENT_EXTERN Connection(const Connection&); + QPID_CLIENT_EXTERN ~Connection(); + QPID_CLIENT_EXTERN Connection& operator=(const Connection&); + QPID_CLIENT_EXTERN void close(); + QPID_CLIENT_EXTERN Session newSession(); + private: + friend class qpid::client::PrivateImplRef<Connection>; + +}; + +struct InvalidOptionString : public qpid::Exception +{ + InvalidOptionString(const std::string& msg); +}; + +QPID_CLIENT_EXTERN void parseOptionString(const std::string&, Variant::Map&); +QPID_CLIENT_EXTERN Variant::Map parseOptionString(const std::string&); + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_CONNECTION_H*/ diff --git a/cpp/include/qpid/messaging/Filter.h b/cpp/include/qpid/messaging/Filter.h new file mode 100644 index 0000000000..5cd844cf73 --- /dev/null +++ b/cpp/include/qpid/messaging/Filter.h @@ -0,0 +1,48 @@ +#ifndef QPID_MESSAGING_FILTER_H +#define QPID_MESSAGING_FILTER_H + +/* + * + * 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 <string> +#include <vector> +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { +} + +namespace messaging { + +struct Filter +{ + std::string type; + std::vector<std::string> patterns; + + QPID_CLIENT_EXTERN Filter(std::string type, std::string pattern); + QPID_CLIENT_EXTERN Filter(std::string type, std::string pattern1, std::string pattern2); + + static QPID_CLIENT_EXTERN const std::string WILDCARD; + static QPID_CLIENT_EXTERN const std::string EXACT_MATCH; +}; + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_FILTER_H*/ diff --git a/cpp/include/qpid/messaging/Message.h b/cpp/include/qpid/messaging/Message.h new file mode 100644 index 0000000000..39edae3637 --- /dev/null +++ b/cpp/include/qpid/messaging/Message.h @@ -0,0 +1,90 @@ +#ifndef QPID_MESSAGING_MESSAGE_H +#define QPID_MESSAGING_MESSAGE_H + +/* + * + * 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 <string> +#include "qpid/messaging/Variant.h" +#include "qpid/messaging/MessageContent.h" +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { +} + +namespace messaging { + +class Address; +class Codec; +class MessageImpl; + +/** + * Representation of a message. + */ +class Message +{ + public: + QPID_CLIENT_EXTERN Message(const std::string& bytes = std::string()); + QPID_CLIENT_EXTERN Message(const char*, size_t); + QPID_CLIENT_EXTERN Message(const Message&); + QPID_CLIENT_EXTERN ~Message(); + + QPID_CLIENT_EXTERN Message& operator=(const Message&); + + QPID_CLIENT_EXTERN void setReplyTo(const Address&); + QPID_CLIENT_EXTERN const Address& getReplyTo() const; + + QPID_CLIENT_EXTERN void setSubject(const std::string&); + QPID_CLIENT_EXTERN const std::string& getSubject() const; + + QPID_CLIENT_EXTERN void setContentType(const std::string&); + QPID_CLIENT_EXTERN const std::string& getContentType() const; + + QPID_CLIENT_EXTERN const VariantMap& getHeaders() const; + QPID_CLIENT_EXTERN VariantMap& getHeaders(); + + QPID_CLIENT_EXTERN const std::string& getBytes() const; + QPID_CLIENT_EXTERN std::string& getBytes(); + QPID_CLIENT_EXTERN void setBytes(const std::string&); + QPID_CLIENT_EXTERN void setBytes(const char* chars, size_t count); + QPID_CLIENT_EXTERN const char* getRawContent() const; + QPID_CLIENT_EXTERN size_t getContentSize() const; + + + QPID_CLIENT_EXTERN MessageContent& getContent(); + QPID_CLIENT_EXTERN const MessageContent& getContent() const; + QPID_CLIENT_EXTERN void setContent(const std::string& s); + QPID_CLIENT_EXTERN void setContent(const Variant::Map&); + QPID_CLIENT_EXTERN void setContent(const Variant::List&); + + QPID_CLIENT_EXTERN void encode(Codec&); + QPID_CLIENT_EXTERN void decode(Codec&); + + //TODO: move this out of the public API + QPID_CLIENT_EXTERN void setInternalId(void*); + QPID_CLIENT_EXTERN void* getInternalId(); + private: + MessageImpl* impl; +}; +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_MESSAGE_H*/ diff --git a/cpp/include/qpid/messaging/MessageContent.h b/cpp/include/qpid/messaging/MessageContent.h new file mode 100644 index 0000000000..7c3a636c07 --- /dev/null +++ b/cpp/include/qpid/messaging/MessageContent.h @@ -0,0 +1,90 @@ +#ifndef QPID_MESSAGING_MESSAGECONTENT_H +#define QPID_MESSAGING_MESSAGECONTENT_H + +/* + * + * 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 "qpid/messaging/Variant.h" +#include <string> +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace messaging { + +/** + * + */ +class MessageContent +{ + public: + QPID_CLIENT_EXTERN virtual ~MessageContent() {} + + virtual const std::string& asString() const = 0; + virtual std::string& asString() = 0; + + virtual const char* asChars() const = 0; + virtual size_t size() const = 0; + + virtual const Variant::Map& asMap() const = 0; + virtual Variant::Map& asMap() = 0; + virtual bool isMap() const = 0; + + virtual const Variant::List& asList() const = 0; + virtual Variant::List& asList() = 0; + virtual bool isList() const = 0; + + virtual void clear() = 0; + + virtual Variant& operator[](const std::string&) = 0; + + + virtual std::ostream& print(std::ostream& out) const = 0; + + + //operator<< for variety of types... (is this a good idea?) + virtual MessageContent& operator<<(const std::string&) = 0; + virtual MessageContent& operator<<(const char*) = 0; + virtual MessageContent& operator<<(bool) = 0; + virtual MessageContent& operator<<(int8_t) = 0; + virtual MessageContent& operator<<(int16_t) = 0; + virtual MessageContent& operator<<(int32_t) = 0; + virtual MessageContent& operator<<(int64_t) = 0; + virtual MessageContent& operator<<(uint8_t) = 0; + virtual MessageContent& operator<<(uint16_t) = 0; + virtual MessageContent& operator<<(uint32_t) = 0; + virtual MessageContent& operator<<(uint64_t) = 0; + virtual MessageContent& operator<<(double) = 0; + virtual MessageContent& operator<<(float) = 0; + + //assignment from string, map and list + virtual MessageContent& operator=(const std::string&) = 0; + virtual MessageContent& operator=(const char*) = 0; + virtual MessageContent& operator=(const Variant::Map&) = 0; + virtual MessageContent& operator=(const Variant::List&) = 0; + + private: +}; + +QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const MessageContent& content); + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_MESSAGECONTENT_H*/ diff --git a/cpp/include/qpid/messaging/MessageListener.h b/cpp/include/qpid/messaging/MessageListener.h new file mode 100644 index 0000000000..72811e7b9c --- /dev/null +++ b/cpp/include/qpid/messaging/MessageListener.h @@ -0,0 +1,49 @@ +#ifndef QPID_MESSAGING_MESSAGELISTENER_H +#define QPID_MESSAGING_MESSAGELISTENER_H + +/* + * + * 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 "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace messaging { + +class Message; + +/** + * To use a push style interface for receiving messages, applications + * provide implementations of this interface and pass an implementing + * instance to MessageSource::subscribe(). + * + * Messages arriving for that subscription will then be passed to the + * implementation via the received() method. + */ +class MessageListener +{ + public: + QPID_CLIENT_EXTERN virtual ~MessageListener() {} + virtual void received(Message&) = 0; + private: +}; + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_MESSAGELISTENER_H*/ diff --git a/cpp/include/qpid/messaging/Receiver.h b/cpp/include/qpid/messaging/Receiver.h new file mode 100644 index 0000000000..e51e1093d1 --- /dev/null +++ b/cpp/include/qpid/messaging/Receiver.h @@ -0,0 +1,115 @@ +#ifndef QPID_MESSAGING_RECEIVER_H +#define QPID_MESSAGING_RECEIVER_H + +/* + * + * 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 "qpid/Exception.h" +#include "qpid/client/ClientImportExport.h" +#include "qpid/client/Handle.h" +#include "qpid/sys/Time.h" + +namespace qpid { +namespace client { + +template <class> class PrivateImplRef; + +} + +namespace messaging { + +class Message; +class MessageListener; +class ReceiverImpl; + +/** + * A pull style interface for message retrieval. + */ +class Receiver : public qpid::client::Handle<ReceiverImpl> +{ + public: + struct NoMessageAvailable : qpid::Exception {}; + + QPID_CLIENT_EXTERN Receiver(ReceiverImpl* impl = 0); + QPID_CLIENT_EXTERN Receiver(const Receiver&); + QPID_CLIENT_EXTERN ~Receiver(); + QPID_CLIENT_EXTERN Receiver& operator=(const Receiver&); + /** + * Retrieves a message from this receivers local queue, or waits + * for upto the specified timeout for a message to become + * available. Returns false if there is no message to give after + * waiting for the specified timeout. + */ + QPID_CLIENT_EXTERN bool get(Message& message, qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + /** + * Retrieves a message from this receivers local queue, or waits + * for upto the specified timeout for a message to become + * available. Throws NoMessageAvailable if there is no + * message to give after waiting for the specified timeout. + */ + QPID_CLIENT_EXTERN Message get(qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + /** + * Retrieves a message for this receivers subscription or waits + * for upto the specified timeout for one to become + * available. Unlike get() this method will check with the server + * that there is no message for the subscription this receiver is + * serving before returning false. + */ + QPID_CLIENT_EXTERN bool fetch(Message& message, qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + /** + * Retrieves a message for this receivers subscription or waits + * for upto the specified timeout for one to become + * available. Unlike get() this method will check with the server + * that there is no message for the subscription this receiver is + * serving before throwing an exception. + */ + QPID_CLIENT_EXTERN Message fetch(qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + + /** + * Enables the message flow for this receiver + */ + QPID_CLIENT_EXTERN void start(); + /** + * Stops the message flow for this receiver (without actually + * cancelling the subscription). + */ + QPID_CLIENT_EXTERN void stop(); + /** + * Sets the capacity for the receiver. The capacity determines how + * many incoming messages can be held in the receiver before being + * requested by a client via fetch() (or pushed to a listener). + */ + QPID_CLIENT_EXTERN void setCapacity(uint32_t); + + /** + * Cancels this receiver + */ + QPID_CLIENT_EXTERN void cancel(); + + /** + * Set a message listener for receiving messages asynchronously. + */ + QPID_CLIENT_EXTERN void setListener(MessageListener* listener); + private: + friend class qpid::client::PrivateImplRef<Receiver>; +}; +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_RECEIVER_H*/ diff --git a/cpp/include/qpid/messaging/Sender.h b/cpp/include/qpid/messaging/Sender.h new file mode 100644 index 0000000000..657c4b8cfe --- /dev/null +++ b/cpp/include/qpid/messaging/Sender.h @@ -0,0 +1,57 @@ +#ifndef QPID_MESSAGING_SENDER_H +#define QPID_MESSAGING_SENDER_H + +/* + * + * 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 "qpid/client/ClientImportExport.h" +#include "qpid/client/Handle.h" + +namespace qpid { +namespace client { + +template <class> class PrivateImplRef; + +} + +namespace messaging { + +class Message; +class SenderImpl; + +/** + * Interface through which messages are sent. + */ +class Sender : public qpid::client::Handle<SenderImpl> +{ + public: + QPID_CLIENT_EXTERN Sender(SenderImpl* impl = 0); + QPID_CLIENT_EXTERN Sender(const Sender&); + QPID_CLIENT_EXTERN ~Sender(); + QPID_CLIENT_EXTERN Sender& operator=(const Sender&); + + QPID_CLIENT_EXTERN void send(Message& message); + QPID_CLIENT_EXTERN void cancel(); + private: + friend class qpid::client::PrivateImplRef<Sender>; +}; +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_SENDER_H*/ diff --git a/cpp/include/qpid/messaging/Session.h b/cpp/include/qpid/messaging/Session.h new file mode 100644 index 0000000000..3a354c009f --- /dev/null +++ b/cpp/include/qpid/messaging/Session.h @@ -0,0 +1,99 @@ +#ifndef QPID_MESSAGING_SESSION_H +#define QPID_MESSAGING_SESSION_H + +/* + * + * 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 "qpid/client/ClientImportExport.h" +#include "qpid/client/Handle.h" +#include "qpid/sys/Time.h" +#include "Variant.h" + +namespace qpid { +namespace client { + +template <class> class PrivateImplRef; + +} + +namespace messaging { + +class Address; +class Filter; +class Message; +class MessageListener; +class Sender; +class Receiver; +class SessionImpl; +class Subscription; + +/** + * A session represents a distinct 'conversation' which can involve + * sending and receiving messages from different sources and sinks. + */ +class Session : public qpid::client::Handle<SessionImpl> +{ + public: + QPID_CLIENT_EXTERN Session(SessionImpl* impl = 0); + QPID_CLIENT_EXTERN Session(const Session&); + QPID_CLIENT_EXTERN ~Session(); + QPID_CLIENT_EXTERN Session& operator=(const Session&); + + QPID_CLIENT_EXTERN void close(); + + QPID_CLIENT_EXTERN void commit(); + QPID_CLIENT_EXTERN void rollback(); + + /** + * Acknowledges all outstanding messages that have been received + * by the application on this session. + */ + QPID_CLIENT_EXTERN void acknowledge(); + /** + * Rejects the specified message. This will prevent the message + * being redelivered. + */ + QPID_CLIENT_EXTERN void reject(Message&); + + QPID_CLIENT_EXTERN void sync(); + QPID_CLIENT_EXTERN void flush(); + + QPID_CLIENT_EXTERN bool fetch(Message& message, qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + QPID_CLIENT_EXTERN Message fetch(qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + QPID_CLIENT_EXTERN bool dispatch(qpid::sys::Duration timeout=qpid::sys::TIME_INFINITE); + + QPID_CLIENT_EXTERN Sender createSender(const Address& address, const VariantMap& options = VariantMap()); + QPID_CLIENT_EXTERN Sender createSender(const std::string& address, const VariantMap& options = VariantMap()); + + QPID_CLIENT_EXTERN Receiver createReceiver(const Address& address, const VariantMap& options = VariantMap()); + QPID_CLIENT_EXTERN Receiver createReceiver(const Address& address, const Filter& filter, const VariantMap& options = VariantMap()); + QPID_CLIENT_EXTERN Receiver createReceiver(const std::string& address, const VariantMap& options = VariantMap()); + QPID_CLIENT_EXTERN Receiver createReceiver(const std::string& address, const Filter& filter, const VariantMap& options = VariantMap()); + + QPID_CLIENT_EXTERN Address createTempQueue(const std::string& baseName = std::string()); + + QPID_CLIENT_EXTERN void* getLastConfirmedSent(); + QPID_CLIENT_EXTERN void* getLastConfirmedAcknowledged(); + private: + friend class qpid::client::PrivateImplRef<Session>; +}; +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_SESSION_H*/ diff --git a/cpp/include/qpid/messaging/Variant.h b/cpp/include/qpid/messaging/Variant.h new file mode 100644 index 0000000000..ac000244c2 --- /dev/null +++ b/cpp/include/qpid/messaging/Variant.h @@ -0,0 +1,167 @@ +#ifndef QPID_MESSAGING_VARIANT_H +#define QPID_MESSAGING_VARIANT_H + +/* + * + * 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 <list> +#include <map> +#include <ostream> +#include <string> +#include "qpid/Exception.h" +#include "qpid/sys/IntegerTypes.h" +#include "qpid/client/ClientImportExport.h" + +namespace qpid { +namespace client { +} + +namespace messaging { + +/** + * Thrown when an illegal conversion of a variant is attempted. + */ +struct InvalidConversion : public qpid::Exception +{ + InvalidConversion(const std::string& msg); +}; + +enum VariantType { + VOID = 0, + BOOL, + UINT8, + UINT16, + UINT32, + UINT64, + INT8, + INT16, + INT32, + INT64, + FLOAT, + DOUBLE, + STRING, + MAP, + LIST +}; + +class VariantImpl; + +/** + * Represents a value of variable type. + */ +class Variant +{ + public: + typedef std::map<std::string, Variant> Map; + typedef std::list<Variant> List; + + QPID_CLIENT_EXTERN Variant(); + QPID_CLIENT_EXTERN Variant(bool); + QPID_CLIENT_EXTERN Variant(uint8_t); + QPID_CLIENT_EXTERN Variant(uint16_t); + QPID_CLIENT_EXTERN Variant(uint32_t); + QPID_CLIENT_EXTERN Variant(uint64_t); + QPID_CLIENT_EXTERN Variant(int8_t); + QPID_CLIENT_EXTERN Variant(int16_t); + QPID_CLIENT_EXTERN Variant(int32_t); + QPID_CLIENT_EXTERN Variant(int64_t); + QPID_CLIENT_EXTERN Variant(float); + QPID_CLIENT_EXTERN Variant(double); + QPID_CLIENT_EXTERN Variant(const std::string&); + QPID_CLIENT_EXTERN Variant(const char*); + QPID_CLIENT_EXTERN Variant(const Map&); + QPID_CLIENT_EXTERN Variant(const List&); + QPID_CLIENT_EXTERN Variant(const Variant&); + + QPID_CLIENT_EXTERN ~Variant(); + + QPID_CLIENT_EXTERN VariantType getType() const; + + QPID_CLIENT_EXTERN Variant& operator=(bool); + QPID_CLIENT_EXTERN Variant& operator=(uint8_t); + QPID_CLIENT_EXTERN Variant& operator=(uint16_t); + QPID_CLIENT_EXTERN Variant& operator=(uint32_t); + QPID_CLIENT_EXTERN Variant& operator=(uint64_t); + QPID_CLIENT_EXTERN Variant& operator=(int8_t); + QPID_CLIENT_EXTERN Variant& operator=(int16_t); + QPID_CLIENT_EXTERN Variant& operator=(int32_t); + QPID_CLIENT_EXTERN Variant& operator=(int64_t); + QPID_CLIENT_EXTERN Variant& operator=(float); + QPID_CLIENT_EXTERN Variant& operator=(double); + QPID_CLIENT_EXTERN Variant& operator=(const std::string&); + QPID_CLIENT_EXTERN Variant& operator=(const char*); + QPID_CLIENT_EXTERN Variant& operator=(const Map&); + QPID_CLIENT_EXTERN Variant& operator=(const List&); + QPID_CLIENT_EXTERN Variant& operator=(const Variant&); + + QPID_CLIENT_EXTERN bool asBool() const; + QPID_CLIENT_EXTERN uint8_t asUint8() const; + QPID_CLIENT_EXTERN uint16_t asUint16() const; + QPID_CLIENT_EXTERN uint32_t asUint32() const; + QPID_CLIENT_EXTERN uint64_t asUint64() const; + QPID_CLIENT_EXTERN int8_t asInt8() const; + QPID_CLIENT_EXTERN int16_t asInt16() const; + QPID_CLIENT_EXTERN int32_t asInt32() const; + QPID_CLIENT_EXTERN int64_t asInt64() const; + QPID_CLIENT_EXTERN float asFloat() const; + QPID_CLIENT_EXTERN double asDouble() const; + QPID_CLIENT_EXTERN std::string asString() const; + + QPID_CLIENT_EXTERN operator bool() const; + QPID_CLIENT_EXTERN operator uint8_t() const; + QPID_CLIENT_EXTERN operator uint16_t() const; + QPID_CLIENT_EXTERN operator uint32_t() const; + QPID_CLIENT_EXTERN operator uint64_t() const; + QPID_CLIENT_EXTERN operator int8_t() const; + QPID_CLIENT_EXTERN operator int16_t() const; + QPID_CLIENT_EXTERN operator int32_t() const; + QPID_CLIENT_EXTERN operator int64_t() const; + QPID_CLIENT_EXTERN operator float() const; + QPID_CLIENT_EXTERN operator double() const; + QPID_CLIENT_EXTERN operator const char*() const; + + QPID_CLIENT_EXTERN const Map& asMap() const; + QPID_CLIENT_EXTERN Map& asMap(); + QPID_CLIENT_EXTERN const List& asList() const; + QPID_CLIENT_EXTERN List& asList(); + /** + * Unlike asString(), getString() will not do any conversions and + * will throw InvalidConversion if the type is not STRING. + */ + QPID_CLIENT_EXTERN const std::string& getString() const; + QPID_CLIENT_EXTERN std::string& getString(); + + QPID_CLIENT_EXTERN void setEncoding(const std::string&); + QPID_CLIENT_EXTERN const std::string& getEncoding() const; + + QPID_CLIENT_EXTERN void reset(); + private: + VariantImpl* impl; +}; + +QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Variant& value); +QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::Map& map); +QPID_CLIENT_EXTERN std::ostream& operator<<(std::ostream& out, const Variant::List& list); + +typedef Variant::Map VariantMap; + +}} // namespace qpid::messaging + +#endif /*!QPID_MESSAGING_VARIANT_H*/ |