commit 62fce2e106346bd01b42bffe48e571c4cd954e94 Author: Frank Pagliughi Date: Tue Sep 3 16:21:24 2013 +0100 Initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3290d87 --- /dev/null +++ b/Makefile @@ -0,0 +1,136 @@ +# Make include file for the mqttpp library +# +# This will compile all the .cpp files in the directory into the library. +# Any files to be excluded should be placed in the variable SRC_IGNORE, like: +# SRC_IGNORE = this.c that.cpp +# + +MODULE = mqttpp + +# ----- Tools ----- + +ifndef VERBOSE + QUIET := @ +endif + +# ----- Directories ----- + +LIB_DIR ?= lib +OBJ_DIR ?= obj +INC_DIR ?= . + +PAHO_C_LIB ?= /home/fmp/static/opensrc/mqtt/paho/org.eclipse.paho.mqtt.c + +INC_DIRS += $(INC_DIR) $(PAHO_C_LIB)/src + +_MK_OBJ_DIR := $(shell mkdir -p $(OBJ_DIR)) +_MK_LIB_DIR := $(shell mkdir -p $(LIB_DIR)) + +# ----- Definitions for the shared library ----- + +LIB_BASE ?= $(MODULE) +LIB_MAJOR ?= 0 +LIB_MINOR ?= 1 + +LIB_LINK = lib$(LIB_BASE).so +LIB_MAJOR_LINK = $(LIB_LINK).$(LIB_MAJOR) + +LIB = $(LIB_MAJOR_LINK).$(LIB_MINOR) + +TGT = $(LIB_DIR)/$(LIB) + +# ----- Sources ----- + +SRCS += $(wildcard *.cpp) + +ifdef SRC_IGNORE + SRCS := $(filter-out $(SRC_IGNORE),$(SRCS)) +endif + +OBJS := $(addprefix $(OBJ_DIR)/,$(SRCS:.cpp=.o)) +DEPS := $(OBJS:.o=.dep) + +# ----- Compiler flags, etc ----- + +CXXFLAGS += -std=c++0x +CPPFLAGS += -Wall -fPIC + +ifdef DEBUG + DEFS += DEBUG + CPPFLAGS += -g -O0 +else + DEFS += _NDEBUG + CPPFLAGS += -O2 -Wno-unused-result -Werror +endif + +CPPFLAGS += $(addprefix -D,$(DEFS)) $(addprefix -I,$(INC_DIRS)) + +LIB_DEPS += c stdc++ pthread + +LIB_DEP_FLAGS += $(addprefix -l,$(LIB_DEPS)) + +LDFLAGS := -g -shared -Wl,-soname,$(LIB_MAJOR_LINK) -L$(LIB_DIR) + +# ----- Compiler directives ----- + +$(OBJ_DIR)/%.o: %.cpp + @echo $(CXX) $< + $(QUIET) $(COMPILE.cpp) $(OUTPUT_OPTION) $< + +# ----- Build targets ----- + +.PHONY: all +all: $(TGT) $(LIB_DIR)/$(LIB_LINK) $(LIB_DIR)/$(LIB_MAJOR_LINK) + +# This might work for a static library +#$(TGT): $(OBJS) +# @echo Creating library: $@ +# $(QUIET) $(AR) $(ARFLAGS) $@ $^ + +$(TGT): $(OBJS) + @echo Creating library: $@ + $(QUIET) $(CC) $(LDFLAGS) -o $@ $^ $(LIB_DEP_FLAGS) + +$(LIB_DIR)/$(LIB_LINK): $(LIB_DIR)/$(LIB_MAJOR_LINK) + $(QUIET) cd $(LIB_DIR) ; $(RM) $(LIB_LINK) ; ln -s $(LIB_MAJOR_LINK) $(LIB_LINK) + +$(LIB_DIR)/$(LIB_MAJOR_LINK): $(TGT) + $(QUIET) cd $(LIB_DIR) ; $(RM) $(LIB_MAJOR_LINK) ; ln -s $(LIB) $(LIB_MAJOR_LINK) + +.PHONY: dump +dump: + @echo LIB=$(LIB) + @echo TGT=$(TGT) + @echo LIB_DIR=$(LIB_DIR) + @echo OBJ_DIR=$(OBJ_DIR) + @echo CFLAGS=$(CFLAGS) + @echo CPPFLAGS=$(CPPFLAGS) + @echo CXX=$(CXX) + @echo COMPILE.cpp=$(COMPILE.cpp) + @echo SRCS=$(SRCS) + @echo OBJS=$(OBJS) + @echo DEPS:$(DEPS) + @echo LIB_DEPS=$(LIB_DEPS) + +.PHONY: clean +clean: + $(QUIET) $(RM) $(TGT) $(LIB_DIR)/$(LIB_LINK) $(LIB_DIR)/$(LIB_MAJOR_LINK) \ + $(OBJS) + +.PHONY: distclean +distclean: clean + $(QUIET) rm -rf $(OBJ_DIR) $(LIB_DIR) + +# ----- Header dependencies ----- + +MKG := $(findstring $(MAKECMDGOALS),"clean distclean dump") +ifeq "$(MKG)" "" + -include $(DEPS) +endif + +$(OBJ_DIR)/%.dep: %.cpp + @echo DEP $< + $(QUIET) $(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,$$(OBJ_DIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \ + $(RM) $@.$$$$ + diff --git a/README.md b/README.md new file mode 100644 index 0000000..52278e6 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ + + +The API organization and documentation were adapted from the Paho Java library +by Dave Locke. +Copyright (c) 2012, IBM Corp + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/epl-v10.html + +----------- + +This code requires the Paho C library by Ian Craggs +Copyright (c) 2013 IBM Corp. + + All rights reserved. This program and the accompanying materials + are made available under the terms of the Eclipse Public License v1.0 + and Eclipse Distribution License v1.0 which accompany this distribution. + + The Eclipse Public License is available at + http://www.eclipse.org/legal/epl-v10.html + and the Eclipse Distribution License is available at + http://www.eclipse.org/org/documents/edl-v10.php. + diff --git a/doc/.include b/doc/.include new file mode 100644 index 0000000..e69de29 diff --git a/doc/Doxyfile b/doc/Doxyfile new file mode 100644 index 0000000..697841c --- /dev/null +++ b/doc/Doxyfile @@ -0,0 +1,1781 @@ +# Doxyfile 1.7.6.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" "). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or sequence of words) that should +# identify the project. Note that if you do not use Doxywizard you need +# to put quotes around the project name if it contains spaces. + +PROJECT_NAME = "mqttpp" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = "0.1" + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer +# a quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = "C++ wrapper library for the Paho MQTT C library" + +# With the PROJECT_LOGO tag one can specify an logo or icon that is +# included in the documentation. The maximum height of the logo should not +# exceed 55 pixels and the maximum width should not exceed 200 pixels. +# Doxygen will copy the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful if your file system +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding +# "class=itcl::class" will allow you to use the command class in the +# itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given extension. +# Doxygen has a built-in mapping, but you can override or extend it using this +# tag. The format is ext=language, where ext is a file extension, and language +# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, +# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make +# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C +# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions +# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also makes the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and +# unions are shown inside the group in which they are included (e.g. using +# @ingroup) instead of on a separate page (for HTML and Man pages) or +# section (for LaTeX and RTF). + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and +# unions with only public data fields will be shown inline in the documentation +# of the scope in which they are defined (i.e. file, namespace, or group +# documentation), provided this scope is documented. If set to NO (the default), +# structs, classes, and unions are shown on a separate page (for HTML and Man +# pages) or section (for LaTeX and RTF). + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penalty. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will roughly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +SYMBOL_CACHE_SIZE = 0 + +# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be +# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given +# their name and scope. Since this can be an expensive process and often the +# same symbol appear multiple times in the code, doxygen keeps a cache of +# pre-resolved symbols. If the cache is too small doxygen will become slower. +# If the cache is too large, memory is wasted. The cache size is given by this +# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespaces are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen +# will list include files with double quotes in the documentation +# rather than with sharp brackets. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen +# will sort the (brief and detailed) documentation of class members so that +# constructors and destructors are listed first. If set to NO (the default) +# the constructors will appear in the respective orders defined by +# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. +# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO +# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to +# do proper type resolution of all parameters of a function it will reject a +# match between the prototype and the implementation of a member function even +# if there is only one candidate or it is obvious which candidate to choose +# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen +# will still accept a match between prototype and implementation in such cases. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or macro consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and macros in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. +# This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. The create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. +# You can optionally specify a file name after the option, if omitted +# DoxygenLayout.xml will be used as the name of the layout file. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files +# containing the references data. This must be a list of .bib files. The +# .bib extension is automatically appended if omitted. Using this command +# requires the bibtex tool to be installed. See also +# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style +# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this +# feature you need bibtex and perl available in the search path. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# The WARN_NO_PARAMDOC option can be enabled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh +# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py +# *.f90 *.f *.for *.vhd *.vhdl + +FILE_PATTERNS = *.h + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. +# If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. +# Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. +# The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty or if +# non of the patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) +# and it is also possible to disable source filtering for a specific pattern +# using *.ext= (so without naming a filter). This option only has effect when +# FILTER_SOURCE_FILES is enabled. + +FILTER_SOURCE_PATTERNS = + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. +# Otherwise they will link to the documentation. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. Note that when using a custom header you are responsible +# for the proper inclusion of any scripts and style sheets that doxygen +# needs, which is dependent on the configuration options used. +# It is advised to generate a default header using "doxygen -w html +# header.html footer.html stylesheet.css YourConfigFile" and then modify +# that header. Note that the header is subject to change so you typically +# have to redo this when upgrading to a newer version of doxygen or when +# changing the value of configuration settings such as GENERATE_TREEVIEW! + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# style sheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that +# the files will be copied as-is; there are no commands or markers available. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. +# Doxygen will adjust the colors in the style sheet and background images +# according to this color. Hue is specified as an angle on a colorwheel, +# see http://en.wikipedia.org/wiki/Hue for more information. +# For instance the value 0 represents red, 60 is yellow, 120 is green, +# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. +# The allowed range is 0 to 359. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of +# the colors in the HTML output. For a value of 0 the output will use +# grayscales only. A value of 255 will produce the most vivid colors. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to +# the luminance component of the colors in the HTML output. Values below +# 100 gradually make the output lighter, whereas values above 100 make +# the output darker. The value divided by 100 is the actual gamma applied, +# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, +# and 100 does not change the gamma. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting +# this to NO can help when comparing the output of multiple runs. + +HTML_TIMESTAMP = YES + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = NO + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated +# that can be used as input for Qt's qhelpgenerator to generate a +# Qt Compressed Help (.qch) of the generated HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#namespace + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#virtual-folders + +QHP_VIRTUAL_FOLDER = doc + +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to +# add. For more information please see +# http://doc.trolltech.com/qthelpproject.html#custom-filters + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see +# +# Qt Help Project / Custom Filters. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's +# filter section matches. +# +# Qt Help Project / Filter Attributes. + +QHP_SECT_FILTER_ATTRS = + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files +# will be generated, which together with the HTML files, form an Eclipse help +# plugin. To install this plugin and make it available under the help contents +# menu in Eclipse, the contents of the directory containing the HTML and XML +# files needs to be copied into the plugins directory of eclipse. The name of +# the directory within the plugins directory should be the same as +# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before +# the help appears. + +GENERATE_ECLIPSEHELP = YES + +# A unique identifier for the eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have +# this name. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) +# at top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. Since the tabs have the same information as the +# navigation tree you can set this option to NO if you already set +# GENERATE_TREEVIEW to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to YES, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. +# Since the tree basically has the same information as the tab index you +# could consider to set DISABLE_INDEX to NO when enabling this option. + +GENERATE_TREEVIEW = YES + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values +# (range [0,1..20]) that doxygen will group on one line in the generated HTML +# documentation. Note that a value of 0 will completely suppress the enum +# values from appearing in the overview section. + +ENUM_VALUES_PER_LINE = 4 + +# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, +# and Class Hierarchy pages using a tree view instead of an ordered list. + +USE_INLINE_TREES = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open +# links to external symbols imported via tag files in a separate window. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are +# not supported properly for IE 6.0, but are supported on all modern browsers. +# Note that when changing this option you need to delete any form_*.png files +# in the HTML output before the changes have effect. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax +# (see http://www.mathjax.org) which uses client side Javascript for the +# rendering instead of using prerendered bitmaps. Use this if you do not +# have LaTeX installed or if you want to formulas look prettier in the HTML +# output. When enabled you also need to install MathJax separately and +# configure the path to it using the MATHJAX_RELPATH option. + +USE_MATHJAX = NO + +# When MathJax is enabled you need to specify the location relative to the +# HTML output directory using the MATHJAX_RELPATH option. The destination +# directory should contain the MathJax.js script. For instance, if the mathjax +# directory is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the +# mathjax.org site, so you can quickly see the result without installing +# MathJax, but it is strongly recommended to install a local copy of MathJax +# before deployment. + +MATHJAX_RELPATH = http://www.mathjax.org/mathjax + +# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension +# names that should be enabled during MathJax rendering. + +MATHJAX_EXTENSIONS = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box +# for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using +# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets +# (GENERATE_DOCSET) there is already a search function so this one should +# typically be disabled. For large projects the javascript based search engine +# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. + +SEARCHENGINE = YES + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a PHP enabled web server instead of at the web client +# using Javascript. Doxygen will generate the search PHP script and index +# file to put on the web server. The advantage of the server +# based approach is that it scales better to large projects and allows +# full text search. The disadvantages are that it is more difficult to setup +# and does not have live searching capabilities. + +SERVER_BASED_SEARCH = NO + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. +# Note that when enabling USE_PDFLATEX this option is only used for +# generating bitmaps for formulas in the HTML output, but not in the +# Makefile that is written to the output directory. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4 + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for +# the generated latex document. The footer should contain everything after +# the last chapter. If it is left blank doxygen will generate a +# standard footer. Notice: only use this tag if you know what you are doing! + +LATEX_FOOTER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +# If LATEX_SOURCE_CODE is set to YES then doxygen will include +# source code with syntax highlighting in the LaTeX output. +# Note that which sources are shown also depends on other settings +# such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See +# http://en.wikipedia.org/wiki/BibTeX for more info. + +LATEX_BIB_STYLE = plain + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load style sheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. +# This is useful +# if you want to understand what is going on. +# On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# pointed to by INCLUDE_PATH will be searched when a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition that +# overrules the definition found in the source code. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all references to function-like macros +# that are alone on a line, have an all uppercase name, and do not end with a +# semicolon, because these will confuse the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option also works with HAVE_DOT disabled, but it is recommended to +# install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is +# allowed to run in parallel. When set to 0 (the default) doxygen will +# base this on the number of processors available in the system. You can set it +# explicitly to a value larger than 0 to get control over the balance +# between CPU load and processing speed. + +DOT_NUM_THREADS = 0 + +# By default doxygen will use the Helvetica font for all dot files that +# doxygen generates. When you want a differently looking font you can specify +# the font name using DOT_FONTNAME. You need to make sure dot is able to find +# the font, which can be done by putting it in a standard location or by setting +# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the +# directory containing the font. + +DOT_FONTNAME = Helvetica + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the Helvetica font. +# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to +# set the path where dot can find it. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will generate a graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are svg, png, jpg, or gif. +# If left blank png will be used. If you choose svg you need to set +# HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible in IE 9+ (other browsers do not have this requirement). + +DOT_IMAGE_FORMAT = png + +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# Note that this requires a modern browser other than Internet Explorer. +# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you +# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible. Older versions of IE do not have SVG support. + +INTERACTIVE_SVG = NO + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the +# \mscfile command). + +MSCFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = YES + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES diff --git a/edl-v10 b/edl-v10 new file mode 100644 index 0000000..cf989f1 --- /dev/null +++ b/edl-v10 @@ -0,0 +1,15 @@ + +Eclipse Distribution License - v 1.0 + +Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/epl-v10 b/epl-v10 new file mode 100644 index 0000000..79e486c --- /dev/null +++ b/epl-v10 @@ -0,0 +1,70 @@ +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. diff --git a/notice.html b/notice.html new file mode 100644 index 0000000..f19c483 --- /dev/null +++ b/notice.html @@ -0,0 +1,108 @@ + + + + + +Eclipse Foundation Software User Agreement + + + +

Eclipse Foundation Software User Agreement

+

February 1, 2011

+ +

Usage Of Content

+ +

THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS + (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND + CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE + OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR + NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND + CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.

+ +

Applicable Licenses

+ +

Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 + ("EPL"). A copy of the EPL is provided with this Content and is also available at http://www.eclipse.org/legal/epl-v10.html. + For purposes of the EPL, "Program" will mean the Content.

+ +

Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code + repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").

+ +
    +
  • Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").
  • +
  • Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".
  • +
  • A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins + and/or Fragments associated with that Feature.
  • +
  • Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.
  • +
+ +

The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and +Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module +including, but not limited to the following locations:

+ +
    +
  • The top-level (root) directory
  • +
  • Plug-in and Fragment directories
  • +
  • Inside Plug-ins and Fragments packaged as JARs
  • +
  • Sub-directories of the directory named "src" of certain Plug-ins
  • +
  • Feature directories
  • +
+ +

Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the +installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or +inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature. +Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in +that directory.

+ +

THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE +OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):

+ + + +

IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please +contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.

+ + +

Use of Provisioning Technology

+ +

The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse + Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or + other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to + install, extend and update Eclipse-based products. Information about packaging Installable Software is available at http://eclipse.org/equinox/p2/repository_packaging.html + ("Specification").

+ +

You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the + applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology + in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the + Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:

+ +
    +
  1. A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology + on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based + product.
  2. +
  3. During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be + accessed and copied to the Target Machine.
  4. +
  5. Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable + Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target + Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern + the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such + indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.
  6. +
+ +

Cryptography

+ +

Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to + another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import, + possession, or use, and re-export of encryption software, to see if this is permitted.

+ +

Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.

+ + diff --git a/src/async_client.cpp b/src/async_client.cpp new file mode 100644 index 0000000..3f17a1f --- /dev/null +++ b/src/async_client.cpp @@ -0,0 +1,664 @@ +//async_client.cpp + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#include "mqtt/async_client.h" +#include "mqtt/token.h" +#include "mqtt/message.h" +#include +#include +#include +#include +#include + +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +async_client::async_client(const std::string& serverURI, const std::string& clientId) + : serverURI_(serverURI), clientId_(clientId), + persist_(nullptr), userCallback_(nullptr) +{ + MQTTAsync_create(&cli_, const_cast(serverURI.c_str()), + const_cast(clientId.c_str()), + MQTTCLIENT_PERSISTENCE_DEFAULT, nullptr); +} + + +async_client::async_client(const std::string& serverURI, const std::string& clientId, + const std::string& persistDir) + : serverURI_(serverURI), clientId_(clientId), + persist_(nullptr), userCallback_(nullptr) +{ + MQTTAsync_create(&cli_, const_cast(serverURI.c_str()), + const_cast(clientId.c_str()), + MQTTCLIENT_PERSISTENCE_DEFAULT, + const_cast(persistDir.c_str())); +} + +async_client::async_client(const std::string& serverURI, const std::string& clientId, + iclient_persistence* persistence) + : serverURI_(serverURI), clientId_(clientId), + persist_(nullptr), userCallback_(nullptr) +{ + if (!persistence) { + MQTTAsync_create(&cli_, const_cast(serverURI.c_str()), + const_cast(clientId.c_str()), + MQTTCLIENT_PERSISTENCE_NONE, nullptr); + } + else { + persist_ = new MQTTClient_persistence { + persistence, + &iclient_persistence::persistence_open, + &iclient_persistence::persistence_close, + &iclient_persistence::persistence_put, + &iclient_persistence::persistence_get, + &iclient_persistence::persistence_remove, + &iclient_persistence::persistence_keys, + &iclient_persistence::persistence_clear, + &iclient_persistence::persistence_containskey + }; + + MQTTAsync_create(&cli_, const_cast(serverURI.c_str()), + const_cast(clientId.c_str()), + MQTTCLIENT_PERSISTENCE_USER, persist_); + } +} + +async_client::~async_client() +{ + MQTTAsync_destroy(&cli_); + delete persist_; +} + +// -------------------------------------------------------------------------- + +void async_client::on_connection_lost(void *context, char *cause) +{ + if (context) { + async_client* m = static_cast(context); + callback* cb = m->get_callback(); + if (cb) + cb->connection_lost(cause ? std::string(cause) : std::string()); + } +} + +int async_client::on_message_arrived(void* context, char* topicName, int topicLen, + MQTTAsync_message* msg) +{ + if (context) { + async_client* m = static_cast(context); + callback* cb = m->get_callback(); + if (cb) { + std::string topic(topicName, topicName+topicLen); + message_ptr m = std::make_shared(*msg); + cb->message_arrived(topic, m); + } + } + + MQTTAsync_freeMessage(&msg); + MQTTAsync_free(topicName); + + // TODO: Should the user code determine the return value? + // The Java version does doesn't seem to... + return (!0); +} + +// Callback to indicate that a message was delivered to the server. It seems +// to only be called for a message with a QOS >= 1, but it happens before +// the on_success() call for the token. Thus we don't have the underlying +// MQTTAsync_token of the outgoing message at the time of this callback. +// +// So, all in all, this callback in it's current implementation seems rather +// redundant. +// +#if 0 +void async_client::on_delivery_complete(void* context, MQTTAsync_token msgID) +{ + if (context) { + async_client* m = static_cast(context); + callback* cb = m->get_callback(); + if (cb) { + idelivery_token_ptr tok = m->get_pending_delivery_token(msgID); + cb->delivery_complete(tok); + } + } +} +#endif + +// -------------------------------------------------------------------------- + +void async_client::add_token(itoken_ptr tok) +{ + if (tok) { + guard g(lock_); + pendingTokens_.push_back(tok); + } +} + +void async_client::add_token(idelivery_token_ptr tok) +{ + if (tok) { + guard g(lock_); + pendingDeliveryTokens_.push_back(tok); + } +} + +// Note that we uniquely identify a token by the address of its raw pointer, +// since the message ID is not unique. + +void async_client::remove_token(itoken* tok) +{ + if (!tok) + return; + + guard g(lock_); + for (auto p=pendingDeliveryTokens_.begin(); + p!=pendingDeliveryTokens_.end(); ++p) { + if (p->get() == tok) { + idelivery_token_ptr dtok = *p; + pendingDeliveryTokens_.erase(p); + + // If there's a user callback registered, we can now call + // delivery_complete() + + if (userCallback_) { + message_ptr msg = dtok->get_message(); + if (msg && msg->get_qos() > 0) { + callback* cb = userCallback_; + g.unlock(); + cb->delivery_complete(dtok); + } + } + return; + } + } + for (auto p=pendingTokens_.begin(); p!=pendingTokens_.end(); ++p) { + if (p->get() == tok) { + pendingTokens_.erase(p); + return; + } + } +} + +std::vector async_client::alloc_topic_filters( + const topic_filter_collection& topicFilters) +{ + std::vector filts; + for (const auto& t : topicFilters) { + char* filt = new char[t.size()+1]; + std::strcpy(filt, t.c_str()); + filts.push_back(filt); + } + return filts; +} + +void async_client::free_topic_filters(std::vector& filts) +{ + for (const auto& f : filts) + delete[] f; +} + +// -------------------------------------------------------------------------- + +itoken_ptr async_client::connect() throw(exception, security_exception) +{ + connect_options opts; + return connect(opts); +} + +itoken_ptr async_client::connect(connect_options opts) throw(exception, security_exception) +{ + token* ctok = new token(*this); + itoken_ptr tok = itoken_ptr(ctok); + add_token(tok); + + opts.opts_.onSuccess = &token::on_success; + opts.opts_.onFailure = &token::on_failure; + opts.opts_.context = ctok; + + int rc = MQTTAsync_connect(cli_, &opts.opts_); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::connect(connect_options opts, void* userContext, + iaction_listener& cb) throw(exception, security_exception) +{ + token* ctok = new token(*this); + itoken_ptr tok = itoken_ptr(ctok); + add_token(tok); + + tok->set_user_context(userContext); + tok->set_action_callback(cb); + + opts.opts_.onSuccess = &token::on_success; + opts.opts_.onFailure = &token::on_failure; + opts.opts_.context = ctok; + + int rc = MQTTAsync_connect(cli_, &opts.opts_); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::connect(void* userContext, iaction_listener& cb) + throw(exception, security_exception) +{ + connect_options opts; + opts.opts_.keepAliveInterval = 30; + opts.opts_.cleansession = 1; + return connect(opts, userContext, cb); +} + +itoken_ptr async_client::disconnect(long timeout) throw(exception) +{ + token* ctok = new token(*this); + itoken_ptr tok = itoken_ptr(ctok); + add_token(tok); + + MQTTAsync_disconnectOptions disconnOpts( MQTTAsync_disconnectOptions_initializer ); + + // TODO: Check timeout range? + disconnOpts.timeout = int(timeout); + disconnOpts.onSuccess = &token::on_success; + disconnOpts.onFailure = &token::on_failure; + disconnOpts.context = ctok; + + int rc = MQTTAsync_disconnect(cli_, &disconnOpts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::disconnect(long timeout, void* userContext, iaction_listener& cb) + throw(exception) +{ + token* ctok = new token(*this); + itoken_ptr tok = itoken_ptr(ctok); + add_token(tok); + + tok->set_user_context(userContext); + tok->set_action_callback(cb); + + + MQTTAsync_disconnectOptions disconnOpts( MQTTAsync_disconnectOptions_initializer ); + + // TODO: Check timeout range? + disconnOpts.timeout = int(timeout); + disconnOpts.onSuccess = &token::on_success; + disconnOpts.onFailure = &token::on_failure; + disconnOpts.context = ctok; + + int rc = MQTTAsync_disconnect(cli_, &disconnOpts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +idelivery_token_ptr async_client::get_pending_delivery_token(int msgID) const +{ + if (msgID > 0) { + guard g(lock_); + for (const auto& t : pendingDeliveryTokens_) { + if (t->get_message_id() == msgID) + return t; + } + } + return idelivery_token_ptr(); +} + +std::vector async_client::get_pending_delivery_tokens() const +{ + std::vector toks; + guard g(lock_); + for (const auto& t : pendingDeliveryTokens_) + toks.push_back(t); + return toks; +} + +idelivery_token_ptr async_client::publish(const std::string& topic, const void* payload, + size_t n, int qos, bool retained) + throw(exception) +{ + message_ptr msg = std::make_shared(payload, n); + msg->set_qos(qos); + msg->set_retained(retained); + + return publish(topic, msg); +} + +idelivery_token_ptr async_client::publish(const std::string& topic, + const void* payload, size_t n, + int qos, bool retained, void* userContext, + iaction_listener& cb) + throw(exception) +{ + message_ptr msg = std::make_shared(payload, n); + msg->set_qos(qos); + msg->set_retained(retained); + + return publish(topic, msg, userContext, cb); +} + +idelivery_token_ptr async_client::publish(const std::string& topic, message_ptr msg) + throw(exception) +{ + delivery_token* dtok = new delivery_token(*this, topic); + idelivery_token_ptr tok = idelivery_token_ptr(dtok); + + dtok->set_message(msg); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &delivery_token::on_success; + opts.onFailure = &delivery_token::on_failure; + opts.context = dtok; + + int rc = MQTTAsync_sendMessage(cli_, (char*) topic.c_str(), &(msg->msg_), &opts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +idelivery_token_ptr async_client::publish(const std::string& topic, message_ptr msg, + void* userContext, iaction_listener& cb) + throw(exception) +{ + delivery_token* dtok = new delivery_token(*this, topic); + idelivery_token_ptr tok = idelivery_token_ptr(dtok); + + dtok->set_message(msg); + tok->set_user_context(userContext); + tok->set_action_callback(cb); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &delivery_token::on_success; + opts.onFailure = &delivery_token::on_failure; + opts.context = dtok; + + int rc = MQTTAsync_sendMessage(cli_, (char*) topic.c_str(), &(msg->msg_), &opts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +void async_client::set_callback(callback& cb) throw(exception) +{ + guard g(lock_); + userCallback_ = &cb; + + int rc = MQTTAsync_setCallbacks(cli_, this, + &async_client::on_connection_lost, + &async_client::on_message_arrived, + nullptr /*&async_client::on_delivery_complete*/); + + if (rc != MQTTASYNC_SUCCESS) + throw exception(rc); +} + +itoken_ptr async_client::subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos) + throw(std::invalid_argument,exception) + +{ + if (topicFilters.size() != qos.size()) + throw std::invalid_argument("Collection sizes don't match"); + + std::vector filts = alloc_topic_filters(topicFilters); + + token* stok = new token(*this, topicFilters); + itoken_ptr tok = itoken_ptr(stok); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_subscribeMany(cli_, (int) topicFilters.size(), + (char**) &filts[0], (int*) &qos[0], &opts); + + free_topic_filters(filts); + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos, + void* userContext, iaction_listener& cb) + throw(std::invalid_argument,exception) +{ + if (topicFilters.size() != qos.size()) + throw std::invalid_argument("Collection sizes don't match"); + + std::vector filts = alloc_topic_filters(topicFilters); + + // No exceptions till C-strings are deleted! + + token* stok = new token(*this, topicFilters); + itoken_ptr tok = itoken_ptr(stok); + + tok->set_user_context(userContext); + tok->set_action_callback(cb); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_subscribeMany(cli_, (int) topicFilters.size(), + (char**) &filts[0], (int*) &qos[0], &opts); + + free_topic_filters(filts); + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::subscribe(const std::string& topicFilter, int qos) + throw(exception) +{ + token* stok = new token(*this, topicFilter); + itoken_ptr tok = itoken_ptr(stok); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_subscribe(cli_, (char*) topicFilter.c_str(), qos, &opts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::subscribe(const std::string& topicFilter, int qos, + void* userContext, iaction_listener& cb) + throw(exception) +{ + token* stok = new token(*this, topicFilter); + itoken_ptr tok = itoken_ptr(stok); + + tok->set_user_context(userContext); + tok->set_action_callback(cb); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_subscribe(cli_, (char*) topicFilter.c_str(), qos, &opts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::unsubscribe(const std::string& topicFilter) + throw(exception) +{ + token* stok = new token(*this, topicFilter); + itoken_ptr tok = itoken_ptr(stok); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_unsubscribe(cli_, (char*) topicFilter.c_str(), &opts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::unsubscribe(const topic_filter_collection& topicFilters) + throw(exception) +{ + size_t n = topicFilters.size(); + std::vector filts = alloc_topic_filters(topicFilters); + + token* stok = new token(*this, topicFilters); + itoken_ptr tok = itoken_ptr(stok); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_unsubscribeMany(cli_, (int) n, (char**) &filts[0], &opts); + + free_topic_filters(filts); + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::unsubscribe(const topic_filter_collection& topicFilters, + void* userContext, iaction_listener& cb) + throw(exception) +{ + size_t n = topicFilters.size(); + std::vector filts = alloc_topic_filters(topicFilters); + + token* stok = new token(*this, topicFilters); + itoken_ptr tok = itoken_ptr(stok); + + tok->set_user_context(userContext); + tok->set_action_callback(cb); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_unsubscribeMany(cli_, (int) n, (char**) &filts[0], &opts); + + free_topic_filters(filts); + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +itoken_ptr async_client::unsubscribe(const std::string& topicFilter, + void* userContext, iaction_listener& cb) + throw(exception) +{ + token* stok = new token(*this, topicFilter); + itoken_ptr tok = itoken_ptr(stok); + + tok->set_user_context(userContext); + tok->set_action_callback(cb); + add_token(tok); + + MQTTAsync_responseOptions opts = MQTTAsync_responseOptions_initializer; + opts.onSuccess = &token::on_success; + opts.onFailure = &token::on_failure; + opts.context = stok; + + int rc = MQTTAsync_unsubscribe(cli_, (char*) topicFilter.c_str(), &opts); + + if (rc != MQTTASYNC_SUCCESS) { + remove_token(tok); + throw exception(rc); + } + + return tok; +} + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + diff --git a/src/client.cpp b/src/client.cpp new file mode 100644 index 0000000..f726019 --- /dev/null +++ b/src/client.cpp @@ -0,0 +1,173 @@ +// client.cpp +// Implementation of the client class for the mqtt C++ client library. + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + + +#include "mqtt/client.h" + +namespace mqtt { + +const int client::DFLT_QOS = 1; + +///////////////////////////////////////////////////////////////////////////// + +client::client(const std::string& serverURI, const std::string& clientId) + : cli_(serverURI, clientId), timeout_(-1) +{ +} + +client::client(const std::string& serverURI, const std::string& clientId, + const std::string& persistDir) + : cli_(serverURI, clientId, persistDir), timeout_(-1) +{ +} + +client::client(const std::string& serverURI, const std::string& clientId, + iclient_persistence* persistence) + : cli_(serverURI, clientId, persistence), timeout_(-1) +{ +} + +void client::close() +{ + // TODO: What? +} + +void client::connect() +{ + cli_.connect()->wait_for_completion(timeout_); +} + +void client::connect(connect_options opts) +{ + cli_.connect(opts)->wait_for_completion(timeout_); +} + +void client::disconnect() +{ + cli_.disconnect()->wait_for_completion(timeout_); +} + +void client::disconnect(long timeout) +{ + cli_.disconnect(timeout)->wait_for_completion(timeout_); +} + +//std::string client::generate_client_id() +//{ +//} + +std::string client::get_client_id() const +{ + return cli_.get_client_id(); +} + +std::string client::get_server_uri() const +{ + return cli_.get_server_uri(); +} + +//Debug getDebug() +//Return a debug object that can be used to help solve problems. + +std::vector client::get_pending_delivery_tokens() const +{ + return cli_.get_pending_delivery_tokens(); +} + +long client::get_time_to_wait() const +{ + return timeout_; +} + +topic client::get_topic(const std::string& top) +{ + return topic(top, cli_); +} + +bool client::is_connected() const +{ + return cli_.is_connected(); +} + +void client::publish(const std::string& top, const void* payload, size_t n, + int qos, bool retained) +{ + cli_.publish(top, payload, n, qos, retained)->wait_for_completion(timeout_); +} + +void client::publish(const std::string& top, message_ptr msg) +{ + cli_.publish(top, msg)->wait_for_completion(timeout_); +} + +void client::set_callback(callback& cb) +{ + cli_.set_callback(cb); +} + +void client::set_time_to_wait(int timeout) +{ + timeout_ = timeout; +} + +void client::subscribe(const std::string& topicFilter) +{ + cli_.subscribe(topicFilter, DFLT_QOS)->wait_for_completion(timeout_); +} + +void client::subscribe(const topic_filter_collection& topicFilters) +{ + qos_collection qos; + for (size_t i=0; iwait_for_completion(timeout_); +} + +void client::subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos) +{ + cli_.subscribe(topicFilters, qos)->wait_for_completion(timeout_); +} + +void client::subscribe(const std::string& topicFilter, int qos) +{ + cli_.subscribe(topicFilter, qos)->wait_for_completion(timeout_); +} + +void client::unsubscribe(const std::string& topicFilter) +{ + cli_.unsubscribe(topicFilter)->wait_for_completion(timeout_); +} + +void client::unsubscribe(const topic_filter_collection& topicFilters) +{ + qos_collection qos; + for (size_t i=0; iwait_for_completion(timeout_); +} + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + + + diff --git a/src/iclient_persistence.cpp b/src/iclient_persistence.cpp new file mode 100644 index 0000000..755c561 --- /dev/null +++ b/src/iclient_persistence.cpp @@ -0,0 +1,226 @@ +// iclient_persistence.cpp + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#include "mqtt/iclient_persistence.h" +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +// This is an internal class for wrapping a buffer into a persistable type. +// Note that it does not copy the buffer or take possession of it, and thus +// is only useful for a subset of circumstances where the buffer is +// guaranteed to live longer than the wrapper object, and performance is +// important. + +class persistence_wrapper : virtual public ipersistable +{ + const uint8_t* hdr_; + const size_t hdrlen_; + const uint8_t* payload_; + const size_t payloadlen_; + +public: + persistence_wrapper(const void* payload, size_t payloadlen) + : hdr_(nullptr), hdrlen_(0), + payload_(static_cast(payload)), payloadlen_(payloadlen) + {} + persistence_wrapper(const void* hdr, size_t hdrlen, + const void* payload, size_t payloadlen) + : hdr_(static_cast(hdr)), hdrlen_(hdrlen), + payload_(static_cast(payload)), payloadlen_(payloadlen) + {} + + virtual const uint8_t* get_header_bytes() const { return hdr_; } + virtual size_t get_header_length() const { return hdrlen_; } + virtual size_t get_header_offset() const { return 0; } + + virtual const uint8_t* get_payload_bytes() const { return payload_; } + virtual size_t get_payload_length() const { return payloadlen_; } + virtual size_t get_payload_offset() const { return 0; } + + virtual std::vector get_header_byte_arr() const { + return std::vector(hdr_, hdr_+hdrlen_); + } + virtual std::vector get_payload_byte_arr() const { + return std::vector(payload_, payload_+payloadlen_); + } +}; + +///////////////////////////////////////////////////////////////////////////// +// Functions to transition C persistence calls to the C++ persistence object. + +// Upon the call to persistence_open(), the 'context' has the address of the +// C++ persistence object, which is reassigned to the 'handle'. Subsequent +// calls have the object address as the handle. + +int iclient_persistence::persistence_open(void** handle, char* clientID, + char* serverURI, void* context) +{ + try { + if (context) { + static_cast(context)->open(clientID, serverURI); + *handle = context; + return 0; + } + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +int iclient_persistence::persistence_close(void* handle) +{ + try { + if (handle) { + static_cast(handle)->close(); + return 0; + } + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +int iclient_persistence::persistence_put(void* handle, char* key, int bufcount, + char* buffers[], int buflens[]) +{ + try { + if (handle && bufcount > 0) { + ipersistable_ptr p; + if (bufcount == 1) + p = std::make_shared(buffers[0], buflens[0]); + else if (bufcount == 2) + p = std::make_shared(buffers[0], buflens[0], + buffers[1], buflens[1]); + else { + std::string buf; + for (int i=0; i 0) + buf.append(buffers[i], buflens[i]); + } + if (buf.empty()) // No data! + return MQTTCLIENT_PERSISTENCE_ERROR; + p = std::make_shared(&buf[0], buf.size()); + } + static_cast(handle)->put(key, p); + return 0; + } + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +int iclient_persistence::persistence_get(void* handle, char* key, + char** buffer, int* buflen) +{ + try { + if (handle) { + ipersistable_ptr p = static_cast(handle)->get(key); + + size_t hdrlen = p->get_header_length(), + payloadlen = p->get_payload_length(); + + if (!p->get_header_bytes()) hdrlen = 0; + if (!p->get_payload_bytes()) payloadlen = 0; + + // TODO: Check range + *buflen = (int) (hdrlen + payloadlen); + char* buf = (char*) malloc(*buflen); + std::memcpy(buf, p->get_header_bytes(), hdrlen); + std::memcpy(buf+hdrlen, p->get_payload_bytes(), payloadlen); + *buffer = buf; + return 0; + } + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +int iclient_persistence::persistence_remove(void* handle, char* key) +{ + try { + if (handle) { + static_cast(handle)->remove(key); + return 0; + } + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +int iclient_persistence::persistence_keys(void* handle, char*** keys, int* nkeys) +{ + try { + if (handle && keys && nkeys) { + std::vector k( + static_cast(handle)->keys()); + size_t n = k.size(); + *nkeys = n; // TODO: Check range + if (n == 0) + *keys = nullptr; + else { + *keys = (char**) malloc(n*sizeof(char*)); + for (size_t i=0; i(handle)->clear(); + return 0; + } + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +int iclient_persistence::persistence_containskey(void* handle, char* key) +{ + try { + if (handle && + static_cast(handle)->contains_key(key)) + return 0; + } + catch (...) {} + + return MQTTCLIENT_PERSISTENCE_ERROR; +} + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + diff --git a/src/message.cpp b/src/message.cpp new file mode 100644 index 0000000..50ebc1a --- /dev/null +++ b/src/message.cpp @@ -0,0 +1,133 @@ +// message.cpp + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + + +#include "mqtt/message.h" +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +message::message() : msg_(MQTTAsync_message_initializer) +{ +} + +message::message(const void* payload, size_t len) + : msg_(MQTTAsync_message_initializer) +{ + copy_payload(payload, len); +} + +message::message(const std::string& payload) + : msg_(MQTTAsync_message_initializer) +{ + copy_payload(payload.data(), payload.length()); +} + +message::message(const MQTTAsync_message& msg) : msg_(msg) +{ + copy_payload(msg.payload, msg.payloadlen); +} + +message::message(const message& other) : msg_(other.msg_) +{ + copy_payload(other.msg_.payload, other.msg_.payloadlen); +} + +message::message(message&& other) : msg_(other.msg_) +{ + other.msg_.payload = nullptr; + other.msg_.payloadlen = 0; +} + +message::~message() +{ + clear_payload(); +} + +void message::copy_payload(const void* payload, size_t len) +{ + if (!payload || len == 0) { + msg_.payload = nullptr; + msg_.payloadlen = 0; + } + else { + msg_.payloadlen = len; + msg_.payload = new char[len]; + std::memcpy(msg_.payload, payload, len); + } +} + +message& message::operator=(const message& rhs) +{ + if (&rhs == this) + return *this; + + delete[] (char*) msg_.payload; + msg_ = rhs.msg_; + copy_payload(rhs.msg_.payload, rhs.msg_.payloadlen); + return *this; +} + +message& message::operator=(message&& rhs) +{ + if (&rhs == this) + return *this; + + delete[] (char*) msg_.payload; + msg_ = rhs.msg_; + + rhs.msg_.payload = nullptr; + rhs.msg_.payloadlen = 0; + + return *this; +} + +void message::clear_payload() +{ + delete[] (char*) msg_.payload; + msg_.payload = nullptr; + msg_.payloadlen = 0; +} + +std::string message::get_payload() const +{ + if (!msg_.payload || msg_.payloadlen == 0) + return std::string(); + + const char *p = (const char *) msg_.payload; + return std::string(p, p+msg_.payloadlen); +} + +void message::set_payload(const void* payload, size_t len) +{ + delete[] (char*) msg_.payload; + copy_payload(payload, len); +} + +void message::set_payload(const std::string& payload) +{ + set_payload(payload.data(), payload.length()); +} + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + diff --git a/src/mqtt/async_client.h b/src/mqtt/async_client.h new file mode 100644 index 0000000..3d6df96 --- /dev/null +++ b/src/mqtt/async_client.h @@ -0,0 +1,650 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file async_client.h +/// Declaration of MQTT async_client class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_async_client_h +#define __mqtt_async_client_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/token.h" +#include "mqtt/delivery_token.h" +#include "mqtt/iclient_persistence.h" +#include "mqtt/iaction_listener.h" +#include "mqtt/connect_options.h" +#include "mqtt/exception.h" +#include "mqtt/message.h" +#include "mqtt/callback.h" +#include +#include +#include +#include +#include + +namespace mqtt { + +const uint32_t VERSION = 0x00010000; +const std::string VERSION_STR("mqttpp v. 0.1"), + COPYRIGHT("Copyright (c) 2013 Frank Pagliughi"); + +///////////////////////////////////////////////////////////////////////////// + +/** + * Enables an application to communicate with an MQTT server using + * non-blocking methods. + * + * It provides applications a simple programming interface to all features + * of the MQTT version 3.1 specification including: + * + * @li connect + * @li publish + * @li subscribe + * @li unsubscribe + * @li disconnect + */ +class iasync_client +{ + friend class token; + virtual void remove_token(itoken* tok) =0; + +public: + /** Type for a collection of filters */ + typedef std::vector topic_filter_collection; + /** Type for a collection of QOS values */ + typedef std::vector qos_collection; + + /** + * Virtual destructor + */ + virtual ~iasync_client() {} + /** + * Connects to an MQTT server using the default options. + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect() throw(exception, security_exception) =0; + /** + * Connects to an MQTT server using the provided connect options. + * @param options + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect(connect_options options) + throw(exception, security_exception) =0; + /** + * Connects to an MQTT server using the specified options. + * + * @param options + * + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect(connect_options options, void* userContext, + iaction_listener& cb) throw(exception, security_exception) =0; + /** + * + * @param userContext + * @param callback + * + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect(void* userContext, iaction_listener& cb) + throw(exception, security_exception) =0; + /** + * Disconnects from the server. + * @return itoken_ptr + */ + virtual itoken_ptr disconnect() throw(exception) =0; + /** + * Disconnects from the server. + * + * @param quiesceTimeout + * @return itoken_ptr + */ + virtual itoken_ptr disconnect(long quiesceTimeout) throw(exception) =0; + /** + * Disconnects from the server. + * + * @param quiesceTimeout + * @param userContext + * @param callback + * @return itoken_ptr + */ + virtual itoken_ptr disconnect(long quiesceTimeout, void* userContext, iaction_listener& cb) + throw(exception) =0; + /** + * Disconnects from the server. + * @param userContext + * @param callback + * @return itoken_ptr + */ + virtual itoken_ptr disconnect(void* userContext, iaction_listener& cb) + throw(exception) =0; + /** + * Returns the delivery token for the specified message ID. + * @return idelivery_token + */ + virtual idelivery_token_ptr get_pending_delivery_token(int msgID) const =0; + /** + * Returns the delivery tokens for any outstanding publish operations. + * @return idelivery_token[] + */ + virtual std::vector get_pending_delivery_tokens() const =0; + /** + * Returns the client ID used by this client. + * @return std::string + */ + virtual std::string get_client_id() const =0; + /** + * Returns the address of the server used by this client. + */ + virtual std::string get_server_uri() const =0; + /** + * Determines if this client is currently connected to the server. + */ + virtual bool is_connected() const =0; + /** + * Publishes a message to a topic on the server + * @param topic + * @param payload + * @param qos + * @param retained + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, const void* payload, + size_t n, int qos, bool retained) + throw(exception) =0; + /** + * Publishes a message to a topic on the server + * @param topic + * @param payload + * @param qos + * @param retained + * @param userContext + * @param cb + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, + const void* payload, size_t n, + int qos, bool retained, void* userContext, + iaction_listener& cb) throw(exception) =0; + /** + * Publishes a message to a topic on the server Takes an Message + * message and delivers it to the server at the requested quality of + * service. + * + * @param topic + * @param message + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, message_ptr msg) + throw(exception) =0; + /** + * Publishes a message to a topic on the server. + * @param topic + * @param message + * @param userContext + * @param callback + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, message_ptr msg, + void* userContext, iaction_listener& cb) + throw(exception) =0; + /** + * Sets a callback listener to use for events that happen + * asynchronously. + * @param callback + */ + virtual void set_callback(callback& cb) throw(exception) =0; + /** + * Subscribe to multiple topics, each of which may include wildcards. + * @param topicFilters + * @param qos + * + * @return bool + */ + virtual itoken_ptr subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos) + throw(std::invalid_argument,exception) =0; + /** + * Subscribes to multiple topics, each of which may include wildcards. + * @param topicFilters + * @param qos + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos, + void* userContext, iaction_listener& callback) + throw(std::invalid_argument,exception) =0; + /** + * Subscribe to a topic, which may include wildcards. + * @param topicFilter + * @param qos + * + * @return bool + */ + virtual itoken_ptr subscribe(const std::string& topicFilter, int qos) + throw(exception) =0; + /** + * Subscribe to a topic, which may include wildcards. + * @param topicFilter + * @param qos + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr subscribe(const std::string& topicFilter, int qos, + void* userContext, iaction_listener& callback) + throw(exception) =0; + /** + * Requests the server unsubscribe the client from a topic. + * @param topicFilter + * + * @return bool + */ + virtual itoken_ptr unsubscribe(const std::string& topicFilter) throw(exception) =0; + /** + * Requests the server unsubscribe the client from one or more topics. + * @param string + * @return bool + */ + virtual itoken_ptr unsubscribe(const topic_filter_collection& topicFilters) + throw(exception) =0; + /** + * Requests the server unsubscribe the client from one or more topics. + * @param string + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr unsubscribe(const topic_filter_collection& topicFilters, + void* userContext, iaction_listener& callback) + throw(exception) =0; + /** + * Requests the server unsubscribe the client from a topics. + * @param topicFilter + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr unsubscribe(const std::string& topicFilter, + void* userContext, iaction_listener& callback) + throw(exception) =0; +}; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Lightweight client for talking to an MQTT server using non-blocking + * methods that allow an operation to run in the background. + */ +class async_client : public virtual iasync_client +{ +public: + /** Pointer type for this object */ + typedef std::shared_ptr ptr_t; + +private: + /** Lock guard type for this class */ + typedef std::unique_lock guard; + + /** Object monitor mutex */ + mutable std::mutex lock_; + /** The underlying C-lib client. */ + MQTTAsync cli_; + /** The server URI string. */ + std::string serverURI_; + /** The client ID string that we provided to the server. */ + std::string clientId_; + /** A user persistence wrapper (if any) */ + MQTTClient_persistence* persist_; + /** Callback supplied by the user (if any) */ + callback* userCallback_; + /** A list of tokens that are in play */ + std::list pendingTokens_; + /** A list of delivery tokens that are in play */ + std::list pendingDeliveryTokens_; + + static void on_connection_lost(void *context, char *cause); + static int on_message_arrived(void* context, char* topicName, int topicLen, + MQTTAsync_message* msg); + static void on_delivery_complete(void* context, MQTTAsync_token tok); + + /** Manage internal list of active tokens */ + friend class token; + virtual void add_token(itoken_ptr tok); + virtual void add_token(idelivery_token_ptr tok); + virtual void remove_token(itoken* tok); + virtual void remove_token(itoken_ptr tok) { remove_token(tok.get()); } + void remove_token(idelivery_token_ptr tok) { remove_token(tok.get()); } + + /** Memory management for C-style filter collections */ + std::vector alloc_topic_filters( + const topic_filter_collection& topicFilters); + void free_topic_filters(std::vector& filts); + + /** + * Convenience function to get user callback safely. + * @return callback* + */ + callback* get_callback() const { + guard g(lock_); + return userCallback_; + } + + /** Non-copyable */ + async_client() =delete; + async_client(const async_client&) =delete; + async_client& operator=(const async_client&) =delete; + +public: + /** + * Create an async_client that can be used to communicate with an MQTT + * server. + * This uses file-based persistence in the current working directory. + * @param serverURI + * @param clientId + */ + async_client(const std::string& serverURI, const std::string& clientId); + /** + * Create an async_client that can be used to communicate with an MQTT + * server. + * This uses file-based persistence in the specified directory. + * @param serverURI + * @param clientId + * @param persistDir + */ + async_client(const std::string& serverURI, const std::string& clientId, + const std::string& persistDir); + /** + * Create an async_client that can be used to communicate with an MQTT + * server. + * This allows the caller to specify a user-defined persistance object, + * or use no persistence. + * @param serverURI + * @param clientId + * @param persistence The user persistence structure. If this is null, + * then no persistence is used. + */ + async_client(const std::string& serverURI, const std::string& clientId, + iclient_persistence* persistence); + /** + * Destructor + */ + ~async_client(); + /** + * Connects to an MQTT server using the default options. + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect() throw(exception, security_exception); + /** + * Connects to an MQTT server using the provided connect options. + * @param options + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect(connect_options options) throw(exception, security_exception); + /** + * Connects to an MQTT server using the specified options. + * + * @param options + * + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect(connect_options options, void* userContext, + iaction_listener& cb) throw(exception, security_exception); + /** + * + * @param userContext + * @param callback + * + * @return bool + * @throw exception + * @throw security_exception + */ + virtual itoken_ptr connect(void* userContext, iaction_listener& cb) + throw(exception, security_exception); + /** + * Disconnects from the server. + * @return itoken_ptr + */ + virtual itoken_ptr disconnect() throw(exception) { return disconnect(0L); } + /** + * Disconnects from the server. + * + * @param quiesceTimeout + * @return itoken_ptr + */ + virtual itoken_ptr disconnect(long quiesceTimeout) throw(exception); + /** + * Disconnects from the server. + * + * @param quiesceTimeout + * @param userContext + * @param callback + * @return itoken_ptr + */ + virtual itoken_ptr disconnect(long quiesceTimeout, void* userContext, iaction_listener& cb) + throw(exception); + /** + * Disconnects from the server. + * @param userContext + * @param callback + * @return itoken_ptr + */ + virtual itoken_ptr disconnect(void* userContext, iaction_listener& cb) throw(exception) { + return disconnect(0L, userContext, cb); + } + /** + * Returns the delivery token for the specified message ID. + * @return idelivery_token + */ + virtual idelivery_token_ptr get_pending_delivery_token(int msgID) const; + /** + * Returns the delivery tokens for any outstanding publish operations. + * @return idelivery_token[] + */ + virtual std::vector get_pending_delivery_tokens() const; + /** + * Returns the client ID used by this client. + * @return std::string + */ + virtual std::string get_client_id() const { return clientId_; } + /** + * Returns the address of the server used by this client. + */ + virtual std::string get_server_uri() const { return serverURI_; } + /** + * Determines if this client is currently connected to the server. + */ + virtual bool is_connected() const { return MQTTAsync_isConnected(cli_) != 0; } + /** + * Publishes a message to a topic on the server + * @param topic + * @param payload + * @param qos + * @param retained + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, const void* payload, + size_t n, int qos, bool retained) throw(exception); + /** + * Publishes a message to a topic on the server + * @param topic + * @param payload + * @param qos + * @param retained + * @param userContext + * @param cb + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, + const void* payload, size_t n, + int qos, bool retained, void* userContext, + iaction_listener& cb) throw(exception); + /** + * Publishes a message to a topic on the server Takes an Message + * message and delivers it to the server at the requested quality of + * service. + * + * @param topic + * @param message + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, message_ptr msg) + throw(exception); + /** + * Publishes a message to a topic on the server. + * @param topic + * @param message + * @param userContext + * @param callback + * + * @return idelivery_token + */ + virtual idelivery_token_ptr publish(const std::string& topic, message_ptr msg, + void* userContext, iaction_listener& cb) + throw(exception); + /** + * Sets a callback listener to use for events that happen + * asynchronously. + * @param callback + */ + virtual void set_callback(callback& cb) throw(exception); + /** + * Subscribe to multiple topics, each of which may include wildcards. + * @param topicFilters + * @param qos + * + * @return bool + */ + virtual itoken_ptr subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos) + throw(std::invalid_argument,exception); + /** + * Subscribes to multiple topics, each of which may include wildcards. + * @param topicFilters + * @param qos + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos, + void* userContext, iaction_listener& callback) + throw(std::invalid_argument,exception); + /** + * Subscribe to a topic, which may include wildcards. + * @param topicFilter + * @param qos + * + * @return bool + */ + virtual itoken_ptr subscribe(const std::string& topicFilter, int qos) + throw(exception); + /** + * Subscribe to a topic, which may include wildcards. + * @param topicFilter + * @param qos + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr subscribe(const std::string& topicFilter, int qos, + void* userContext, iaction_listener& callback) + throw(exception); + /** + * Requests the server unsubscribe the client from a topic. + * @param topicFilter + * + * @return bool + */ + virtual itoken_ptr unsubscribe(const std::string& topicFilter) throw(exception); + /** + * Requests the server unsubscribe the client from one or more topics. + * @param string + * @return bool + */ + virtual itoken_ptr unsubscribe(const topic_filter_collection& topicFilters) + throw(exception); + /** + * Requests the server unsubscribe the client from one or more topics. + * @param string + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr unsubscribe(const topic_filter_collection& topicFilters, + void* userContext, iaction_listener& callback) + throw(exception); + /** + * Requests the server unsubscribe the client from a topics. + * @param topicFilter + * @param userContext + * @param callback + * + * @return bool + */ + virtual itoken_ptr unsubscribe(const std::string& topicFilter, + void* userContext, iaction_listener& callback) + throw(exception); +}; + +/** + * Shared pointer to an asynchronous MQTT client object. + */ +typedef async_client::ptr_t async_client_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_async_client_h + diff --git a/src/mqtt/callback.h b/src/mqtt/callback.h new file mode 100644 index 0000000..a2e7f0e --- /dev/null +++ b/src/mqtt/callback.h @@ -0,0 +1,74 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file callback.h +/// Declaration of MQTT callback class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_callback_h +#define __mqtt_callback_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/delivery_token.h" +#include +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism for tracking the completion of an asynchronous + * action. + */ +class callback +{ +public: + typedef std::shared_ptr ptr_t; + /** + * This method is called when the connection to the server is lost. + * @param cause + */ + virtual void connection_lost(const std::string& cause) =0; + /** + * This method is called when a message arrives from the server. + * @param topic + * @param msg + */ + virtual void message_arrived(const std::string& topic, message_ptr msg) =0; + /** + * Called when delivery for a message has been completed, and all + * acknowledgments have been received. + * @param token + */ + virtual void delivery_complete(idelivery_token_ptr tok) =0; +}; + +typedef callback::ptr_t callback_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_callback_h + diff --git a/src/mqtt/client.h b/src/mqtt/client.h new file mode 100644 index 0000000..41a7b13 --- /dev/null +++ b/src/mqtt/client.h @@ -0,0 +1,229 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file client.h +/// Declaration of MQTT client class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_client_h +#define __mqtt_client_h + +//extern "C" { +// #include "MQTTClient.h" +// #include "MQTTClientPersistence.h" +//} + +#include "async_client.h" + +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * Lightweight client for talking to an MQTT server using methods that block + * until an operation completes. + */ +class client +{ + static const int DFLT_QOS; + + //MQTTClient cli_; + + /** + * The actual client + */ + async_client cli_; + /** + * The longest amount of time to wait for an operation (in milliseconds) + */ + int timeout_; + + /** Non-copyable */ + client() =delete; + client(const async_client&) =delete; + client& operator=(const async_client&) =delete; + +public: + /** Smart pointer type for this object */ + typedef std::shared_ptr ptr_t; + /** Type for a collection of filters */ + typedef async_client::topic_filter_collection topic_filter_collection; + /** Type for a collection of QOS values */ + typedef async_client::qos_collection qos_collection; + + /** + * Create a client that can be used to communicate with an MQTT server. + * This uses file-based persistence in the current working directory. + * @param serverURI + * @param clientId + */ + client(const std::string& serverURI, const std::string& clientId); + /** + * Create a client that can be used to communicate with an MQTT server. + * This uses file-based persistence in the specified directory. + * @param serverURI + * @param clientId + * @param persistDir + */ + client(const std::string& serverURI, const std::string& clientId, + const std::string& persistDir); + /** + * Create a client that can be used to communicate with an MQTT server. + * This allows the caller to specify a user-defined persistance object, + * or use no persistence. + * @param serverURI + * @param clientId + * @param persistence The user persistence structure. If this is null, + * then no persistence is used. + */ + client(const std::string& serverURI, const std::string& clientId, + iclient_persistence* persistence); + /** + * Close the client and releases all resource associated with the + * client. + */ + virtual void close(); + /** + * Connects to an MQTT server using the default options. + */ + virtual void connect(); + /** + * Connects to an MQTT server using the specified options. + * @param options + */ + virtual void connect(connect_options options); + /** + * Disconnects from the server. + */ + virtual void disconnect(); + /** + * Disconnects from the server. + */ + virtual void disconnect(long quiesceTimeout); + /** + * Returns a randomly generated client identifier based on the current + * user's login name and the system time. + */ + //static std::string generateClientId(); + /** + * Returns the client ID used by this client. + * @return std::string + */ + virtual std::string get_client_id() const; + + //Debug getDebug() + //Return a debug object that can be used to help solve problems. + + /** + * Returns the delivery tokens for any outstanding publish operations. + */ + virtual std::vector get_pending_delivery_tokens() const; + /** + * Returns the address of the server used by this client, as a URI. + * @return std::string + */ + virtual std::string get_server_uri() const; + /** + * Return the maximum time to wait for an action to complete. + * @return long + */ + virtual long get_time_to_wait() const; + /** + * Get a topic object which can be used to publish messages. + * @param tpc + * @return topic + */ + virtual topic get_topic(const std::string& tpc); + /** + * Determines if this client is currently connected to the server. + * @return bool + */ + virtual bool is_connected() const; + /** + * Publishes a message to a topic on the server and return once it is + * delivered. + * @param topic + * @param payload + * @param n + * @param qos + * @param retained + */ + virtual void publish(const std::string& top, const void* payload, size_t n, + int qos, bool retained); + /** + * Publishes a message to a topic on the server. + * @param tpc + * @param msg + */ + virtual void publish(const std::string& tpc, message_ptr msg); + /** + * Sets the callback listener to use for events that happen + * asynchronously. + * @param callback + */ + virtual void set_callback(callback& cb); + /** + * Set the maximum time to wait for an action to complete + * @param timeToWaitInMillis + */ + virtual void set_time_to_wait(int timeToWaitInMillis); + /** + * Subscribe to a topic, which may include wildcards using a QoS of 1. + * @param topicFilter + */ + virtual void subscribe(const std::string& topicFilter); + /** + * Subscribes to a one or more topics, which may include wildcards using + * a QoS of 1. + */ + virtual void subscribe(const topic_filter_collection& topicFilters); + /** + * Subscribes to multiple topics, each of which may include wildcards. + * @param string + */ + virtual void subscribe(const topic_filter_collection& topicFilters, + const qos_collection& qos); + /** + * Subscribe to a topic, which may include wildcards. + * @param topicFilter + * @param qos + */ + virtual void subscribe(const std::string& topicFilter, int qos); + /** + * Requests the server unsubscribe the client from a topic. + * @param topicFilter + */ + virtual void unsubscribe(const std::string& topicFilter); + /** + * Requests the server unsubscribe the client from one or more topics. + */ + virtual void unsubscribe(const topic_filter_collection& topicFilters); +}; + +typedef client::ptr_t client_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_client_h + diff --git a/src/mqtt/connect_options.h b/src/mqtt/connect_options.h new file mode 100644 index 0000000..ed19885 --- /dev/null +++ b/src/mqtt/connect_options.h @@ -0,0 +1,199 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file connect_options.h +/// Declaration of MQTT connect_options class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_connect_options_h +#define __mqtt_connect_options_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/message.h" +#include "mqtt/topic.h" +#include +#include +#include + +namespace mqtt { + +class async_client; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Holds the set of options that control how the client connects to a + * server. + */ +class connect_options +{ + /** The underlying C connection options */ + MQTTAsync_connectOptions opts_; + + /** The client has special access */ + friend class async_client; + +public: + /** + * Smart/shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + /** + * Constructs a new MqttConnectOptions object using the default values. + */ + connect_options() : opts_( MQTTAsync_connectOptions_initializer ) {} + /** + * Returns the connection timeout value. + * @return int + */ + int get_connection_timeout() const; + + //java.util.Properties getDebug() + + /** + * Returns the "keep alive" interval. + * @return int + */ + int get_keep_alive_interval() const { + return opts_.keepAliveInterval; + } + /** + * Returns the password to use for the connection. + * @return std::string + */ + std::string get_password() const { + return std::string(opts_.password); + } + /** + * Returns the socket factory that will be used when connecting, or null + * if one has not been set. + */ + //javax.net.SocketFactory get_socket_factory(); + /** + * Returns the SSL properties for the connection. + */ + //java.util.Properties get_ssl_properties(); + /** + * Returns the user name to use for the connection. + * @return std::string + */ + std::string get_user_name() const { + return std::string(opts_.username); + } + /** + * Returns the topic to be used for last will and testament (LWT). + * @return std::string + */ + std::string get_will_destination() const; + /** + * Returns the message to be sent as last will and testament (LWT). + * @return MqttMessage + */ + message get_will_message() const; + /** + * Returns whether the server should remember state for the client + * across reconnects. + * @return bool + */ + bool is_clean_session() const { return opts_.cleansession != 0; } + /** + * Sets whether the server should remember state for the client across + * reconnects. + * @param cleanSession + */ + void set_clean_session(bool cleanSession) { + opts_.cleansession = (cleanSession) ? (!0) : 0; + } + /** + * Sets the connection timeout value. + * @param timeout + */ + void set_connection_timeout(int timeout) { + opts_.connectTimeout = timeout; + } + /** + * Sets the "keep alive" interval. + * @param keepAliveInterval + */ + void set_keep_alive_interval(int keepAliveInterval) { + opts_.keepAliveInterval = keepAliveInterval; + } + /** + * Sets the password to use for the connection. + */ + void set_password(const std::string& password); + /** + * Sets the SocketFactory to use. + */ + //void set_socket_factory(javax.net.SocketFactory socketFactory) + /** + * Sets the SSL properties for the connection. + */ + //void set_ssl_properties(java.util.Properties props); + /** + * Sets the user name to use for the connection. + * @param userName + */ + void set_user_name(const std::string& userName); + /** + * Sets the "Last Will and Testament" (LWT) for the connection. + * @param top + * @param payload + * @param n + * @param qos + * @param retained + */ + void set_will(const topic& top, void* payload, size_t n, int qos, bool retained) { + set_will(top.get_name(), payload, n, qos, retained); + } + /** + * Sets the "Last Will and Testament" (LWT) for the connection. + * @param top + * @param payload + * @param n + * @param qos + * @param retained + */ + void set_will(const std::string& top, void* payload, size_t n, int qos, bool retained); + /** + * Sets up the will information, based on the supplied parameters. + * @param top + * @param msg + * @param qos + * @param retained + */ + /*protected*/ void set_will(const std::string& top, message msg, int qos, bool retained); + + std::string to_str() const; +}; + +/** + * Shared pointer to the connection options class. + */ +typedef connect_options::ptr_t connect_options_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_connect_options_h + diff --git a/src/mqtt/delivery_token.h b/src/mqtt/delivery_token.h new file mode 100644 index 0000000..fc52249 --- /dev/null +++ b/src/mqtt/delivery_token.h @@ -0,0 +1,109 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file delivery_token.h +/// Declaration of MQTT delivery_token class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_delivery_token_h +#define __mqtt_delivery_token_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/token.h" +#include "mqtt/message.h" +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism for tracking the delivery of a message. + */ +class idelivery_token : public virtual itoken +{ +public: + typedef std::shared_ptr ptr_t; + /** + * Returns the message associated with this token. + * @return The message associated with this token. + */ + virtual message_ptr get_message() const =0; +}; + +typedef idelivery_token::ptr_t idelivery_token_ptr; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism to track the delivery progress of a message. + * Used to track the the delivery progress of a message when a publish is + * executed in a non-blocking manner (run in the background) action. + */ +class delivery_token : public virtual idelivery_token, + public token +{ + /** The message being tracked. */ + message_ptr msg_; + + /** Client has special access. */ + friend class async_client; + + /** + * Sets the message that this token correspn + * @param msg + */ + void set_message(message_ptr msg) { msg_ = msg; } + +public: + /** + * Smart/shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + + delivery_token(iasync_client& cli) : token(cli) {} + + delivery_token(iasync_client& cli, const std::string& topic) : token(cli, topic) {} + + delivery_token(iasync_client& cli, const std::vector& topics) + : token(cli, topics) {} + + //delivery_token(const std::string& logContext); + + /** + * Returns the message associated with this token. + * @return message + */ + virtual message_ptr get_message() const { return msg_; } +}; + +/** + * Shared pointer to a delivery_token. + */ +typedef delivery_token::ptr_t delivery_token_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_delivery_token_h + diff --git a/src/mqtt/exception.h b/src/mqtt/exception.h new file mode 100644 index 0000000..301c8b8 --- /dev/null +++ b/src/mqtt/exception.h @@ -0,0 +1,109 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file exception.h +/// Declaration of MQTT exception class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_exception_h +#define __mqtt_exception_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include +#include +#include +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism for tracking the completion of an asynchronous + * action. + */ +class exception : public std::runtime_error +{ + int code_; + +public: + explicit exception(int reasonCode) : std::runtime_error("mqtt::exception"), + code_(reasonCode) {} + /** + * Returns the underlying cause of this exception, if available. + */ + //java.lang.Throwable getCause() + /** + * Returns the detail message for this exception. + */ + std::string get_message() const { return std::string(what()); } + /** + * Returns the reason code for this exception. + */ + int get_reason_code() const { return code_; } + /** + * Returns a String representation of this exception. + * @return std::tring + */ + std::string to_str() const { return std::string(what()); } + /** + * Returns an explanatory string for the exception. + * @return const char* + */ + virtual const char* what() const noexcept { + return std::exception::what(); + } +}; + +///////////////////////////////////////////////////////////////////////////// + +/** + * This exception is thrown by the implementor of the persistence interface + * if there is a problem reading or writing persistent data. + */ +class persistence_exception : public exception +{ +public: + // TODO: Define "reason codes" + persistence_exception() : exception(MQTTCLIENT_PERSISTENCE_ERROR) {} + persistence_exception(int reasonCode) : exception(reasonCode) {} +}; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Thrown when a client is not authorized to perform an operation, or if + there is a problem with the security configuration. + */ +class security_exception : public exception +{ +public: + security_exception(int reasonCode) : exception(reasonCode) {} +}; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_token_h + diff --git a/src/mqtt/iaction_listener.h b/src/mqtt/iaction_listener.h new file mode 100644 index 0000000..e54cf1c --- /dev/null +++ b/src/mqtt/iaction_listener.h @@ -0,0 +1,83 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file iaction_listener.h +/// Declaration of MQTT iaction_listener class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_iaction_listener_h +#define __mqtt_iaction_listener_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include +#include +#include + +namespace mqtt { + +class itoken; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism for tracking the completion of an asynchronous + * action. + * + * A listener is registered on a token and that token is associated with + * an action like connect or publish. When used with tokens on the + * async_client the listener will be called back on the MQTT client's + * thread. The listener will be informed if the action succeeds or fails. It + * is important that the listener returns control quickly otherwise the + * operation of the MQTT client will be stalled. + */ +class iaction_listener +{ +public: + /** + * Shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + /** + * Virtual base destructor. + */ + virtual ~iaction_listener() {} + /** + * This method is invoked when an action fails. + * @param asyncActionToken + * @param exc + */ + virtual void on_failure(const itoken& asyncActionToken /*, java.lang.Throwable exc*/) =0; + /** + * This method is invoked when an action has completed successfully. + * @param asyncActionToken + */ + virtual void on_success(const itoken& asyncActionToken) =0; +}; + +typedef iaction_listener::ptr_t iaction_listener_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_iaction_listener_h + diff --git a/src/mqtt/iclient_persistence.h b/src/mqtt/iclient_persistence.h new file mode 100644 index 0000000..1fad4df --- /dev/null +++ b/src/mqtt/iclient_persistence.h @@ -0,0 +1,133 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file iclient_persistence.h +/// Declaration of MQTT iclient_persistence interface +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_iclient_persistence_h +#define __mqtt_iclient_persistence_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/ipersistable.h" +#include +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * Represents a persistent data store, used to store outbound and inbound + * messages while they are in flight, enabling delivery to the QoS + * specified. You can specify an implementation of this interface using + * client::client(string, string, iclient_persistence), which the + * client will use to persist QoS 1 and 2 messages. + * + * If the methods defined throw the MqttPersistenceException then the state + * of the data persisted should remain as prior to the method being called. + * For example, if put(string, persistable) throws an exception at any + * point then the data will be assumed to not be in the persistent store. + * Similarly if remove(string) throws an exception then the data will be + * assumed to still be held in the persistent store. + * + * It is up to the persistence interface to log any exceptions or error + * information which may be required when diagnosing a persistence failure. + */ +class iclient_persistence +{ + friend class iasync_client; + +public: + + /** C-callbacks */ + static int persistence_open(void** handle, char* clientID, char* serverURI, void* context); + static int persistence_close(void* handle); + static int persistence_put(void* handle, char* key, int bufcount, char* buffers[], int buflens[]); + static int persistence_get(void* handle, char* key, char** buffer, int* buflen); + static int persistence_remove(void* handle, char* key); + static int persistence_keys(void* handle, char*** keys, int* nkeys); + static int persistence_clear(void* handle); + static int persistence_containskey(void* handle, char* key); + +public: + /** + * Smart/shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + /** + * Virtual destructor. + */ + virtual ~iclient_persistence() {} + /** + * Initialise the persistent store. + */ + virtual void open(const std::string& clientId, const std::string& serverURI) =0; + /** + * Close the persistent store that was previously opened. + */ + virtual void close() =0; + /** + * Clears persistence, so that it no longer contains any persisted data. + */ + virtual void clear() =0; + /** + * Returns whether or not data is persisted using the specified key. + * @param key + * @return bool + */ + virtual bool contains_key(const std::string& key) =0; + /** + * Gets the specified data out of the persistent store. + * @param key + * @return persistable + */ + virtual ipersistable_ptr get(const std::string& key) const =0; + /** + * Returns an Enumeration over the keys in this persistent data store. + */ + virtual std::vector keys() const =0; + /** + * Puts the specified data into the persistent store. + * @param key + * @param persistable + */ + virtual void put(const std::string& key, ipersistable_ptr persistable) =0; + /** + * Remove the data for the specified key. + * @param key + */ + virtual void remove(const std::string& key) =0; +}; + +/** + * Shared pointer to a persistence client. + */ +typedef std::shared_ptr iclient_persistence_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_iclient_persistence_h + diff --git a/src/mqtt/ipersistable.h b/src/mqtt/ipersistable.h new file mode 100644 index 0000000..51d7624 --- /dev/null +++ b/src/mqtt/ipersistable.h @@ -0,0 +1,140 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file ipersistable.h +/// Declaration of MQTT ipersistable interface. +/// @date May 24, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_ipersistable_h +#define __mqtt_ipersistable_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include +#include +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * Represents an object used to pass data to be persisted across the + * MqttClientPersistence interface. + * + * When data is passed across the interface the header and payload are + * separated, so that unnecessary message copies may be avoided. For + * example, if a 10 MB payload was published it would be inefficient to + * create a byte array a few bytes larger than 10 MB and copy the MQTT + * message header and payload into a contiguous byte array. + * + * When the request to persist data is made a separate byte array and offset + * is passed for the header and payload. Only the data between offset and + * length need be persisted. So for example, a message to be persisted + * consists of a header byte array starting at offset 1 and length 4, plus a + * payload byte array starting at offset 30 and length 40000. There are + * three ways in which the persistence implementation may return data to the + * client on recovery: + * + * @li + * It could return the data as it was passed in originally, with the same + * byte arrays and offsets. + * + * @li + * It could safely just persist and return the bytes from the offset for the + * specified length. For example, return a header byte array with offset 0 + * and length 4, plus a payload byte array with offset 0 and length 40000 + * + * @li + * It could return the header and payload as a contiguous byte array with + * the header bytes preceeding the payload. The contiguous byte array should + * be set as the header byte array, with the payload byte array being null. + * For example, return a single byte array with offset 0 and length 40004. + * This is useful when recovering from a file where the header and payload + * could be written as a contiguous stream of bytes. + */ + +class ipersistable +{ +public: + /** + * Smart/shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + /** + * Virtual destructor + */ + virtual ~ipersistable() {} + /** + * Returns the header bytes in an array. + * @return std::vector + */ + virtual const uint8_t* get_header_bytes() const =0; + /** + * Returns the header bytes in an array. + * @return std::vector + */ + virtual std::vector get_header_byte_arr() const =0; + /** + * Returns the length of the header. + * @return int + */ + virtual size_t get_header_length() const =0; + /** + * Returns the offset of the header within the byte array returned by + * get_header_bytes(). + * @return int + */ + virtual size_t get_header_offset() const =0; + /** + * Returns the payload bytes in an array. + * @return std::vector + */ + virtual const uint8_t* get_payload_bytes() const =0; + /** + * Returns the payload bytes in an array. + * @return std::vector + */ + virtual std::vector get_payload_byte_arr() const =0; + /** + * Returns the length of the payload. + * @return int + */ + virtual size_t get_payload_length() const =0; + /** + * Returns the offset of the payload within the byte array returned by + * get_payload_bytes(). + * + * @return int + */ + virtual size_t get_payload_offset() const =0; +}; + +typedef ipersistable::ptr_t ipersistable_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_ipersistable_h + + diff --git a/src/mqtt/message.h b/src/mqtt/message.h new file mode 100644 index 0000000..7653619 --- /dev/null +++ b/src/mqtt/message.h @@ -0,0 +1,183 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file message.h +/// Declaration of MQTT message class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_message_h +#define __mqtt_message_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +/** + * An MQTT message holds the application payload and options specifying how + * the message is to be delivered The message includes a "payload" (the body + * of the message) represented as a byte array. + */ +class message +{ + /** The underlying C message struct */ + MQTTAsync_message msg_; + + /** The client has special access. */ + friend class async_client; + + /** + * Set the dup flag in the underlying message + * @param dup + */ + void set_duplicate(bool dup) { msg_.dup = (dup) ? (!0) : 0; } + /** + * Copies the specified payload into this object. + * @param payload + * @param len + */ + void copy_payload(const void* payload, size_t len); + +public: + /** + * Smart/shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + /** + * Constructs a message with an empty payload, and all other values set + * to defaults. + */ + message(); + /** + * Constructs a message with the specified array as a payload, and all + * other values set to defaults. + */ + message(const void* payload, size_t len); + /** + * Constructs a message with the specified string as a payload, and + * all other values set to defaults. + */ + message(const std::string& payload); + /** + * Constructs a message as a copy of the message structure. + */ + message(const MQTTAsync_message& msg); + /** + * Constructs a message as a copy of the other message. + */ + message(const message& other); + /** + * Moves the other message to this one. + */ + message(message&& other); + /** + * Destroys a message and frees all associated resources. + */ + ~message(); + /** + * Copies another message to this one. + * @param rhs The other message. + * @return A reference to this message. + */ + message& operator=(const message& rhs); + /** + * Moves another message to this one. + * @param rhs The other message. + * @return A reference to this message. + */ + message& operator=(message&& rhs); + /** + * Clears the payload, resetting it to be empty. + */ + void clear_payload(); + /** + * Gets the payload + */ + std::string get_payload() const; + /** + * Returns the quality of service for this message. + * @return The quality of service for this message. + */ + int get_qos() const { return msg_.qos; } + /** + * Returns whether or not this message might be a duplicate of one which + * has already been received. + * @return bool + */ + bool is_duplicate() const { return msg_.dup != 0; } + /** + * Returns whether or not this message should be/was retained by the + * server. + * @return bool + */ + bool is_retained() const { return msg_.retained != 0; } + /** + * Sets the payload of this message to be the specified byte array. + */ + void set_payload(const void* payload, size_t n); + /** + * Sets the payload of this message to be the specified string. + */ + void set_payload(const std::string& payload); + /** + * Sets the quality of service for this message. + * + * @param qos + */ + void set_qos(int qos) throw(std::invalid_argument) { + validate_qos(qos); + msg_.qos = qos; + } + /** + * Whether or not the publish message should be retained by the + * messaging engine. + * @param retained + */ + void set_retained(bool retained) { msg_.retained = (retained) ? (!0) : 0; } + /** + * Returns a string representation of this messages payload. + * @return std::string + */ + std::string to_str() const { return get_payload(); } + /** + * Determines if the QOS value is a valid one. + * @param qos The QOS value. + * @throw std::invalid_argument If the qos value is invalid. + */ + static void validate_qos(int qos) throw(std::invalid_argument) { + if (qos < 0 || qos > 2) + throw std::invalid_argument("QOS invalid"); + } +}; + +typedef message::ptr_t message_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_message_h + diff --git a/src/mqtt/token.h b/src/mqtt/token.h new file mode 100644 index 0000000..b79c9bf --- /dev/null +++ b/src/mqtt/token.h @@ -0,0 +1,331 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file token.h +/// Declaration of MQTT token class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_token_h +#define __mqtt_token_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/iaction_listener.h" +#include "mqtt/exception.h" +#include +#include +#include +#include +#include +#include +#include + +namespace mqtt { + +class iasync_client; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism for tracking the completion of an asynchronous task. + */ +class itoken +{ +public: + typedef std::shared_ptr ptr_t; + /** + * Virtual base destructor. + */ + virtual ~itoken() {} + /** + * Return the async listener for this token. + * @return iaction_listener + */ + virtual iaction_listener* get_action_callback() const =0; + /** + * Returns the MQTT client that is responsible for processing the + * asynchronous action. + * @return iasync_client + */ + virtual iasync_client* get_client() const =0; + /** + * Returns an exception providing more detail if an operation failed. + * @return Exception + */ + //virtual exception get_exception() =0; + /** + * Returns the message ID of the message that is associated with the + * token. + * @return int + */ + virtual int get_message_id() const =0; + /** + * Returns the topic string(s) for the action being tracked by this + * token. + * @return std::vector + */ + virtual const std::vector& get_topics() const =0; + /** + * Retrieve the context associated with an action. + * @return void* + */ + virtual void* get_user_context() const =0; + /** + * Returns whether or not the action has finished. + * @return bool + */ + virtual bool is_complete() const =0; + /** + * Register a listener to be notified when an action completes. + * @param listener + */ + virtual void set_action_callback(iaction_listener& listener) =0; + /** + * Store some context associated with an action. + * @param userContext + */ + virtual void set_user_context(void* userContext) =0; + /** + * Blocks the current thread until the action this token is associated + * with has completed. + */ + virtual void wait_for_completion() =0; + /** + * Blocks the current thread until the action this token is associated + * with has completed. + * @param timeout + */ + virtual void wait_for_completion(long timeout) =0; +}; + +typedef itoken::ptr_t itoken_ptr; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Provides a mechanism for tracking the completion of an asynchronous + * action. + */ +class token : public virtual itoken +{ + /** Lock guard type for this class. */ + typedef std::unique_lock guard; + + /** Object monitor mutex. */ + mutable std::mutex lock_; + /** Condition variable signals when the action completes */ + mutable std::condition_variable cond_; + /** The underlying C token. Note that this is just an integer */ + MQTTAsync_token tok_; + /** The topic string(s) for the action being tracked by this token */ + std::vector topics_; + /** The MQTT client that is processing this action */ + iasync_client* cli_; + /** User supplied context */ + void* userContext_; + /** + * User supplied listener. + * Note that the user listener fires after the action is marked + * complete, but before the token is signaled. + */ + iaction_listener* listener_; + /** Whether the action has yet to complete */ + bool complete_; + /** The action success/failure code */ + int rc_; + + /** Client has special access for full initialization */ + friend class async_client; + + void set_topics(const std::string& top) { + topics_.clear(); + topics_.push_back(top); + } + void set_topics(const std::vector& top) { + topics_ = top; + } + + /** + * C-style callback for success. + * This simply passes the call on to the proper token object for + * processing. + * @param tokObj The token object to process the call. Note that this is + * @em not the user-supplied context pointer. That is + * kept in the object itself. + * @param rsp The success response. + */ + static void on_success(void* tokObj, MQTTAsync_successData* rsp); + /** + * C-style callback for failure. + * This simply passes the call on to the proper token object for + * processing. + * @param tokObj The token object to process the call. Note that this is + * @em not the user-supplied context pointer. That is + * kept in the object itself. + * @param rsp The failure response. + */ + static void on_failure(void* tokObj, MQTTAsync_failureData* rsp); + /** + * Internal handler for the success callback. + * @param rsp The success response. + */ + void on_success(MQTTAsync_successData* rsp); + /** + * Internal handler for the failure callback. + * @param rsp The failure response. + */ + void on_failure(MQTTAsync_failureData* rsp); + +public: + typedef std::shared_ptr ptr_t; + /** + * Constructs a token object. + * @param cli + */ + token(iasync_client& cli); + /** + * Constructs a token object. + * @param tok + */ + token(iasync_client& cli, MQTTAsync_token tok); + /** + * Constructs a token object. + * @param cli + */ + token(iasync_client& cli, const std::string& topic); + /** + * Constructs a token object. + * @param cli + */ + token(iasync_client& cli, const std::vector& topics); + + //token(const std::string& logContext); + + /** + * Return the async listener for this token. + * @return iaction_listener + */ + virtual iaction_listener* get_action_callback() const { + // TODO: Guard? + return listener_; + } + /** + * Returns the MQTT client that is responsible for processing the + * asynchronous action. + * @return iasync_client + */ + virtual iasync_client* get_client() const { + return (iasync_client*) cli_; + } + /** + * Returns an exception providing more detail if an operation failed. + * @return Exception + */ + //virtual exception get_exception(); + /** + * Returns the message ID of the message that is associated with the + * token. + * @return int + */ + virtual int get_message_id() const { return int(tok_); } + /** + * Returns the topic string(s) for the action being tracked by this + * token. + */ + virtual const std::vector& get_topics() const { + return topics_; + } + /** + * Retrieve the context associated with an action. + */ + virtual void* get_user_context() const { + guard g(lock_); + return userContext_; + } + /** + * Returns whether or not the action has finished. + * @return bool + */ + virtual bool is_complete() const { return complete_; } + /** + * Register a listener to be notified when an action completes. + * @param listener + */ + virtual void set_action_callback(iaction_listener& listener) { + guard g(lock_); + listener_ = &listener; + } + /** + * Store some context associated with an action. + * @param userContext + */ + virtual void set_user_context(void* userContext) { + guard g(lock_); + userContext_ = userContext; + } + /** + * Blocks the current thread until the action this token is associated + * with has completed. + */ + virtual void wait_for_completion(); + /** + * Blocks the current thread until the action this token is associated + * with has completed. + * @param timeout The timeout (in milliseconds) + */ + virtual void wait_for_completion(long timeout); + /** + * Waits a relative amount of time for the action to complete. + * @param relTime The amount of time to wait for the event. + * @return @em true if the event gets signaled in the specified time, + * @em false on a timeout. + */ + template + bool wait_for_completion(const std::chrono::duration& relTime) { + wait_for_completion((long) std::chrono::duration_cast(relTime).count()); + return rc_ == 0; + } + /** + * Waits until an absolute time for the action to complete. + * @param absTime The absolute time to wait for the event. + * @return @em true if the event gets signaled in the specified time, + * @em false on a timeout. + */ + template + bool wait_until_completion(const std::chrono::time_point& absTime) { + guard g(lock_); + if (!cond_.wait_until(g, absTime, [this]{return complete_;})) + return false; + if (rc_ != MQTTASYNC_SUCCESS) + throw exception(rc_); + return true; + } + +}; + +typedef token::ptr_t token_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_token_h + diff --git a/src/mqtt/topic.h b/src/mqtt/topic.h new file mode 100644 index 0000000..3aabd90 --- /dev/null +++ b/src/mqtt/topic.h @@ -0,0 +1,115 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file topic.h +/// Declaration of MQTT topic class +/// @date May 1, 2013 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_topic_h +#define __mqtt_topic_h + +extern "C" { + #include "MQTTAsync.h" +} + +#include "mqtt/delivery_token.h" +#include "mqtt/message.h" +#include +#include +#include + +namespace mqtt { + +class async_client; + +///////////////////////////////////////////////////////////////////////////// + +/** + * Represents a topic destination, used for publish/subscribe messaging. + */ +class topic +{ + /// The topic name + std::string name_; + + /// The client to which this topic is connected + async_client* cli_; + +public: + /** + * A smart/shared pointer to this class. + */ + typedef std::shared_ptr ptr_t; + /** + * Construct an MQTT topic destination for messages. + * @param name + * @param cli + */ + topic(const std::string& name, async_client& cli) : name_(name), cli_(&cli) {} + /** + * Returns the name of the queue or topic. + * @return std::string + */ + std::string get_name() const { return name_; } + /** + * Publishes a message on the topic. + * @param payload + * @param n + * @param qos + * @param retained + * + * @return delivery_token + */ + idelivery_token_ptr publish(const void* payload, size_t n, int qos, bool retained); + /** + * Publishes a message on the topic. + * @param payload + * @param qos + * @param retained + * + * @return delivery_token + */ + idelivery_token_ptr publish(const std::string& str, int qos, bool retained) { + return publish(str.data(), str.length(), qos, retained); + } + /** + * Publishes the specified message to this topic, but does not wait for + * delivery of the message to complete. + * @param message + * @return delivery_token + */ + idelivery_token_ptr publish(message_ptr msg); + /** + * Returns a string representation of this topic. + * @return std::string + */ + std::string to_str() const { return name_; } +}; + +/** + * A shared pointer to the topic class. + */ +typedef topic::ptr_t topic_ptr; + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + +#endif // __mqtt_topic_h + diff --git a/src/obj/async_client.dep b/src/obj/async_client.dep new file mode 100644 index 0000000..e69de29 diff --git a/src/obj/client.dep b/src/obj/client.dep new file mode 100644 index 0000000..e69de29 diff --git a/src/obj/iclient_persistence.dep b/src/obj/iclient_persistence.dep new file mode 100644 index 0000000..e69de29 diff --git a/src/obj/message.dep b/src/obj/message.dep new file mode 100644 index 0000000..e69de29 diff --git a/src/obj/token.dep b/src/obj/token.dep new file mode 100644 index 0000000..e69de29 diff --git a/src/obj/topic.dep b/src/obj/topic.dep new file mode 100644 index 0000000..e69de29 diff --git a/src/samples/Makefile b/src/samples/Makefile new file mode 100644 index 0000000..e49c436 --- /dev/null +++ b/src/samples/Makefile @@ -0,0 +1,36 @@ +# Makefile for the mqttpp sample applications + +PAHO_C_LIB ?= /home/fmp/static/opensrc/mqtt/paho/org.eclipse.paho.mqtt.c + +all: async_publish async_subscribe sync_publish + +CXXFLAGS += -Wall -std=c++0x +CPPFLAGS += -I.. -I$(PAHO_C_LIB)/src + +ifdef DEBUG + CPPFLAGS += -DDEBUG + CXXFLAGS += -g -O0 +else + CPPFLAGS += -D_NDEBUG + CXXFLAGS += -O2 +endif + +LDLIBS += -L../lib -L$(PAHO_C_LIB)/src/linux_ia64 -lmqttpp -lmqttv3a + +async_publish: async_publish.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< $(LDLIBS) + +async_subscribe: async_subscribe.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< $(LDLIBS) + +sync_publish: sync_publish.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $< $(LDLIBS) + +.PHONY: clean +clean: + rm -f async_publish async_subscribe sync_publish + +.PHONY: distclean +distclean: clean + + diff --git a/src/samples/async_publish.cpp b/src/samples/async_publish.cpp new file mode 100644 index 0000000..cd545a8 --- /dev/null +++ b/src/samples/async_publish.cpp @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#include +#include +#include +#include // For sleep +#include +#include +#include "mqtt/async_client.h" + +const std::string ADDRESS("tcp://localhost:1883"); +const std::string CLIENTID("AsyncPublisher"); +const std::string TOPIC("hello"); + +const char* PAYLOAD1 = "Hello World!"; +const char* PAYLOAD2 = "Hi there!"; +const char* PAYLOAD3 = "Is anyone listening?"; +const char* PAYLOAD4 = "Someone is always listening."; + +const int QOS = 1; +const long TIMEOUT = 10000L; + +inline void sleep(int ms) { + std::this_thread::sleep_for(std::chrono::milliseconds(ms)); +} + +///////////////////////////////////////////////////////////////////////////// + +/** + * A callback class for use with the main MQTT client. + */ +class callback : public virtual mqtt::callback +{ +public: + virtual void connection_lost(const std::string& cause) { + std::cout << "\nConnection lost" << std::endl; + if (!cause.empty()) + std::cout << "\tcause: " << cause << std::endl; + } + + // We're not subscribed to anything, so this should never be called. + virtual void message_arrived(const std::string& topic, mqtt::message_ptr msg) {} + + virtual void delivery_complete(mqtt::idelivery_token_ptr tok) { + std::cout << "Delivery complete for token: " + << (tok ? tok->get_message_id() : -1) << std::endl; + } +}; + +///////////////////////////////////////////////////////////////////////////// + +/** + * A base action listener. + */ +class action_listener : public virtual mqtt::iaction_listener +{ +protected: + virtual void on_failure(const mqtt::itoken& tok) { + std::cout << "\n\tListener: Failure on token: " + << tok.get_message_id() << std::endl; + } + + virtual void on_success(const mqtt::itoken& tok) { + std::cout << "\n\tListener: Success on token: " + << tok.get_message_id() << std::endl; + } +}; + +///////////////////////////////////////////////////////////////////////////// + +/** + * A derived action listener for publish events. + */ +class delivery_action_listener : public action_listener +{ + bool done_; + + virtual void on_failure(const mqtt::itoken& tok) { + action_listener::on_failure(tok); + done_ = true; + } + + virtual void on_success(const mqtt::itoken& tok) { + action_listener::on_success(tok); + done_ = true; + } + +public: + delivery_action_listener() : done_(false) {} + bool is_done() const { return done_; } +}; + +///////////////////////////////////////////////////////////////////////////// + +int main(int argc, char* argv[]) +{ + mqtt::async_client client(ADDRESS, CLIENTID); + + callback cb; + client.set_callback(cb); + + try { + mqtt::itoken_ptr conntok = client.connect(); + std::cout << "Waiting for the connection..." << std::flush; + conntok->wait_for_completion(); + std::cout << "OK" << std::endl; + + // First use a message pointer. + + std::cout << "Sending message..." << std::flush; + mqtt::message_ptr pubmsg = std::make_shared(PAYLOAD1); + pubmsg->set_qos(QOS); + client.publish(TOPIC, pubmsg)->wait_for_completion(TIMEOUT); + std::cout << "OK" << std::endl; + + // Now try with itemized publish. + + std::cout << "Sending next message..." << std::flush; + mqtt::idelivery_token_ptr pubtok; + pubtok = client.publish(TOPIC, PAYLOAD2, std::strlen(PAYLOAD2), QOS, false); + pubtok->wait_for_completion(TIMEOUT); + std::cout << "OK" << std::endl; + + // Now try with a listener + + std::cout << "Sending next message..." << std::flush; + action_listener listener; + pubmsg = std::make_shared(PAYLOAD3); + pubtok = client.publish(TOPIC, pubmsg, nullptr, listener); + pubtok->wait_for_completion(); + std::cout << "OK" << std::endl; + + // Finally try with a listener, but no token + + std::cout << "Sending final message..." << std::flush; + delivery_action_listener deliveryListener; + pubmsg = std::make_shared(PAYLOAD4); + client.publish(TOPIC, pubmsg, nullptr, deliveryListener); + + while (!deliveryListener.is_done()) { + sleep(100); + } + std::cout << "OK" << std::endl; + + // Double check that there are no pending tokens + + std::vector toks = client.get_pending_delivery_tokens(); + if (!toks.empty()) + std::cout << "Error: There are pending delivery tokens!" << std::endl; + + // Disconnect + std::cout << "Disconnecting..." << std::flush; + conntok = client.disconnect(); + conntok->wait_for_completion(); + std::cout << "OK" << std::endl; + } + catch (const mqtt::exception& exc) { + std::cerr << "Error: " << exc.what() << std::endl; + return 1; + } + + return 0; +} + diff --git a/src/samples/async_subscribe.cpp b/src/samples/async_subscribe.cpp new file mode 100644 index 0000000..f832369 --- /dev/null +++ b/src/samples/async_subscribe.cpp @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include "mqtt/async_client.h" + +const std::string ADDRESS("tcp://localhost:1883"); +const std::string CLIENTID("AsyncSubcriber"); +const std::string TOPIC("hello"); + +const int QOS = 1; +const long TIMEOUT = 10000L; + +///////////////////////////////////////////////////////////////////////////// + +class action_listener : public virtual mqtt::iaction_listener +{ + std::string name_; + + virtual void on_failure(const mqtt::itoken& tok) { + std::cout << name_ << " failure"; + if (tok.get_message_id() != 0) + std::cout << " (token: " << tok.get_message_id() << ")" << std::endl; + std::cout << std::endl; + } + + virtual void on_success(const mqtt::itoken& tok) { + std::cout << name_ << " success"; + if (tok.get_message_id() != 0) + std::cout << " (token: " << tok.get_message_id() << ")" << std::endl; + if (!tok.get_topics().empty()) + std::cout << "\ttoken topic: '" << tok.get_topics()[0] << "', ..." << std::endl; + std::cout << std::endl; + } + +public: + action_listener(const std::string& name) : name_(name) {} +}; + +///////////////////////////////////////////////////////////////////////////// + +class callback : public virtual mqtt::callback, + public virtual mqtt::iaction_listener + +{ + int nretry_; + mqtt::async_client& cli_; + action_listener& listener_; + + void reconnect() { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + mqtt::connect_options connOpts; + connOpts.set_keep_alive_interval(20); + connOpts.set_clean_session(true); + + try { + cli_.connect(connOpts, nullptr, *this); + } + catch (const mqtt::exception& exc) { + std::cerr << "Error: " << exc.what() << std::endl; + exit(1); + } + } + + // Re-connection failure + virtual void on_failure(const mqtt::itoken& tok) { + std::cout << "Reconnection failed." << std::endl; + if (++nretry_ > 5) + exit(1); + reconnect(); + } + + // Re-connection success + virtual void on_success(const mqtt::itoken& tok) { + std::cout << "Reconnection success" << std::endl;; + cli_.subscribe(TOPIC, QOS, nullptr, listener_); + } + + virtual void connection_lost(const std::string& cause) { + std::cout << "\nConnection lost" << std::endl; + if (!cause.empty()) + std::cout << "\tcause: " << cause << std::endl; + + std::cout << "Reconnecting." << std::endl; + nretry_ = 0; + reconnect(); + } + + virtual void message_arrived(const std::string& topic, mqtt::message_ptr msg) { + std::cout << "Message arrived" << std::endl; + std::cout << "\ttopic: '" << topic << "'" << std::endl; + std::cout << "\t'" << msg->to_str() << "'\n" << std::endl; + } + + virtual void delivery_complete(mqtt::idelivery_token_ptr token) {} + +public: + callback(mqtt::async_client& cli, action_listener& listener) + : cli_(cli), listener_(listener) {} +}; + +///////////////////////////////////////////////////////////////////////////// + +int main(int argc, char* argv[]) +{ + mqtt::async_client client(ADDRESS, CLIENTID); + action_listener subListener("Subscription"); + + callback cb(client, subListener); + client.set_callback(cb); + + mqtt::connect_options connOpts; + connOpts.set_keep_alive_interval(20); + connOpts.set_clean_session(true); + + try { + mqtt::itoken_ptr conntok = client.connect(connOpts); + std::cout << "Waiting for the connection..." << std::flush; + conntok->wait_for_completion(); + std::cout << "OK" << std::endl; + + std::cout << "Subscribing to topic " << TOPIC << "\n" + << "for client " << CLIENTID + << " using QoS" << QOS << "\n\n" + << "Press Q to quit\n" << std::endl; + + client.subscribe(TOPIC, QOS, nullptr, subListener); + + while (std::tolower(std::cin.get()) != 'q') + ; + + std::cout << "Disconnecting..." << std::flush; + conntok = client.disconnect(); + conntok->wait_for_completion(); + std::cout << "OK" << std::endl; + } + catch (const mqtt::exception& exc) { + std::cerr << "Error: " << exc.what() << std::endl; + return 1; + } + + return 0; +} + diff --git a/src/samples/sync_publish.cpp b/src/samples/sync_publish.cpp new file mode 100644 index 0000000..879c660 --- /dev/null +++ b/src/samples/sync_publish.cpp @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "mqtt/client.h" +#include "mqtt/ipersistable.h" + +const std::string ADDRESS("tcp://localhost:1883"); +const std::string CLIENTID("SyncPublisher"); +const std::string TOPIC("hello"); + +const std::string PAYLOAD1("Hello World!"); + +const char* PAYLOAD2 = "Hi there!"; +const char* PAYLOAD3 = "Is anyone listening?"; + +const int QOS = 1; +const int TIMEOUT = 10000; + +///////////////////////////////////////////////////////////////////////////// + +class sample_mem_persistence : virtual public mqtt::iclient_persistence +{ + bool open_; + std::map store_; + +public: + sample_mem_persistence() : open_(false) {} + + // "Open" the store + virtual void open(const std::string& clientId, const std::string& serverURI) { + std::cout << "[Opening persistence for '" << clientId + << "' at '" << serverURI << "']" << std::endl; + open_ = true; + } + + // Close the persistent store that was previously opened. + virtual void close() { + std::cout << "[Closing persistence store.]" << std::endl; + open_ = false; + } + + // Clears persistence, so that it no longer contains any persisted data. + virtual void clear() { + std::cout << "[Clearing persistence store.]" << std::endl; + store_.clear(); + } + + // Returns whether or not data is persisted using the specified key. + virtual bool contains_key(const std::string &key) { + return store_.find(key) != store_.end(); + } + + // Gets the specified data out of the persistent store. + virtual mqtt::ipersistable_ptr get(const std::string& key) const { + std::cout << "[Searching persistence for key '" + << key << "']" << std::endl; + auto p = store_.find(key); + if (p == store_.end()) + throw mqtt::persistence_exception(); + std::cout << "[Found persistence data for key '" + << key << "']" << std::endl; + + return p->second; + } + /** + * Returns the keys in this persistent data store. + */ + virtual std::vector keys() const { + std::vector ks; + for (const auto& k : store_) + ks.push_back(k.first); + return ks; + } + + // Puts the specified data into the persistent store. + virtual void put(const std::string& key, mqtt::ipersistable_ptr persistable) { + std::cout << "[Persisting data with key '" + << key << "']" << std::endl; + + store_[key] = persistable; + } + + // Remove the data for the specified key. + virtual void remove(const std::string &key) { + std::cout << "[Persistence removing key '" << key << "']" << std::endl; + auto p = store_.find(key); + if (p == store_.end()) + throw mqtt::persistence_exception(); + store_.erase(p); + std::cout << "[Persistence key removed '" << key << "']" << std::endl; + } +}; + +///////////////////////////////////////////////////////////////////////////// + +class callback : public virtual mqtt::callback +{ +public: + virtual void connection_lost(const std::string& cause) { + std::cout << "\nConnection lost" << std::endl; + if (!cause.empty()) + std::cout << "\tcause: " << cause << std::endl; + } + + // We're not subscrived to anything, so this should never be called. + virtual void message_arrived(const std::string& topic, mqtt::message_ptr msg) { + } + + virtual void delivery_complete(mqtt::idelivery_token_ptr tok) { + std::cout << "\n\t[Delivery complete for token: " + << (tok ? tok->get_message_id() : -1) << "]" << std::endl; + } +}; + +// -------------------------------------------------------------------------- + +int main(int argc, char* argv[]) +{ + sample_mem_persistence persist; + mqtt::client client(ADDRESS, CLIENTID, &persist); + + callback cb; + client.set_callback(cb); + + mqtt::connect_options connOpts; + connOpts.set_keep_alive_interval(20); + connOpts.set_clean_session(true); + + try { + std::cout << "Connecting..." << std::flush; + client.connect(connOpts); + std::cout << "OK" << std::endl; + + // First use a message pointer. + + std::cout << "Sending message..." << std::flush; + mqtt::message_ptr pubmsg = std::make_shared(PAYLOAD1); + pubmsg->set_qos(QOS); + client.publish(TOPIC, pubmsg); + std::cout << "OK" << std::endl; + + // Now try with itemized publish. + + std::cout << "Sending next message..." << std::flush; + client.publish(TOPIC, PAYLOAD2, strlen(PAYLOAD2)+1, 0, false); + std::cout << "OK" << std::endl; + + // Now try with a listener, but no token + + std::cout << "Sending final message..." << std::flush; + pubmsg = std::make_shared(PAYLOAD3); + pubmsg->set_qos(QOS); + client.publish(TOPIC, pubmsg); + std::cout << "OK" << std::endl; + + // Disconnect + std::cout << "Disconnecting..." << std::flush; + client.disconnect(); + std::cout << "OK" << std::endl; + } + catch (const mqtt::persistence_exception& exc) { + std::cerr << "Persistence Error: " << exc.what() << " [" + << exc.get_reason_code() << "]" << std::endl; + return 1; + } + catch (const mqtt::exception& exc) { + std::cerr << "Error: " << exc.what() << " [" + << exc.get_reason_code() << "]" << std::endl; + return 1; + } + + return 0; +} + diff --git a/src/token.cpp b/src/token.cpp new file mode 100644 index 0000000..1f21643 --- /dev/null +++ b/src/token.cpp @@ -0,0 +1,149 @@ +// token.cpp + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#include "mqtt/token.h" +#include "mqtt/async_client.h" +#include +#include + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +// Failure callback from the C library. +// The 'context' is a raw pointer to the token object. +void token::on_failure(void* context, MQTTAsync_failureData* rsp) +{ + if (context) { + token* tok = static_cast(context); + tok->on_failure(rsp); + tok->get_client()->remove_token(tok); + } +} + +// Success callback from the C library. +// The 'context' is a raw pointer to the token object. +void token::on_success(void* context, MQTTAsync_successData* rsp) +{ + if (context) { + token* tok = static_cast(context); + tok->on_success(rsp); + tok->get_client()->remove_token(tok); + } +} + +void token::on_success(MQTTAsync_successData* rsp) +{ + guard g(lock_); + iaction_listener* listener = listener_; + tok_ = (rsp) ? rsp->token : 0; + rc_ = MQTTASYNC_SUCCESS; + complete_ = true; + g.unlock(); + + // Note: callback always completes before the obect is signalled. + if (listener) + listener->on_success(*this); + cond_.notify_all(); +} + +void token::on_failure(MQTTAsync_failureData* rsp) +{ + guard g(lock_); + iaction_listener* listener = listener_; + if (rsp) { + tok_ = rsp->token; + rc_ = rsp->code; + } + else { + tok_ = 0; + rc_ = -1; + } + complete_ = true; + g.unlock(); + + // Note: callback always completes before the obect is signalled. + if (listener) + listener->on_failure(*this); + cond_.notify_all(); +} + +// -------------------------------------------------------------------------- + +token::token(iasync_client& cli) : tok_(MQTTAsync_token(0)), cli_(&cli), + userContext_(nullptr), listener_(nullptr), + complete_(false), rc_(0) +{ +} + +token::token(iasync_client& cli, MQTTAsync_token tok) : tok_(tok), cli_(&cli), + userContext_(nullptr), listener_(nullptr), + complete_(false), rc_(0) +{ +} + +token::token(iasync_client& cli, const std::string& top) + : tok_(MQTTAsync_token(0)), cli_(&cli), + userContext_(nullptr), listener_(nullptr), + complete_(false), rc_(0) +{ + topics_.push_back(top); +} + +token::token(iasync_client& cli, const std::vector& topics) + : tok_(MQTTAsync_token(0)), topics_(topics), cli_(&cli), + userContext_(nullptr), listener_(nullptr), + complete_(false), rc_(0) +{ +} + +//exception token::get_exception() +//{ +//} + +void token::wait_for_completion() +{ + guard g(lock_); + cond_.wait(g, [this]{return complete_;}); + if (rc_ != MQTTASYNC_SUCCESS) + throw exception(rc_); +} + +void token::wait_for_completion(long timeout) +{ + guard g(lock_); + if (timeout == 0) { // No wait. Are we done now? + if (!complete_) + throw exception(MQTTASYNC_FAILURE); // TODO: Get a timout error number + } + else if (timeout < 0) { // Wait forever + cond_.wait(g, [this]{return complete_;}); + } + else { + if (!cond_.wait_for(g, std::chrono::milliseconds(timeout), + [this]{return complete_;})) + throw exception(MQTTASYNC_FAILURE); // TODO: Get a timout error number + } + if (rc_ != MQTTASYNC_SUCCESS) + throw exception(rc_); +} + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + diff --git a/src/topic.cpp b/src/topic.cpp new file mode 100644 index 0000000..c5f8543 --- /dev/null +++ b/src/topic.cpp @@ -0,0 +1,43 @@ +// topic.cpp + +/******************************************************************************* + * Copyright (c) 2013 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + + +#include "mqtt/topic.h" +#include "mqtt/async_client.h" + +namespace mqtt { + +///////////////////////////////////////////////////////////////////////////// + +idelivery_token_ptr topic::publish(const void* payload, size_t n, + int qos, bool retained) +{ + return cli_->publish(name_, payload, n, qos, retained); +} + +idelivery_token_ptr topic::publish(message_ptr msg) +{ + return cli_->publish(name_, msg); +} + +///////////////////////////////////////////////////////////////////////////// +// end namespace mqtt +} + + +