diff options
author | Jesse Gilles <jgilles@multitech.com> | 2015-04-20 16:49:52 -0500 |
---|---|---|
committer | Jesse Gilles <jgilles@multitech.com> | 2015-04-20 16:49:52 -0500 |
commit | 17b117e73df71925d73ee026b4f54aa1867ce0a5 (patch) | |
tree | 382610c8e598a77a961c5ceb32b9b614ed00e757 | |
download | libmts-17b117e73df71925d73ee026b4f54aa1867ce0a5.tar.gz libmts-17b117e73df71925d73ee026b4f54aa1867ce0a5.tar.bz2 libmts-17b117e73df71925d73ee026b4f54aa1867ce0a5.zip |
initial commit
48 files changed, 7959 insertions, 0 deletions
@@ -0,0 +1,3 @@ +Sean Godinez <sgodinez@multitech.com> +Jason Reiss <jreiss@multitech.com> +Mike Fiore <mfiore@multitech.com> @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d1e6a87 --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +include version + +includedir ?= /usr/include +libdir ?= /usr/lib + +OBJS += \ +MTS_Buffer.o \ +MTS_Condition.o \ +MTS_Lock.o \ +MTS_Logger.o \ +MTS_Object.o \ +MTS_SignalThread.o \ +MTS_System.o \ +MTS_Text.o \ +MTS_Thread.o \ +MTS_Timer.o \ +MTS_TimerThread.o + +CPP_DEPPS+= \ +MTS_Buffer.d \ +MTS_Condition.d \ +MTS_Lock.d \ +MTS_Logger.d \ +MTS_Object.d \ +MTS_SignalThread.d \ +MTS_System.d \ +MTS_Text.d \ +MTS_Thread.d \ +MTS_Timer.d \ +MTS_TimerThread.d + +all: libmts.a libmts.so.0 + +libmts.a: $(OBJS) + @echo 'Building target: $@' + $(AR) -r libmts.a $(OBJS) + @echo 'Finished building target: $@' + @echo ' ' + +libmts.so.0: $(OBJS) + @echo 'Building target: $@' + $(CXX) -shared -Wl,-soname,$@ -o libmts.so.$(VERSION) $(OBJS) + @echo 'Finished building target: $@' + @echo ' ' + +%.o: src/%.cpp + @echo 'Building file: $<' + $(CXX) $(CFLAGS) -Iinclude -Wall -Werror -c -fPIC -fmessage-length=0 -std=c++0x -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + +install: + mkdir -p $(DESTDIR)$(libdir) + mkdir -p $(DESTDIR)$(includedir)/mts + install -m 0644 libmts.a libmts.so.$(VERSION) $(DESTDIR)$(libdir)/ + ln -sf libmts.so.$(VERSION) $(DESTDIR)$(libdir)/libmts.so.0 + ln -sf libmts.so.0 $(DESTDIR)$(libdir)/libmts.so + install -m 0644 include/mts/* $(DESTDIR)$(includedir)/mts/ + +clean: + -$(RM) $(OBJS) $(CPP_DEPPS) libmts.a libmts.so* + -@echo ' ' + +.PHONY: all clean dependents install +.SECONDARY: + diff --git a/doc/MTS_Documentation.doxyfile b/doc/MTS_Documentation.doxyfile new file mode 100644 index 0000000..8a72bd7 --- /dev/null +++ b/doc/MTS_Documentation.doxyfile @@ -0,0 +1,1679 @@ +# Doxyfile 1.7.3 + +# 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 a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = "MTS C++ Library Documentation " + +# 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 = "General purpose 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 = mts_logo.jpeg + +# 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 = + +# 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 = NO + +# 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 = + +# 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 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 + +#--------------------------------------------------------------------------- +# 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 <command> <input-file>, where <command> is the value of +# the FILE_VERSION_FILTER tag, and <input-file> 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 = + +#--------------------------------------------------------------------------- +# 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 = doxygen.log + +#--------------------------------------------------------------------------- +# 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 = resource ../include + +# 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 = + +# 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 +# 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. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used 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 <filter> <input-file>, where <filter> +# is the value of the INPUT_FILTER tag, and <input-file> 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. + +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 +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. +# Doxygen will adjust the colors in the stylesheet 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 +# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters"> +# Qt Help Project / Custom Filters</a>. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's +# filter section matches. +# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes"> +# Qt Help Project / Filter Attributes</a>. + +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 = NO + +# 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 at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This 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 + +# 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. + +GENERATE_TREEVIEW = YES + +# 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 + +# 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 = YES + +# 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 = + +# 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 + +#--------------------------------------------------------------------------- +# 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 stylesheet 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 +# in the INCLUDE_PATH (see below) will be search if 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 write a font called Helvetica to the output +# directory and reference it in 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 output directory to look for the +# FreeSans.ttf font (which doxygen will put there itself). If you specify a +# different font using DOT_FONTNAME you can set the path where dot +# can find it using this tag. + +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 +# 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 png, svg, gif or svg. +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# 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/doc/resource/MTS_DoxygenMain.h b/doc/resource/MTS_DoxygenMain.h new file mode 100755 index 0000000..ce57cd9 --- /dev/null +++ b/doc/resource/MTS_DoxygenMain.h @@ -0,0 +1,34 @@ +/*! + \file MTS_DoxygenMain.h + \brief Header for MTS Library Code Documentation. + \date 2012-12-13 + \author Sean Godinez + + Details. + */ + +#ifndef MTS_DOXYGENMAIN_H_ +#define MTS_DOXYGENMAIN_H_ + + +/** @mainpage Welcome to the Multi-Tech Systems MTS Library Documentation Site +* +* @authors MTS Software Developers +* +* @section intro Introduction +* @todo Provide an introduction describing the MTS library, +* build configuration, and unit testing. +* +* +* <hr> +* @section notes Release Notes +* <hr> +* @section requirements Requirements +* <hr> +* @todo Document MTS Libraries +* +* <hr> +* Website: <A HREF="http://www.multitech.com"> Multi-Tech Systems </A> +*/ + +#endif /* MTR_DOXYGENMAIN_H_ */ diff --git a/doc/resource/mts_logo.jpeg b/doc/resource/mts_logo.jpeg Binary files differnew file mode 100644 index 0000000..3bae16d --- /dev/null +++ b/doc/resource/mts_logo.jpeg diff --git a/include/mts/MTS_AutoLock.h b/include/mts/MTS_AutoLock.h new file mode 100644 index 0000000..e7a05bd --- /dev/null +++ b/include/mts/MTS_AutoLock.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_AutoLock.h + \brief Auto lock + \date 08OCT14 + \author Pavlo Samko + + Auto lock. + */ + + +#ifndef _MTS_AUTOLOCK_H_ +#define _MTS_AUTOLOCK_H_ + +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_Lock.h> + +namespace MTS { + + //! Auto lock + /*! + Auto lock + + \sa Lock + */ + + class AutoLock: private NonCopyable { + + public: + AutoLock(Lock &lock): m_lock(lock) { m_lock.lock(); } //!< Constructs the AutoLock + ~AutoLock() { m_lock.unlock(); } //!< Destructs the AutoLock + + private: + Lock &m_lock; //!< Lock + }; +} + +#endif diff --git a/include/mts/MTS_AutoPtr.h b/include/mts/MTS_AutoPtr.h new file mode 100644 index 0000000..68b82cf --- /dev/null +++ b/include/mts/MTS_AutoPtr.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_AutoPtr.h + \brief An autopointer + \date 15JUN11 + \author Sean Godinez + + An autopointer. + */ + +#ifndef MTS_AUTOPTR_H +#define MTS_AUTOPTR_H + +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_Stdint.h> + +namespace MTS { + + //! An autopointer + /*! + An autopointer cleans up after itself. + */ + template<class T> class AutoPtr: NonCopyable { + + public: + enum MallocType { + SINGLE, ARRAY + }; + + explicit AutoPtr(T* ptr = 0, MallocType type = SINGLE); //!< Explicitly Constructs the AutoPtr to reference ptr + ~AutoPtr(); //!< Destructs the AutoPtr deleting T + + T& operator*() const; //!< Returns T + T* operator->() const; //!< Returns address of T + T& operator[](const uint32_t& index) const; //!< Returns T at index + T* get() const; //!< Returns address of T + T* release(); //!< Removes reference to T (does NOT delete T) and returns address + void reset(T* ptr = 0, MallocType type = SINGLE); //!< Deletes old T and assigns internal reference to ptr + bool isNull() const; //!< Returns true if pointer is NULL + + private: + T* m_pObj; //!< Reference to class T + MallocType m_eType; //!< Describes memory allocated as a single T or block of Ts + + }; + + template<class T> AutoPtr<T>::AutoPtr(T* ptr, MallocType type) + : m_pObj(ptr), m_eType(type) { + } + + template<class T> AutoPtr<T>::~AutoPtr() { + if (m_eType == SINGLE) { + delete m_pObj; + } else { + delete[] m_pObj; + } + } + + template<class T> T& AutoPtr<T>::operator*() const { + return *m_pObj; + } + + template<class T> T* AutoPtr<T>::operator->() const { + return m_pObj; + } + + template<class T> T& AutoPtr<T>::operator[](const uint32_t& index) const { + return m_pObj[index]; + } + + template<class T> T* AutoPtr<T>::get() const { + return m_pObj; + } + + template<class T> T* AutoPtr<T>::release() { + T* temp = m_pObj; + m_pObj = 0; + return temp; + } + + template<class T> void AutoPtr<T>::reset(T* ptr, MallocType type) { + T* temp = m_pObj; + m_pObj = ptr; + if (m_eType == SINGLE) { + delete temp; + } else { + delete[] temp; + } + m_eType = type; + } + + template<class T> bool AutoPtr<T>::isNull() const { + return (m_pObj == 0); + } +} + +#endif diff --git a/include/mts/MTS_BasicPublisher.h b/include/mts/MTS_BasicPublisher.h new file mode 100644 index 0000000..d5749ec --- /dev/null +++ b/include/mts/MTS_BasicPublisher.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_BasicPublisher.h + \brief A simple publisher + \date 28MAR12 + \author Sean Godinez + + A basic publisher. + */ + +#ifndef _MTS_BASICPUBLISHER_H_ +#define _MTS_BASICPUBLISHER_H_ + +#include <mts/MTS_Publisher.h> + +namespace MTS { + + //! A basic publisher + /*! + A basic publisher provides simple publishing functionality. + + \sa Publisher, Subscriber, BasicSubscriber + */ + template<class T> class BasicPublisher: public Publisher<T> { + + public: + BasicPublisher(); //!< Constructor + virtual ~BasicPublisher(); //!< Destructor + + virtual void publish(const T& object); //!< Publishes T to Subscribers + }; + + template<class T> BasicPublisher<T>::BasicPublisher() { + } + + template<class T> BasicPublisher<T>::~BasicPublisher() { + } + + template<class T> void BasicPublisher<T>::publish(const T& object) { + Publisher<T>::publish(object); + } + +} + +#endif diff --git a/include/mts/MTS_BasicSubscriber.h b/include/mts/MTS_BasicSubscriber.h new file mode 100644 index 0000000..908dde9 --- /dev/null +++ b/include/mts/MTS_BasicSubscriber.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_BasicSubscriber.h + \brief A simple subscriber + \date 28MAR12 + \author Sean Godinez + + A subscriber. + */ +#ifndef _MTS_BASICSUBSCRIBER_H_ +#define _MTS_BASICSUBSCRIBER_H_ + +#include <mts/MTS_Subscriber.h> +#include <mts/MTS_Callback.h> + +namespace MTS { + + //! A basic subscriber + /*! + A basic subscriber provides simple subscribing functionality. + + \sa Publisher, Subscriber, BasicPublisher + */ + template<class T> class BasicSubscriber: public Subscriber<T> { + + public: + explicit BasicSubscriber(const Callback<T>& callback, const std::string& name = ""); //!< Constructor + virtual ~BasicSubscriber();//!< Destructor + + virtual void update(const T& object); //!< Invokes callback with published data T + + private: + Callback<T>* callback; + + //Prevent Copy and Assignment operators from being called + BasicSubscriber(const BasicSubscriber&); + BasicSubscriber& operator=(const BasicSubscriber&); + }; + + template<class T> BasicSubscriber<T>::BasicSubscriber(const Callback<T>& callback, const std::string& name) + : Subscriber<T>(name), callback(callback.clone()) { + } + + template<class T> BasicSubscriber<T>::~BasicSubscriber() { + delete callback; + } + + template<class T> void BasicSubscriber<T>::update(const T& object) { + callback->invoke(object); + } +} + +#endif diff --git a/include/mts/MTS_Buffer.h b/include/mts/MTS_Buffer.h new file mode 100644 index 0000000..96f25a9 --- /dev/null +++ b/include/mts/MTS_Buffer.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Buffer.h + \brief A buffer + \date 15JUN11 + \author Sean Godinez + + A buffer. + */ + +#ifndef MTS_BUFFER_H +#define MTS_BUFFER_H + +#include <mts/MTS_Stdint.h> +#include <vector> +#include <string> + +namespace MTS { + + class Buffer { + + public: + static const uint32_t DEFAULT_CAPACITY; + + explicit Buffer(uint32_t capacity = DEFAULT_CAPACITY); + Buffer(const uint8_t* bytes, uint32_t count); + Buffer(const Buffer& other); + virtual ~Buffer(); + + Buffer& operator=(const Buffer& other); + + const uint8_t* getBuffer() const; + std::string str() const; + + uint32_t getSize() const; + void setSize(uint32_t newSize); + + uint32_t getCapacity() const; + void setCapacity(uint32_t newCapacity); + + void clear(); + void compact(); + + uint8_t operator[](uint32_t index) const; + uint8_t operator[](uint32_t index); + + const uint8_t& at(uint32_t index) const; + uint8_t& at(uint32_t index); + + Buffer& append(uint8_t byte); + Buffer& append(const uint8_t* bytes, uint32_t count); + + Buffer& insert(uint32_t index, uint8_t byte); + Buffer& insert(uint32_t index, const uint8_t* bytes, + uint32_t count); + + Buffer& remove(uint32_t index); + Buffer& remove(uint32_t start, uint32_t end); + + Buffer& replace(uint32_t start, uint32_t end, const uint8_t* bytes, uint32_t count); + Buffer* clone() const; + + private: + std::vector<uint8_t> m_vBuffer; + + }; +} + +#endif diff --git a/include/mts/MTS_Component.h b/include/mts/MTS_Component.h new file mode 100644 index 0000000..215add5 --- /dev/null +++ b/include/mts/MTS_Component.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Component.h + \brief A threaded sub-pub object + \date 28MAR12 + \author Sean Godinez + + A threaded subscriber-publisher object. + */ + +#ifndef _MTS_COMPONENT_H_ +#define _MTS_COMPONENT_H_ + +#include <mts/MTS_Thread.h> +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_SubscriberQueue.h> +#include <mts/MTS_BasicPublisher.h> +#include <mts/MTS_Stdint.h> +#include <string> + +namespace MTS { + + template<class S, class P> class Component: public Thread { + + public: + virtual ~Component(); + + Subscriber<S>& getSubscriber(); + Publisher<P>& getPublisher(); + + virtual void stop(); + + protected: + explicit Component(const std::string& sName, uint32_t iCapacity = UINT32_MAX, bool bManaged = true); + + SubscriberQueue<S> m_oSubscriber; + BasicPublisher<P> m_oPublisher; + + private: + + }; + + template<class S, class P> Component<S, P>::Component( + const std::string& name, uint32_t capacity, bool managed) + : Thread(name, managed), m_oSubscriber(name, capacity) { + } + + template<class S, class P> Component<S, P>::~Component() { + Component::stop(); + } + + template<class S, class P> Subscriber<S>& Component<S, P>::getSubscriber() { + return m_oSubscriber; + } + + template<class S, class P> Publisher<P>& Component<S, P>::getPublisher() { + return m_oPublisher; + } + + template<class S, class P> void Component<S, P>::stop() { + Thread::stop(); + m_oSubscriber.clear(); + } +} + +#endif diff --git a/include/mts/MTS_Condition.h b/include/mts/MTS_Condition.h new file mode 100644 index 0000000..c15acd0 --- /dev/null +++ b/include/mts/MTS_Condition.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Condition.h + \brief A condition that can be waited on or signaled + \date 15JUN11 + \author Sean Godinez + + A platform independent condition that can be waited on or signaled. + */ + +#ifndef _MTS_CONDITION_H_ +#define _MTS_CONDITION_H_ + +#include <mts/MTS_Stdint.h> +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_NonCopyable.h> + +#ifdef WIN32 +#include <windows.h> +#else +#include <pthread.h> +#endif + +namespace MTS { + + class Lock; + + //! A condition + /*! + A platform independent condition that can be waited on or signaled. Useful in building semaphores. + + \sa Lock + */ + class Condition: private NonCopyable { + friend class Lock; + + public: + ~Condition(); //!< Destructs the Condition + + void wait(); //!< Waits on *this Condition for signal + void wait(uint32_t millis); //!< Waits on *this Condition for signal or given amount of time + void signal(); //!< Signals *this Condition + + private: + + Lock* m_pLock; //!< Lock that created *this Condition +#ifdef WIN32 + AutoPtr<HANDLE> m_apCondition; //!< Handle to WIN32 Condition +#else + AutoPtr<pthread_cond_t> m_apCondition; //!< Handle to PTHREAD Condition +#endif + + explicit Condition(Lock* lock); //!< Explicit Constructor! Must pass Lock as parent. + }; +} + +#endif diff --git a/include/mts/MTS_Lock.h b/include/mts/MTS_Lock.h new file mode 100644 index 0000000..c35b131 --- /dev/null +++ b/include/mts/MTS_Lock.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Lock.h + \brief A mutex lock + \date 15JUN11 + \author Sean Godinez + + A platform independent mutex lock. + */ + +#ifndef _MTS_LOCK_H_ +#define _MTS_LOCK_H_ + +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_Condition.h> +#include <mts/MTS_AutoPtr.h> + +#ifdef WIN32 +#include <windows.h> +#else +#include <pthread.h> +#endif + +namespace MTS { + + //! A mutex lock + /*! + A platform independent mutex lock + + \sa Condition + */ + + class Lock: private NonCopyable { + + public: + Lock(); //!< Constructs the Lock + ~Lock(); //!< Destructs the Lock + + void lock(); //!< Locks the mutex + void unlock(); //!< Unlocks the mutex + + bool isLocked() const; //!< Returns true if locked + + Condition* createCondition(); //!< Creates a Condition object associated with *this Lock + + private: + friend class Condition; + volatile bool m_bLocked; //!< Locks the mutex +#ifdef WIN32 + AutoPtr<HANDLE> m_apMutex; //!< WIN32 Mutex Handle +#else + AutoPtr<pthread_mutex_t> m_apMutex; //!< PTHREAD Mutex Handle + AutoPtr<pthread_mutexattr_t> m_apMutexAttr; //!< PTHREAD Mutex Attributes +#endif + }; +} + +#endif diff --git a/include/mts/MTS_Logger.h b/include/mts/MTS_Logger.h new file mode 100644 index 0000000..a1e88a2 --- /dev/null +++ b/include/mts/MTS_Logger.h @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Logger.h + \brief A logging utility + \date 15JUN11 + \author Sean Godinez + + A logging utility capable of writing to stdout, syslog, or file + */ +#ifndef MTS_LOGGER_H_ +#define MTS_LOGGER_H_ + +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_NonConstructable.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_Stdint.h> +#include <string> + +#ifdef DEBUG +#define printFatal(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::FATAL_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::FATAL_LEVEL, MTS::Logger::PrintLevel::FATAL_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#define printError(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::ERROR_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::ERROR_LEVEL, MTS::Logger::PrintLevel::ERROR_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#define printWarning(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::WARNING_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::WARNING_LEVEL, MTS::Logger::PrintLevel::WARNING_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#define printInfo(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::INFO_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::INFO_LEVEL, MTS::Logger::PrintLevel::INFO_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#define printConfig(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::CONFIG_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::CONFIG_LEVEL, MTS::Logger::PrintLevel::CONFIG_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#define printDebug(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::DEBUG_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::DEBUG_LEVEL, MTS::Logger::PrintLevel::DEBUG_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#define printTrace(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::TRACE_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::TRACE_LEVEL, MTS::Logger::PrintLevel::TRACE_LABEL, "%s:%s:%d| " format, __FILE__, __func__, __LINE__, ##__VA_ARGS__) +#else +#define printFatal(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::FATAL_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::FATAL_LEVEL, MTS::Logger::PrintLevel::FATAL_LABEL, format, ##__VA_ARGS__) +#define printError(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::ERROR_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::ERROR_LEVEL, MTS::Logger::PrintLevel::ERROR_LABEL, format, ##__VA_ARGS__) +#define printWarning(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::WARNING_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::WARNING_LEVEL, MTS::Logger::PrintLevel::WARNING_LABEL, format, ##__VA_ARGS__) +#define printInfo(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::INFO_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::INFO_LEVEL, MTS::Logger::PrintLevel::INFO_LABEL, format, ##__VA_ARGS__) +#define printConfig(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::CONFIG_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::CONFIG_LEVEL, MTS::Logger::PrintLevel::CONFIG_LABEL, format, ##__VA_ARGS__) +#define printDebug(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::DEBUG_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::DEBUG_LEVEL, MTS::Logger::PrintLevel::DEBUG_LABEL, format, ##__VA_ARGS__) +#define printTrace(format, ...) \ + if (MTS::Logger::isPrintable(MTS::Logger::PrintLevel::TRACE_LEVEL)) \ + MTS::Logger::printfGeneric(MTS::Logger::PrintLevel::TRACE_LEVEL, MTS::Logger::PrintLevel::TRACE_LABEL, format, ##__VA_ARGS__) +#endif + +namespace MTS { + + class Logger: private NonCopyable { + + public: + + class PrintLevel: private NonConstructable { + public: + static const int32_t OFF_LEVEL; + static const int32_t MINIMUM_LEVEL; + static const int32_t FATAL_LEVEL; + static const int32_t ERROR_LEVEL; + static const int32_t WARNING_LEVEL; + static const int32_t INFO_LEVEL; + static const int32_t CONFIG_LEVEL; + static const int32_t DEBUG_LEVEL; + static const int32_t TRACE_LEVEL; + static const int32_t MAXIMUM_LEVEL; + + static const char* OFF_LABEL; + static const char* FATAL_LABEL; + static const char* ERROR_LABEL; + static const char* WARNING_LABEL; + static const char* INFO_LABEL; + static const char* CONFIG_LABEL; + static const char* DEBUG_LABEL; + static const char* TRACE_LABEL; + static const char* MAXIMUM_LABEL; + }; + + enum PrintMode { + NO_PRINTING, + STDOUT_ONLY, + FILE_ONLY, + SYSLOG_ONLY, + STDOUT_AND_FILE, + STDOUT_AND_SYSLOG + }; + + static int getPrintLevel(); + static const std::string& getPrintLevelString(); + static void setPrintLevel(int32_t level, bool silent = false); + static bool isPrintable(int32_t level); + + static void printfFatal(const char* format, ...); + static void printfError(const char* format, ...); + static void printfWarning(const char* format, ...); + static void printfInfo(const char* format, ...); + static void printfConfig(const char* format, ...); + static void printfDebug(const char* format, ...); + static void printfTrace(const char* format, ...); + static void printfGeneric(int level, const char* label, const char* format, ...); + + static void printf(int level, const char* format, ...); + static void printf(const char* format, ...); + + static bool setup(const PrintMode& mode); + static bool setup(const PrintMode& mode, const std::string& ident, const int& option, const int& facility); + static bool setup(const PrintMode& mode, const std::string& filename); + + private: + + static volatile int m_iPrintLevel; + static std::string m_sPrintLevel; + static Logger::PrintMode m_eMode; + static Lock m_oPrintLock; + static FILE* m_pFile; + static int m_iLogFacility; + static std::string m_sIdent; + static std::string m_sFileName; + + static int32_t syslogPrintLevelConversion(const int32_t& level); + static void printMessage(const int32_t& level, const char* label, const char* format, va_list argptr); + + Logger(); + }; +} + +#endif /* MTS_LOG_H_ */ diff --git a/include/mts/MTS_NonConstructable.h b/include/mts/MTS_NonConstructable.h new file mode 100644 index 0000000..ab69c1d --- /dev/null +++ b/include/mts/MTS_NonConstructable.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_NonConstructable.h + \brief Disables Constructors + \date May 7, 2012 + \author Sean Godinez + + Prevents this class from being constructed by anyone + */ + +#ifndef MTS_NONCONSTRUCTABLE_H_ +#define MTS_NONCONSTRUCTABLE_H_ + +namespace MTS { + + class NonConstructable { + protected: + + private: + // Do Not Allow Use of Any Constructors or the Assignment Operator + NonConstructable(); + ~NonConstructable(); + NonConstructable(const NonConstructable&); + const NonConstructable& operator=(const NonConstructable&); + }; + +} + +#endif /* MTS_NONCONSTRUCTABLE_H_ */ diff --git a/include/mts/MTS_NonCopyable.h b/include/mts/MTS_NonCopyable.h new file mode 100644 index 0000000..c5a772a --- /dev/null +++ b/include/mts/MTS_NonCopyable.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_NonCopyable.h + \brief Disables Copying + \date May 7, 2012 + \author Sean Godinez + + Prevents this class from being copied by anyone + */ +#ifndef _MTS_NONCOPYABLE_H_ +#define _MTS_NONCOPYABLE_H_ + +namespace MTS { + + class NonCopyable { + protected: + NonCopyable() { + } + ~NonCopyable() { + } + private: + // Do Not Allow Use of Copy Constructor or Assignment Operator + NonCopyable(const NonCopyable&); + const NonCopyable& operator=(const NonCopyable&); + }; + +} + +#endif /* _MTS_NONCOPYABLE_H_ */ diff --git a/include/mts/MTS_Object.h b/include/mts/MTS_Object.h new file mode 100644 index 0000000..4fd9d2d --- /dev/null +++ b/include/mts/MTS_Object.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Object.h + \brief An object + \date 28MAR12 + \author Sean Godinez + + A common base class to handle objects. + */ +#ifndef _MTS_OBJECT_H_ +#define _MTS_OBJECT_H_ + +#include <mts/MTS_Buffer.h> +#include <ostream> +#include <string> +#include <set> + +namespace MTS { + + //! An object + /*! + A common base class to handle objects + + \sa Buffer + */ + class Object { + + public: + virtual ~Object(); //!< Destructs object + + virtual void encode(Buffer& buffer) const = 0; //!< Encodes object into byte buffer + virtual void decode(Buffer& buffer) = 0; //!< Decodes object from byte buffer + virtual void copy(const Object& object) = 0; //!< Copies another object + virtual Object* clone() const = 0; //!< Clones object + + virtual std::string toString() const; //!< Generates a string of the object + virtual std::string toIDD() const; //!< Generates a string of the object type id + + protected: + Object(); //!< Constructor of object + }; +} + +#endif diff --git a/include/mts/MTS_Publisher.h b/include/mts/MTS_Publisher.h new file mode 100644 index 0000000..8b0fcee --- /dev/null +++ b/include/mts/MTS_Publisher.h @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Publisher.h + \brief An abstract publisher + \date 28MAR12 + \author Sean Godinez + + A publisher base class. Requires derived class to handle publishing. + */ +#ifndef _MTS_PUBLISHER_H_ +#define _MTS_PUBLISHER_H_ + +#include <mts/MTS_Subscriber.h> +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_Logger.h> +#include <mts/MTS_NonCopyable.h> +#include <set> + +namespace MTS { + + //! An abstract publisher + /*! + A template abstract publisher class + + \sa Subscriber + */ + template<class T> class Publisher: NonCopyable { + + public: + virtual ~Publisher(); //!< Destructs subscriber + + void addSubscriber(Subscriber<T>& subscriber); //!< Adds a subscriber + void removeSubscriber(Subscriber<T>& subscriber); //!< Removes a subscriber + + protected: + Publisher(); //!< Constructs publisher + virtual void publish(const T& object); //!< Protects publishing operation + + private: + typedef std::set<Subscriber<T>*> SubscriberSet; + + AutoPtr<Lock> m_apLock; //!< Guards for thread safety + SubscriberSet m_sSubscribers; //!< Set of subscribers + + }; + + template<class T> Publisher<T>::Publisher() { + m_apLock.reset(new Lock()); + } + + template<class T> Publisher<T>::~Publisher() { + m_apLock.reset(); + } + + template<class T> void Publisher<T>::addSubscriber( + Subscriber<T>& subscriber) { + + m_apLock->lock(); + m_sSubscribers.insert(&subscriber); + + /* + + //WARNING IF ALREADY PRESENT IN SET + pair<set<T>::iterator,bool> ret; + ret = m_sSubscribers.insert(&subscriber); + if (ret.second==false) { + Logger::printWarning("subscriber already in set %s (%p)", + subscriber->getName().c_str(), subscriber); + } + + */ + + m_apLock->unlock(); + } + + template<class T> void Publisher<T>::removeSubscriber( + Subscriber<T>& subscriber) { + m_apLock->lock(); + m_sSubscribers.erase(&subscriber); + + /* + + //WARNING IF SUBSCRIBER WAS NOT IN SET + uint32_t count = m_sSubscribers.erase(&subscriber); + if (count == 0) { + Logger::printWarning("subscriber was not in set %s (%p)", + subscriber->getName().c_str(), subscriber); + } + + */ + + m_apLock->unlock(); + } + + template<class T> void Publisher<T>::publish(const T& object) { + m_apLock->lock(); + SubscriberSet set(m_sSubscribers); + for (typename SubscriberSet::iterator i = set.begin(); i != set.end(); i++) { + Subscriber<T>* subscriber = *i; + try { + subscriber->update(object); + } catch (...) { + printWarning("Publisher| exception caught while updating subscriber %s (%p)", + subscriber->getName().c_str(), subscriber); + } + } + m_apLock->unlock(); + } +} + +#endif diff --git a/include/mts/MTS_Queue.h b/include/mts/MTS_Queue.h new file mode 100644 index 0000000..aa59e51 --- /dev/null +++ b/include/mts/MTS_Queue.h @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Queue.h + \brief A queue + \date 15JUN11 + \author Sean Godinez + + A thread-safe queue with condition signaling + */ +#ifndef _MTS_QUEUE_H_ +#define _MTS_QUEUE_H_ + +#include <mts/MTS_NonCopyable.h> +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_Logger.h> +#include <mts/MTS_Stdint.h> +#include <queue> +#include <cassert> + +namespace MTS { + + //! A queue + /*! + A thread-safe, blocking, template queue that signals when it is not empty, and when it is not full. + + \sa AutoPtr, Lock + */ + template<class T> class Queue : public NonCopyable { + + public: + explicit Queue(uint32_t capacity = UINT32_MAX); //!< Constructs the queue + ~Queue(); //!< Destructs the queue + + bool empty() const; //!< Returns true if queue is empty + bool full() const; //!< Returns true if queue is full + uint32_t size() const; //!< Returns the number of elements in the queue + uint32_t capacity() const; //!< Returns the maximum capacity of the queue + + void push(const T& object); //!< Pushes an object on the queue (BLOCKS IF FULL) + void pop(T& object); //!< Pops an object off the queue (BLOCKS IF EMPTY) + + bool offer(const T& object, uint32_t waitMillis); + bool poll(T& object, uint32_t waitMillis); + bool peek(T& object, uint32_t waitMillis); + + private: + const uint32_t m_iMaxSize; + std::queue<T> m_qContainer; + AutoPtr<Lock> m_apLock; + AutoPtr<Condition> m_apNotEmpty; + AutoPtr<Condition> m_apNotFull; + }; + + template<class T> Queue<T>::Queue(uint32_t capacity) + : m_iMaxSize(capacity) { + m_apLock.reset(new Lock()); + m_apNotEmpty.reset(m_apLock->createCondition()); + m_apNotFull.reset(m_apLock->createCondition()); + } + + template<class T> Queue<T>::~Queue() { + m_apNotFull.reset(); + m_apNotEmpty.reset(); + m_apLock.reset(); + } + + template<class T> bool Queue<T>::empty() const { + bool result = false; + m_apLock->lock(); + result = m_qContainer.empty(); + m_apLock->unlock(); + return result; + } + + template<class T> bool Queue<T>::full() const { + bool result = false; + m_apLock->lock(); + result = (m_qContainer.size() >= m_iMaxSize); + m_apLock->unlock(); + return result; + } + + template<class T> uint32_t Queue<T>::size() const { + uint32_t result = 0; + m_apLock->lock(); + result = static_cast<uint32_t>(m_qContainer.size()); + m_apLock->unlock(); + return result; + } + + template<class T> uint32_t Queue<T>::capacity() const { + return m_iMaxSize; + } + + template<class T> void Queue<T>::push(const T& object) { + // Block forever until there is room on the queue + m_apLock->lock(); + try { + while (m_qContainer.size() >= m_iMaxSize) { + m_apNotFull->wait(); + } + m_qContainer.push(object); + m_apNotEmpty->signal(); + } catch (...) { + printWarning("Queue| failed to push object"); + assert(false); + } + m_apLock->unlock(); + } + + template<class T> void Queue<T>::pop(T& object) { + //Block on not-empty condition if empty + m_apLock->lock(); + while (m_qContainer.empty()) { + m_apNotEmpty->wait(); + } + object = m_qContainer.front(); + m_qContainer.pop(); + m_apNotFull->signal(); + m_apLock->unlock(); + } + + //! Attempts to push an object onto the queue within the given milliseconds + /*! + \param object an object to push onto the queue + \param waitMillis the amount of milliseonds to wait if the queue is full + \return Returns true if the object was pushed onto the queue, false otherwise + \sa push() + */ + template<class T> bool Queue<T>::offer(const T& object, + uint32_t waitMillis) { + bool result = false; + m_apLock->lock(); + try { + if (waitMillis > 0 && m_qContainer.size() >= m_iMaxSize) { + m_apNotFull->wait(waitMillis); + } + if (m_qContainer.size() < m_iMaxSize) { + m_qContainer.push(object); + m_apNotEmpty->signal(); + result = true; + } + } catch (...) { + printWarning("Queue| failed to offer object"); + assert(false); + } + m_apLock->unlock(); + return result; + } + + //! Attempts to pop an object from the queue within the given milliseconds + /*! + \param object if successful, a reference to the object that was popped + \param waitMillis the amount of milliseonds to wait if the queue is empty + \return Returns true if an object was popped from the queue, false otherwise + \sa pop(), peek() + */ + template<class T> bool Queue<T>::poll(T& object, uint32_t waitMillis) { + bool result = false; + m_apLock->lock(); + if (waitMillis > 0 && m_qContainer.empty()) { + m_apNotEmpty->wait(waitMillis); + } + if (!m_qContainer.empty()) { + object = m_qContainer.front(); + m_qContainer.pop(); + m_apNotFull->signal(); + result = true; + } + m_apLock->unlock(); + return result; + } + + //! Attempts to view the top of the queue within the given milliseconds + /*! + \param object if successful, a reference to the object that is at the head of the queue + \param waitMillis the amount of milliseonds to wait if the queue is empty + \return Returns true if there is an object in the queue, false otherwise + \sa pop(), poll() + */ + template<class T> bool Queue<T>::peek(T& object, uint32_t waitMillis) { + bool result = false; + m_apLock->lock(); + if (waitMillis > 0 && m_qContainer.empty()) { + m_apNotEmpty->wait(waitMillis); + } + if (!m_qContainer.empty()) { + object = m_qContainer.front(); + result = true; + } + m_apLock->unlock(); + return result; + } +} + +#endif diff --git a/include/mts/MTS_SharedPtr.h b/include/mts/MTS_SharedPtr.h new file mode 100644 index 0000000..0fd670e --- /dev/null +++ b/include/mts/MTS_SharedPtr.h @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_SharedPtr.h + \brief A shared pointer template + \date 15JUN11 + \author Sean Godinez + + A shared pointer template + */ + +#ifndef _MTS_SHAREDPTR_H +#define _MTS_SHAREDPTR_H + +namespace MTS { + + //! A shared pointer + /*! + A shared pointer keeps track of references and + cleans up when the reference count reaches zero + */ + template<class T> class SharedPtr { + + public: + + enum MallocType { + SINGLE, ARRAY + }; + + explicit SharedPtr(T* ptr = 0, MallocType type = SINGLE); //!< Explicitly Constructs the SharedPtr to reference ptr + SharedPtr(const SharedPtr<T>& other); //!< Constructs from another shared pointer, increasing reference count + ~SharedPtr(); //!< Destructs the AutoPtr deleting T + + SharedPtr<T>& operator=(const SharedPtr<T>& other); //!< Releases *this and shares other's T + + T& operator*() const; //!< Returns T + T* operator->() const; //!< Returns address of T + T& operator[](const uint32_t& index) const; //!< Returns T at index + T* get() const; //!< Returns address of T + + bool isNull() const; //!< Returns true if pointer is NULL + bool isShared() const; //!< Returns true if reference count is greater than 1 + int count() const; //!< Returns number of references + + private: + + T* m_pObj; //!< Reference to class T + int* m_pReferences; //!< Reference to reference count + MallocType m_eType; //!< Describes memory allocated as a single T or block of Ts + + void release(); + }; + + template<class T> SharedPtr<T>::SharedPtr(T* ptr, MallocType type) + : m_pObj(ptr), m_pReferences(new int(1)), m_eType(type) { + } + + template<class T> SharedPtr<T>::SharedPtr(const SharedPtr<T>& other) + : m_pObj(other.m_pObj), m_pReferences(other.m_pReferences) { + *(m_pReferences) += 1; + } + + template<class T> SharedPtr<T>::~SharedPtr() { + release(); + } + + template<class T> SharedPtr<T>& SharedPtr<T>::operator=( + const SharedPtr<T>& other) { + if (&other != this) { + release(); + this->m_pObj = other.m_pObj; + this->m_pReferences = other.m_pReferences; + this->m_eType = other.m_eType; + (*m_pReferences) += 1; + } + return *this; + } + + template<class T> T& SharedPtr<T>::operator*() const { + return *m_pObj; + } + + template<class T> T* SharedPtr<T>::operator->() const { + return m_pObj; + } + + template<class T> T& SharedPtr<T>::operator[](const uint32_t& index) const { + return m_pObj[index]; + } + + template<class T> T* SharedPtr<T>::get() const { + return m_pObj; + } + + template<class T> bool SharedPtr<T>::isNull() const { + return (m_pObj == 0); + } + + template<class T> bool SharedPtr<T>::isShared() const { + return ((*m_pReferences) > 1); + } + + template<class T> int SharedPtr<T>::count() const { + return (*m_pReferences); + } + + template<class T> void SharedPtr<T>::release() { + (*m_pReferences) -= 1; + if ((*m_pReferences) == 0) { + if (m_eType == SINGLE) { + delete m_pObj; + } else { + delete[] m_pObj; + } + delete m_pReferences; + } + } +} + +#endif diff --git a/include/mts/MTS_SignalThread.h b/include/mts/MTS_SignalThread.h new file mode 100644 index 0000000..5f6aab4 --- /dev/null +++ b/include/mts/MTS_SignalThread.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_SignalThread.h + \brief An abstract worker thread + \date 01MAR13 + \author Mike Fiore + + A platform independent thread that executes a task when it is signaled. + */ + +#ifndef _MTS_SIGNAL_THREAD_H_ +#define _MTS_SIGNAL_THREAD_H_ + +#include <mts/MTS_Thread.h> +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_Condition.h> + +namespace MTS { + + //! An abstract worker thread + /*! + A platform independent worker thread class + */ + + class SignalThread: public Thread { + + public: + + ~SignalThread(); //!< Destructs the thread + + bool isExecuting() const; //!< Returns true if the thread is currently running executing the execute() function + + void signal(); //!< Instructs the thread to run the execute() function + + protected: + + explicit SignalThread(const std::string& name); //!< Creates the thread + explicit SignalThread(const std::string& name, uint32_t waitMillis); //!< Creates the thread + + private: + + void run(); //!< Abstracts the running of the thread + virtual void execute() = 0; //!< main() of the thread which is executed each time signal() is called + void init(); //!< Startup code common to all constructors + + AutoPtr<Lock> m_apStateLock; //!< Condition Lock + AutoPtr<Lock> m_apConditionLock; //!< Condition Lock + AutoPtr<Condition> m_apCondition; //!< Condition for signaling and waiting + bool m_bShouldExecute; //!< Should execute flag + bool m_bCurrentlyExecuting; //!< Currently executing flag + uint32_t m_ui32WaitMillis; //!< Max time to wait on condition before checking for shutdown + }; +} + +#endif diff --git a/include/mts/MTS_Singleton.h b/include/mts/MTS_Singleton.h new file mode 100644 index 0000000..463d1c0 --- /dev/null +++ b/include/mts/MTS_Singleton.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Singleton.h + \brief A Documented file. + \date 2011-06-20 + \author Sean Godinez + + Details. + */ + +#ifndef _MTS_SINGLETON_H_ +#define _MTS_SINGLETON_H_ + +#include <mts/MTS_Lock.h> + +namespace MTS { + + template<class T> class Singleton { + + public: + + static T* instance(); + + protected: + + private: + static T* m_pInstance; + static AutoPtr<Lock> m_apLock; + + // Do Not Allow Use of Any Constructor or Assignment Operator + Singleton() { + } + ~Singleton(); + Singleton(const Singleton&); + Singleton& operator=(const Singleton&); + }; + + template<class T> Singleton<T>::~Singleton() { + m_apLock.reset(); + delete T; + } + + template<class T> T* Singleton<T>::instance() { + + m_apLock->lock(); + if (m_pInstance == NULL) { + m_pInstance = new T(); + } + m_apLock->unlock(); + + return m_pInstance; + } + + //FIXME: Template Initialization + template<class T> static AutoPtr<Lock> Singleton<T>::m_apLock.reset(new Lock()); + template<class T> static T* Singleton<T>::m_pInstance = NULL; +} + +#endif /* MTS_SINGLETON_H_ */ diff --git a/include/mts/MTS_Stdint.h b/include/mts/MTS_Stdint.h new file mode 100644 index 0000000..9a6885b --- /dev/null +++ b/include/mts/MTS_Stdint.h @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Stdint.h + \brief A set of defined types + \date 28MAR12 + \author Sean Godinez + + A set of defined types + */ +#ifndef MTS_STDINT_H +#define MTS_STDINT_H + +#ifdef WIN32 +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; + +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +#ifndef INT8_MIN +#define INT8_MIN (-127i8 - 1) +#endif + +#ifndef INT16_MIN +#define INT16_MIN (-32767i16 - 1) +#endif + +#ifndef INT32_MIN +#define INT32_MIN (-2147483647i32 - 1) +#endif + +#ifndef INT64_MIN +#define INT64_MIN (-9223372036854775807i64 - 1) +#endif + +#ifndef INT8_MAX +#define INT8_MAX (127i8) +#endif + +#ifndef INT16_MAX +#define INT16_MAX (32767i16) +#endif + +#ifndef INT32_MAX +#define INT32_MAX (2147483647i32) +#endif + +#ifndef INT64_MAX +#define INT64_MAX (9223372036854775807i64) +#endif + +#ifndef UINT8_MAX +#define UINT8_MAX (0xffui8) +#endif + +#ifndef UINT16_MAX +#define UINT16_MAX (0xffffui16) +#endif + +#ifndef UINT32_MAX +#define UINT32_MAX (0xffffffffui32) +#endif + +#ifndef UINT64_MAX +#define UINT64_MAX (0xffffffffffffffffui64) +#endif + +#elif __cplusplus +#ifdef STDINT +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS +#endif +#include <stdint.h> +#else +#include <cstdint> +#endif +#else +#include <stdint.h> +#endif + +#endif + diff --git a/include/mts/MTS_Subscriber.h b/include/mts/MTS_Subscriber.h new file mode 100644 index 0000000..e359d4c --- /dev/null +++ b/include/mts/MTS_Subscriber.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Subscriber.h + \brief An abstract subscriber + \date 28MAR12 + \author Sean Godinez + + A subscriber. + */ +#ifndef _MTS_SUBSCRIBER_H_ +#define _MTS_SUBSCRIBER_H_ + +#include <mts/MTS_NonCopyable.h> +#include <string> + +namespace MTS { + + //! An abstract subscriber + /*! + A template abstract subscriber class + + \sa Publisher + */ + template<class T> class Subscriber: NonCopyable { + + public: + virtual ~Subscriber(); //!< Destructs subscriber + + const std::string& getName() const; //!< Returns name + + virtual void update(const T& object) = 0; //!< Updates subscriber + + protected: + explicit Subscriber(const std::string& name = ""); //!< Protected Constructor + + private: + const std::string m_sName; //!< Name of subscriber + + }; + + template<class T> Subscriber<T>::Subscriber(const std::string& name) + : m_sName(name) { + } + + template<class T> Subscriber<T>::~Subscriber() { + } + + template<class T> const std::string& Subscriber<T>::getName() const { + return m_sName; + } +} + +#endif diff --git a/include/mts/MTS_SubscriberQueue.h b/include/mts/MTS_SubscriberQueue.h new file mode 100644 index 0000000..d070841 --- /dev/null +++ b/include/mts/MTS_SubscriberQueue.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_SubscriberQueue.h + \brief An template subscriber queue + \date 28MAR12 + \author Sean Godinez + + A subscriber queue. + */ + +#ifndef _MTS_SUBSCRIBERQUEUE_H_ +#define _MTS_SUBSCRIBERQUEUE_H_ + +#include <mts/MTS_Subscriber.h> +#include <mts/MTS_Queue.h> +#include <mts/MTS_Stdint.h> +#include <new> + +namespace MTS { + + template<class T> class SubscriberQueue: public Subscriber<T> { + + public: + explicit SubscriberQueue(const std::string& name, uint32_t capacity = UINT32_MAX); + virtual ~SubscriberQueue(); + + Queue<T*>& getQueue(); + void clear(); + + virtual void update(const T& object); + + private: + Queue<T*> m_oQueue; + + //Prevent Copy and Assignment operators from being called + SubscriberQueue(const SubscriberQueue&); + SubscriberQueue& operator=(const SubscriberQueue&); + }; + + template<class T> SubscriberQueue<T>::SubscriberQueue( + const std::string& name, uint32_t capacity) + : Subscriber<T>(name), m_oQueue(capacity) { + } + + template<class T> SubscriberQueue<T>::~SubscriberQueue() { + clear(); + } + + template<class T> Queue<T*>& SubscriberQueue<T>::getQueue() { + return m_oQueue; + } + + template<class T> void SubscriberQueue<T>::clear() { + while (!m_oQueue.empty()) { + T* object = 0; + m_oQueue.poll(object, 0); + delete object; + } + } + + template<class T> void SubscriberQueue<T>::update(const T& object) { + T* clone = object.clone(); + if (clone == 0) { + printWarning("SubQ| %s failed to clone object, out of memory", Subscriber<T>::getName().c_str()); + return; + } + bool ok = m_oQueue.offer(clone, 0); + if (!ok) { + delete clone; + printWarning("SubQ| %s queue full, dropping object", Subscriber<T>::getName().c_str()); + return; + } + } +} + +#endif diff --git a/include/mts/MTS_System.h b/include/mts/MTS_System.h new file mode 100644 index 0000000..a16265c --- /dev/null +++ b/include/mts/MTS_System.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_System.h + \brief System Utilities + \date 15JUN11 + \author Sean Godinez + + System utilities for time, endian, etc. + */ +#ifndef MTS_SYSTEM_H +#define MTS_SYSTEM_H + +#include <mts/MTS_NonConstructable.h> +#include <mts/MTS_Stdint.h> +#include <string> + +namespace MTS { + + class System: private NonConstructable { + + public: + + //UTC (Coordinated Universal Time) : This is the standard international time or the Greenwich Mean Time. + //EPOCH : number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time. + + static uint64_t timeMicros(); + static uint64_t precisionTimeMicros(); + + static bool isBigEndian(); + static void swapBytes(uint8_t* const pBuffer, const uint32_t iSize); + + static int32_t cmd(const std::string& cmd, std::string& result); + static int32_t readFile(const std::string& path, std::string& result); + }; +} + +#endif diff --git a/include/mts/MTS_Text.h b/include/mts/MTS_Text.h new file mode 100644 index 0000000..2380add --- /dev/null +++ b/include/mts/MTS_Text.h @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Text.h + \brief A set of string formatting utilities + \date 15JUN11 + \author Sean Godinez + + A set of string formatting utilities + */ + +#ifndef MTS_TEXT_H_ +#define MTS_TEXT_H_ + +#include <mts/MTS_NonConstructable.h> +#include <mts/MTS_Stdint.h> +#include <mts/MTS_Buffer.h> +#include <sstream> +#include <string> +#include <vector> +#include <time.h> + +namespace MTS { + + class Text: private NonConstructable { + + public: + + enum DATEFORMAT { + MMsDDsYY, //MM/DD/YYYY + MMsDDsYY_HHcMMcSS, //MM/DD/YYYY HH:MM:SS:mmm + RFC_1123 //Wdy, DD Mon YYYY HH:MM:SS GMT (Thu, 01 Jan 1970 00:00:01 GMT) + }; + + enum TIMEFORMAT { + HHcMMcSScmmm, //HH:MM:SS:mmm + HHcMMcSS //HH:MM:SS + }; + + static const uint8_t RDSTATE_SUCCESS_MASK = 0x02; //Only OEF bit + + static std::string time(const uint64_t& iTimeMicros, const TIMEFORMAT& eTime = HHcMMcSScmmm); + static std::string date(const tm& stTime, const DATEFORMAT& eDate = MMsDDsYY); + static bool datetimeIsBefore(const std::string& time1, const std::string& time2); + + static std::vector<std::string> split(const std::string& str, char delimiter, int limit = 0); + static std::vector<std::string> split(const std::string& str, const std::string& delimiter, int limit = 0); + static std::string join(std::vector<std::string> list, char delimiter); + static std::string replace(const std::string& str, const std::string& from, const std::string& to); + static uint32_t count(const std::string& str, const std::string& element); + static uint32_t count(const std::string& str, const uint8_t& element); + static bool endsWith(const std::string& str, const std::string& key); + + static std::string getLine(const std::string& source, const size_t& start, size_t& cursor); + + static std::string trim(const std::string& str); + static std::string trim(const std::string& str, const uint8_t& element); + static std::string strip(const std::string& str, const std::vector<uint8_t>& elements); + static std::string strip(const std::string& str, const uint8_t& element); + + static std::string toLowerCase(const std::string& str); + static std::string toUpperCase(const std::string& str); + static std::string toCapitalized(const std::string& str); + static std::string toCamelCase(const std::string& str); + static std::string toCommandLineEscaped(const std::string& str); + + static std::wstring widen(const std::string& str); + static std::string narrow(const std::wstring& str); + + static std::string format(bool value); + static std::string format(double value, std::streamsize percision = 6); + + static std::string format(int8_t value); + static std::string format(int16_t value); + static std::string format(int32_t value); + static std::string format(int64_t value); + + static std::string format(uint8_t value); + static std::string format(uint16_t value); + static std::string format(uint32_t value); + static std::string format(uint64_t value); + + static std::string formatHex(int8_t value, bool pad = false); + static std::string formatHex(int16_t value, bool pad = false); + static std::string formatHex(int32_t value, bool pad = false); + static std::string formatHex(int64_t value, bool pad = false); + + static std::string formatHex(uint8_t value, bool pad = false); + static std::string formatHex(uint16_t value, bool pad = false); + static std::string formatHex(uint32_t value, bool pad = false); + static std::string formatHex(uint64_t value, bool pad = false); + + static std::string formatHex(const Buffer& value); + + static bool parse(bool& value, const std::string& str); + static bool parse(double& value, const std::string& str); + + static bool parse(int8_t& value, const std::string& str); + static bool parse(int16_t& value, const std::string& str); + static bool parse(int32_t& value, const std::string& str); + static bool parse(int64_t& value, const std::string& str); + + static bool parse(uint8_t& value, const std::string& str); + static bool parse(uint16_t& value, const std::string& str); + static bool parse(uint32_t& value, const std::string& str); + static bool parse(uint64_t& value, const std::string& str); + + static bool parseHex(uint8_t& value, const std::string& str); + static bool parseHex(uint16_t& value, const std::string& str); + static bool parseHex(uint32_t& value, const std::string& str); + static bool parseHex(uint64_t& value, const std::string& str); + + template<typename S, typename T> + static bool lexicalCast(S source, T& target) { + std::stringstream interpreter; + if(!(interpreter << source) || + !(interpreter >> target) || + !(interpreter >> std::ws).eof()) { + return false; + } + return true; + } + }; +} + +#endif diff --git a/include/mts/MTS_Thread.h b/include/mts/MTS_Thread.h new file mode 100644 index 0000000..7a3472c --- /dev/null +++ b/include/mts/MTS_Thread.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_Thread.h + \brief A thread + \date 15JUN11 + \author Sean Godinez + + A platform independent thread. + */ +#ifndef _MTS_THREAD_H_ +#define _MTS_THREAD_H_ + +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_Condition.h> +#include <mts/MTS_Stdint.h> +#include <mts/MTS_NonCopyable.h> +#include <string> + +#ifdef WIN32 +#include <windows.h> +#else +#include <pthread.h> +#endif + +namespace MTS { + + //! An abstract thread + /*! + A platform independent abstract thread class + + \sa Condition, Lock + */ + + class Thread: private NonCopyable { + + public: + + virtual ~Thread(); //!< Destructs thread + + static void sleep(uint32_t iMillis); //!< Pauses calling thread for the given amount of milliseconds + + const std::string& getName() const; //!< Returns the name of thread + + virtual void start(); //!< Starts thread + virtual void stop(); //!< Ends thread + + void wait(); //!< Block until *this thread has finished executing + void wait(uint32_t millis); //!< Waits on signal for *this thread to finish executing or time is up + + bool isAlive() const; //!< Returns true if it is still running + bool isCanceled() const; //!< Returns true if it has been told to shutdown + bool isDone() const; //!< Returns true if it finished running + bool isManaged() const; //!< Returns true if it should not Destruct itself when done running + + protected: + explicit Thread(const std::string& name, bool managed = true); //!< Explicit Constructor + + private: + +#ifdef WIN32 + static DWORD WINAPI doInBackground(__in LPVOID lpParameter); //!< WIN32 function callback + HANDLE m_pThread;//!< WIN32 Thread Handle +#else + static void* doInBackground(void* parameters); //!< PTHREAD function callback + pthread_t* m_pThread; //!< PTHREAD Thread Handle +#endif + + const std::string m_sName; //!< Thread's name + const bool m_bManaged; //!< Self-cleanup flag + bool m_bComplete; //!< Completed flag + bool m_bCanceled; //!< Canceled/Shutdown flag + + AutoPtr<Lock> m_apThreadLock; //!< Thread Lock + AutoPtr<Lock> m_apStateLock; //!< State Lock + AutoPtr<Condition> m_apCompleteCondition; //!< Thread Completed Condition/Signal + + void cancel(); //!< Cancels thread by setting Canceled/Shutdown flag + void done(); //!< Triggers Thread Completed Condition/Signal + void reset(); //!< Resets Canceled and Completed flags + + + virtual void run() = 0; //!< main() of *this Thread + }; +} + +#endif diff --git a/include/mts/MTS_Timer.h b/include/mts/MTS_Timer.h new file mode 100644 index 0000000..3f0b0e5 --- /dev/null +++ b/include/mts/MTS_Timer.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! + \file MTS_Timer.h + \brief Tracks passage of time + \date Jan 3, 2014 + \author sgodinez + + Useful for tracking time and timeout loops + */ + +#ifndef MTS_TIMER_H_ +#define MTS_TIMER_H_ + +#include <mts/MTS_Stdint.h> + +namespace MTS { + + class Timer { + + public: + Timer(); + virtual ~Timer(); + + void start(); + void stop(); + void pause(); + void resume(); + void reset(); + + bool isRunning(); + + uint64_t getMicros(); + uint64_t getMillis(); + uint64_t getSeconds(); + uint64_t getMinutes(); + + protected: + + private: + uint64_t m_iStart; + uint64_t m_iPause; + bool m_bStarted; + bool m_bPaused; + }; +} + +#endif /* MTS_TIMER_H_ */ diff --git a/include/mts/MTS_TimerThread.h b/include/mts/MTS_TimerThread.h new file mode 100644 index 0000000..28e3e73 --- /dev/null +++ b/include/mts/MTS_TimerThread.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/*! \file MTS_TimerThread.h + \brief An abstract worker thread + \date 10MAY13 + \author Mike Fiore + + A platform independent thread that executes a task every x miliseconds. + Thread can be paused and unpaused. + */ + +#ifndef _MTS_TIMER_THREAD_H_ +#define _MTS_TIMER_THREAD_H_ + +#include <mts/MTS_Thread.h> +#include <mts/MTS_AutoPtr.h> +#include <mts/MTS_Lock.h> + +namespace MTS { + + //! An abstract worker thread + /*! + A platform independent worker thread class + */ + + class TimerThread: public Thread { + + public: + + ~TimerThread(); //!< Destructs the thread + + virtual bool isExecuting() const; //!< Returns true if the thread has been started + + virtual void stopExecution(); //!< Stops running execute() function + + virtual void restartExecution(); //!< Resumes running execute() function + + virtual void updateIntervalMillis(uint32_t newMillis); //!< Updates interval to given value + + protected: + + explicit TimerThread(const std::string& name); //!< Creates the thread + + explicit TimerThread(const std::string& name, uint32_t intervalMillis); //!< Creates the thread + + private: + + void run(); //!< Abstracts the running of the thread + virtual void execute() = 0; //!< main() of the thread which is executed once per interval + void init(); //!< Startup code common to all constructors + + AutoPtr<Lock> m_apStateLock; //!< Condition Lock + bool m_bCurrentlyExecuting; //!< Currently executing flag + bool m_bExecutionStopped; //!< Execution stopped flag + uint32_t m_ui32IntervalMillis; //!< How often the thread executes + }; +} + +#endif diff --git a/src/MTS_Buffer.cpp b/src/MTS_Buffer.cpp new file mode 100644 index 0000000..91ece42 --- /dev/null +++ b/src/MTS_Buffer.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Buffer.h> +#include <stdexcept> +#include <string> + +using namespace MTS; + +const uint32_t Buffer::DEFAULT_CAPACITY = 80; + +Buffer::Buffer(uint32_t capacity) { + setCapacity(capacity); +} + +Buffer::Buffer(const uint8_t* bytes, uint32_t count) +: m_vBuffer(bytes, bytes + count) { + +} + +Buffer::Buffer(const Buffer& other) +: m_vBuffer(other.m_vBuffer.begin(), other.m_vBuffer.end()) { + +} + +Buffer::~Buffer() { + +} + +Buffer& +Buffer::operator=(const Buffer& other) { + if (&other == this) { + return *this; + } + m_vBuffer = other.m_vBuffer; + return *this; +} + +const uint8_t* +Buffer::getBuffer() const { + return &m_vBuffer.at(0); +} + +std::string Buffer::str() const { + return std::string(reinterpret_cast<const char*>(&m_vBuffer.at(0)), m_vBuffer.size()); +} + +uint32_t Buffer::getSize() const { + return m_vBuffer.size(); +} + +void Buffer::setSize(uint32_t newSize) { + m_vBuffer.resize(newSize); +} + +uint32_t Buffer::getCapacity() const { + return m_vBuffer.capacity(); +} + +void Buffer::setCapacity(uint32_t newCapacity) { + m_vBuffer.reserve(newCapacity); +} + +void Buffer::clear() { + m_vBuffer.clear(); +} + +void Buffer::compact() { + m_vBuffer.resize(m_vBuffer.size()); +} + +uint8_t Buffer::operator[](uint32_t index) const { + return m_vBuffer[index]; +} + +uint8_t Buffer::operator[](uint32_t index) { + return m_vBuffer[index]; +} + +const uint8_t& +Buffer::at(uint32_t index) const { + return m_vBuffer.at(index); +} + +uint8_t& +Buffer::at(uint32_t index) { + return m_vBuffer.at(index); +} + +Buffer& +Buffer::append(uint8_t byte) { + m_vBuffer.push_back(byte); + return *this; +} + +Buffer& Buffer::append(const uint8_t* bytes, uint32_t count) { + m_vBuffer.resize(m_vBuffer.size() + count); + std::copy(bytes, bytes + count, std::back_inserter(m_vBuffer)); + return *this; +} + +Buffer& +Buffer::insert(uint32_t index, uint8_t byte) { + m_vBuffer.insert(m_vBuffer.begin() + index, byte); + return *this; +} + +Buffer& +Buffer::insert(uint32_t index, const uint8_t* bytes, uint32_t count) { + m_vBuffer.insert(m_vBuffer.begin() + index, bytes, bytes + count); + return *this; +} + +Buffer& +Buffer::remove(uint32_t index) { + m_vBuffer.erase(m_vBuffer.begin() + index); + return *this; +} + +Buffer& +Buffer::remove(uint32_t start, uint32_t end) { + m_vBuffer.erase(m_vBuffer.begin() + start, m_vBuffer.begin() + end); + return *this; +} + +Buffer& +Buffer::replace(uint32_t start, uint32_t end, const uint8_t* bytes, +uint32_t count) { + if (end - start == count) { + if (start > end || end > m_vBuffer.size()) { + throw std::out_of_range("Buffer| index out of bounds"); + } + std::copy(bytes, bytes + count, m_vBuffer.begin()); + return *this; + } + return remove(start, end).insert(start, bytes, count); +} + +Buffer* Buffer::clone() const { + return new Buffer(*this); +} + diff --git a/src/MTS_Condition.cpp b/src/MTS_Condition.cpp new file mode 100644 index 0000000..d238d50 --- /dev/null +++ b/src/MTS_Condition.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Condition.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_System.h> +#include <mts/MTS_Logger.h> +#include <cassert> +#include <cerrno> +#include <stdexcept> + +using namespace MTS; + +Condition::Condition(Lock* pLock) +: m_pLock(pLock) { + if (pLock == 0) { + throw std::invalid_argument("Condition| constructing lock is null"); + } +#ifdef WIN32 + m_apCondition.reset(CreateEvent(NULL, FALSE, FALSE, NULL)); + if (m_pCondition.get() == NULL) { + throw std::bad_alloc(); + } +#else + m_apCondition.reset(new pthread_cond_t()); + const uint32_t result = pthread_cond_init(m_apCondition.get(), NULL); + if (result != 0) { + throw std::runtime_error("Condition| failed to initialize condition"); + } +#endif +} + +Condition::~Condition() { + if (!m_apCondition.isNull()) { +#ifdef WIN32 + const BOOL ok = CloseHandle(m_apCondition.get()); + assert(ok); +#else + const uint32_t result = pthread_cond_destroy(m_apCondition.get()); + if (result != 0) { + printWarning("Condition| failed to destroy condition"); + } + assert(result == 0); +#endif + } +} + +void Condition::wait() { +#ifdef WIN32 + wait(INFINITE); +#else + const uint32_t result = pthread_cond_wait(m_apCondition.get(), + m_pLock->m_apMutex.get()); + if (result != 0) { + printWarning("Condition| failed to wait on condition"); + } + assert(result == 0); +#endif +} + +void Condition::wait(uint32_t millis) { + assert(m_pLock->isLocked()); + if(!m_pLock->isLocked()) { + printWarning("Condition| lock was not locked. not waiting on signal."); + return; + } +#ifdef WIN32 + ResetEvent(m_apCondition.get()); + m_pLock->unlock(); + const DWORD waitResult = WaitForSingleObject(m_apCondition.get(), millis); + assert(waitResult == WAIT_OBJECT_0 || waitResult == WAIT_TIMEOUT); + m_pLock->lock(); +#else + timespec abstime; + int64_t micros = System::timeMicros() + (millis * 1000); + abstime.tv_sec = static_cast<long>(micros / 1000000); + abstime.tv_nsec = static_cast<long>((micros % 1000000) * 1000); + const uint32_t result = pthread_cond_timedwait(m_apCondition.get(), + m_pLock->m_apMutex.get(), &abstime); + if (result != 0 && result != ETIMEDOUT) { + printWarning("Condition| failed to time wait on condition"); + } + assert(result == 0 || result == ETIMEDOUT); +#endif +} + +void Condition::signal() { +#ifdef WIN32 + const BOOL ok = SetEvent(m_apCondition.get()); + assert(ok); +#else + const uint32_t result = pthread_cond_broadcast(m_apCondition.get()); + if (result != 0) { + printWarning("Condition| failed to signal condition"); + } + assert(result == 0); +#endif +} diff --git a/src/MTS_Lock.cpp b/src/MTS_Lock.cpp new file mode 100644 index 0000000..dc2e7c0 --- /dev/null +++ b/src/MTS_Lock.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Lock.h> +#include <mts/MTS_Logger.h> +#include <cassert> +#include <stdexcept> + +using namespace MTS; + +Lock::Lock() +: m_bLocked(false) { +#ifdef WIN32 + m_apMutex.reset(CreateMutex(NULL, FALSE, NULL)); + if (m_apMutex.get() == NULL) { + throw std::bad_alloc(); + } +#else + m_apMutexAttr.reset(new pthread_mutexattr_t()); + int result = pthread_mutexattr_init(m_apMutexAttr.get()); + if (result != 0) { + throw std::runtime_error("failed to initialize mutex attributes"); + } + result = pthread_mutexattr_settype(m_apMutexAttr.get(), + PTHREAD_MUTEX_RECURSIVE); + if (result != 0) { + throw std::runtime_error("failed to set mutex recursive"); + } + m_apMutex.reset(new pthread_mutex_t()); + result = pthread_mutex_init(m_apMutex.get(), m_apMutexAttr.get()); + if (result != 0) { + throw std::runtime_error("failed to initialize mutex"); + } +#endif + +} + +Lock::~Lock() { + if (isLocked()) { + unlock(); + } +#ifdef WIN32 + const BOOL ok = CloseHandle(m_apMutex.release()); + assert(ok); +#else + if (!m_apMutex.isNull()) { + const int result = pthread_mutex_destroy(m_apMutex.get()); + if (result != 0) { + printWarning("Lock| Failed to destroy mutex"); + } + assert(result == 0); + } + if (!m_apMutexAttr.isNull()) { + const int result = pthread_mutexattr_destroy(m_apMutexAttr.get()); + if (result != 0) { + printWarning("Lock| Failed to destroy mutex attributes"); + } + assert(result == 0); + } +#endif +} + +void Lock::lock() { +#ifdef WIN32 + const DWORD waitResult = WaitForSingleObject(m_apMutex.get(), INFINITE); + assert(waitResult == WAIT_OBJECT_0); +#else + const int result = pthread_mutex_lock(m_apMutex.get()); + if (result != 0) { + printWarning("Lock| Failed to lock mutex"); + } + assert(result == 0); +#endif + m_bLocked = true; +} + +void Lock::unlock() { + m_bLocked = false; +#ifdef WIN32 + const BOOL ok = ReleaseMutex(m_apMutex.get()); + assert(ok); +#else + const int result = pthread_mutex_unlock(m_apMutex.get()); + if (result != 0) { + printWarning("Lock| Failed to unlock mutex"); + } + assert(result == 0); +#endif +} + +bool Lock::isLocked() const { + return m_bLocked; +} + +Condition* Lock::createCondition() { + return new Condition(this); +} diff --git a/src/MTS_Logger.cpp b/src/MTS_Logger.cpp new file mode 100644 index 0000000..93775fe --- /dev/null +++ b/src/MTS_Logger.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Logger.h> +#include <mts/MTS_Lock.h> +#include <mts/MTS_Text.h> +#include <mts/MTS_System.h> +#include <stdio.h> +#include <errno.h> +#include <stdarg.h> +#include <syslog.h> + +#include <iostream> + +using namespace MTS; + +const char* Logger::PrintLevel::OFF_LABEL = "OFF"; +const char* Logger::PrintLevel::FATAL_LABEL = "FATAL"; +const char* Logger::PrintLevel::ERROR_LABEL = "ERROR"; +const char* Logger::PrintLevel::WARNING_LABEL = "WARNING"; +const char* Logger::PrintLevel::INFO_LABEL = "INFO"; +const char* Logger::PrintLevel::CONFIG_LABEL = "CONFIG"; +const char* Logger::PrintLevel::DEBUG_LABEL = "DEBUG"; +const char* Logger::PrintLevel::TRACE_LABEL = "TRACE"; +const char* Logger::PrintLevel::MAXIMUM_LABEL = "MAXIMUM"; + +const int Logger::PrintLevel::OFF_LEVEL = 0; +const int Logger::PrintLevel::MINIMUM_LEVEL = 1; +const int Logger::PrintLevel::FATAL_LEVEL = 1; +const int Logger::PrintLevel::ERROR_LEVEL = 10; +const int Logger::PrintLevel::WARNING_LEVEL = 20; +const int Logger::PrintLevel::INFO_LEVEL = 30; +const int Logger::PrintLevel::CONFIG_LEVEL = 40; +const int Logger::PrintLevel::DEBUG_LEVEL = 50; +const int Logger::PrintLevel::TRACE_LEVEL = 60; +const int Logger::PrintLevel::MAXIMUM_LEVEL = 100; + +volatile int Logger::m_iPrintLevel = Logger::PrintLevel::MAXIMUM_LEVEL; +std::string Logger::m_sPrintLevel = Logger::PrintLevel::MAXIMUM_LABEL; +Logger::PrintMode Logger::m_eMode = Logger::PrintMode::STDOUT_ONLY; +FILE* Logger::m_pFile = NULL; +int Logger::m_iLogFacility = -1; +Lock Logger::m_oPrintLock; +std::string Logger::m_sIdent; +std::string Logger::m_sFileName; + +int Logger::getPrintLevel() { + return m_iPrintLevel; +} + +const std::string& Logger::getPrintLevelString() { + if (m_iPrintLevel == PrintLevel::OFF_LEVEL) + m_sPrintLevel = std::string(PrintLevel::OFF_LABEL); + else if (m_iPrintLevel == PrintLevel::FATAL_LEVEL) + m_sPrintLevel = std::string(PrintLevel::FATAL_LABEL); + else if (m_iPrintLevel > PrintLevel::FATAL_LEVEL && m_iPrintLevel <= PrintLevel::ERROR_LEVEL) + m_sPrintLevel = std::string(PrintLevel::ERROR_LABEL); + else if (m_iPrintLevel > PrintLevel::ERROR_LEVEL && m_iPrintLevel <= PrintLevel::WARNING_LEVEL) + m_sPrintLevel = std::string(PrintLevel::WARNING_LABEL); + else if (m_iPrintLevel > PrintLevel::WARNING_LEVEL && m_iPrintLevel <= PrintLevel::INFO_LEVEL) + m_sPrintLevel = std::string(PrintLevel::INFO_LABEL); + else if (m_iPrintLevel > PrintLevel::INFO_LEVEL && m_iPrintLevel <= PrintLevel::CONFIG_LEVEL) + m_sPrintLevel = std::string(PrintLevel::CONFIG_LABEL); + else if (m_iPrintLevel > PrintLevel::CONFIG_LEVEL && m_iPrintLevel <= PrintLevel::DEBUG_LEVEL) + m_sPrintLevel = std::string(PrintLevel::DEBUG_LABEL); + else if (m_iPrintLevel > PrintLevel::DEBUG_LEVEL && m_iPrintLevel <= PrintLevel::TRACE_LEVEL) + m_sPrintLevel = std::string(PrintLevel::TRACE_LABEL); + else + m_sPrintLevel = std::string(PrintLevel::MAXIMUM_LABEL); + + return m_sPrintLevel; +} + +void Logger::setPrintLevel(int32_t level, bool silent) { + m_iPrintLevel = level; + if (!silent) { + printf(level, "Logger Level Changed to %d\n", level); + } +} + +bool Logger::isPrintable(int32_t level) { + int32_t currentLevel = getPrintLevel(); + return (level <= currentLevel) && (currentLevel > PrintLevel::OFF_LEVEL); +} + +int32_t Logger::syslogPrintLevelConversion(const int32_t& level) { + if (level < 10) { + return LOG_EMERG; + } else if (level < 20) { + return LOG_ERR; + } else if (level < 30) { + return LOG_WARNING; + } else if (level < 50) { + return LOG_INFO; + } else { + return LOG_DEBUG; + } +} + +void Logger::printMessage(const int32_t& level, const char* label, const char* format, va_list argptr) { + + m_oPrintLock.lock(); + switch (m_eMode) { + case Logger::PrintMode::STDOUT_ONLY: + ::printf("%s|%s|", MTS::Text::time(MTS::System::timeMicros()).c_str(), label); + vprintf(format, argptr); + ::printf("\n"); + break; + + case Logger::PrintMode::FILE_ONLY: + fprintf(m_pFile, "%s|%s| ", MTS::Text::time(MTS::System::timeMicros()).c_str(), label); + vfprintf(m_pFile, format, argptr); + fprintf(m_pFile, "\n"); + fflush(m_pFile); + break; + + case Logger::PrintMode::SYSLOG_ONLY: + if (level <= Logger::PrintLevel::TRACE_LEVEL) { + vsyslog(syslogPrintLevelConversion(level), format, argptr); + } + break; + + case Logger::PrintMode::STDOUT_AND_FILE: { + const std::string timestr(MTS::Text::time(MTS::System::timeMicros())); + va_list argptr2; + va_copy(argptr2, argptr); + ::printf("%s|%s|", timestr.c_str(), label); + vprintf(format, argptr); + ::printf("\n"); + fprintf(m_pFile, "%s|%s| ", timestr.c_str(), label); + vfprintf(m_pFile, format, argptr2); + fprintf(m_pFile, "\n"); + fflush(m_pFile); + va_end(argptr2); + } + break; + + case Logger::PrintMode::STDOUT_AND_SYSLOG: { + if (level <= Logger::PrintLevel::TRACE_LEVEL) { + va_list argptr2; + va_copy(argptr2, argptr); + vsyslog(syslogPrintLevelConversion(level), format, argptr2); + va_end(argptr2); + } + ::printf("%s|", MTS::Text::time(MTS::System::timeMicros()).c_str()); + ::printf("%s|", label); + vprintf(format, argptr); + ::printf("\n"); + } + break; + + case Logger::PrintMode::NO_PRINTING: + default: + break; + + } + m_oPrintLock.unlock(); +} + +void Logger::printfFatal(const char* format, ...) { + if (isPrintable(PrintLevel::FATAL_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::FATAL_LEVEL, PrintLevel::FATAL_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfError(const char* format, ...) { + if (isPrintable(PrintLevel::ERROR_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::ERROR_LEVEL, PrintLevel::ERROR_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfWarning(const char* format, ...) { + if (isPrintable(PrintLevel::WARNING_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::WARNING_LEVEL, PrintLevel::WARNING_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfInfo(const char* format, ...) { + if (isPrintable(PrintLevel::INFO_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::INFO_LEVEL, PrintLevel::INFO_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfConfig(const char* format, ...) { + if (isPrintable(PrintLevel::CONFIG_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::CONFIG_LEVEL, PrintLevel::CONFIG_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfDebug(const char* format, ...) { + if (isPrintable(PrintLevel::DEBUG_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::DEBUG_LEVEL, PrintLevel::DEBUG_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfTrace(const char* format, ...) { + if (isPrintable(PrintLevel::TRACE_LEVEL)) { + va_list argptr; + va_start(argptr, format); + printMessage(PrintLevel::TRACE_LEVEL, PrintLevel::TRACE_LABEL, format, argptr); + va_end(argptr); + } +} + +void Logger::printfGeneric(int level, const char* label, const char* format, ...) { + va_list argptr; + va_start(argptr, format); + printMessage(level, label, format, argptr); + va_end(argptr); +} + +void Logger::printf(int level, const char* format, ...) { + if (isPrintable(level)) { + va_list argptr; + va_start(argptr, format); + m_oPrintLock.lock(); + vprintf(format, argptr); + m_oPrintLock.unlock(); + va_end(argptr); + } +} + +void Logger::printf(const char* format, ...) { + if (isPrintable(PrintLevel::MAXIMUM_LEVEL)) { + va_list argptr; + va_start(argptr, format); + m_oPrintLock.lock(); + vprintf(format, argptr); + m_oPrintLock.unlock(); + va_end(argptr); + } +} + +bool Logger::setup(const PrintMode& mode) { + m_oPrintLock.lock(); + m_eMode = mode; + m_oPrintLock.unlock(); + return true; +} + +bool Logger::setup(const PrintMode& mode, const std::string& filename) { + /* close the handle and reopen it each time setup() is called in case + * we are being used with programs like logrotate, etc + * + * if the file is different, switch to the new file */ + + m_oPrintLock.lock(); + if (m_pFile) { + fclose(m_pFile); + } + if (m_sFileName != filename) { + m_sFileName = filename; + } + m_pFile = fopen(m_sFileName.c_str(), "a"); + m_iLogFacility = -1; + m_oPrintLock.unlock(); + + if (!m_pFile) { + fprintf(stderr, "Error opening logfile %s\n", m_sFileName.c_str()); + return false; + } + m_eMode = mode; + return true; +} + +bool Logger::setup(const PrintMode& mode, const std::string& ident, const int& option, const int& facility) { + m_oPrintLock.lock(); + m_pFile = NULL; + m_sFileName = ""; + m_iLogFacility = facility; + m_sIdent = ident; + m_eMode = mode; + m_oPrintLock.unlock(); + openlog(m_sIdent.c_str(), option, m_iLogFacility); + return true; +} + diff --git a/src/MTS_Object.cpp b/src/MTS_Object.cpp new file mode 100644 index 0000000..c798c70 --- /dev/null +++ b/src/MTS_Object.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Object.h> +#include <sstream> +#include <typeinfo> + +using namespace MTS; + +Object::Object() { +} + +Object::~Object() { +} + +std::string Object::toString() const { + return std::string("MTS::Object"); +} + +std::string Object::toIDD() const { + std::stringstream ss; + ss << typeid(*this).name() << "@" << reinterpret_cast<const void*>(this); + return ss.str().erase(0, 6); +} diff --git a/src/MTS_SignalThread.cpp b/src/MTS_SignalThread.cpp new file mode 100644 index 0000000..99975c0 --- /dev/null +++ b/src/MTS_SignalThread.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_SignalThread.h> +#include <mts/MTS_Logger.h> + +using namespace MTS; + +SignalThread::SignalThread(const std::string& name) +: Thread(name, true) +, m_bShouldExecute(false) +, m_bCurrentlyExecuting(false) +, m_ui32WaitMillis(200) +{ + init(); +} + +SignalThread::SignalThread(const std::string& name, uint32_t waitMillis) +: Thread(name, true) +, m_bShouldExecute(false) +, m_bCurrentlyExecuting(false) +, m_ui32WaitMillis(waitMillis) +{ + init(); +} + +void SignalThread::init() +{ + printConfig("SignalThread| %s - starting up", Thread::getName().c_str()); + m_apStateLock.reset(new MTS::Lock); + m_apConditionLock.reset(new MTS::Lock); + m_apCondition.reset(m_apConditionLock->createCondition()); +} + +SignalThread::~SignalThread() +{ + stop(); + m_apStateLock.reset(); + m_apConditionLock.reset(); + m_apCondition.reset(); + printConfig("SignalThread| %s - shutting down", Thread::getName().c_str()); +} + +void SignalThread::signal() +{ + m_apConditionLock->lock(); + m_bShouldExecute = true; + m_apCondition->signal(); + m_apConditionLock->unlock(); +} + +void SignalThread::run() +{ + while (! Thread::isCanceled()) + { + m_apConditionLock->lock(); + if (! m_bShouldExecute) + { + m_apCondition->wait(m_ui32WaitMillis); + } + if (m_bShouldExecute) + { + printTrace("SignalThread| %s - starting execute() function", Thread::getName().c_str()); + m_apStateLock->lock(); + m_bCurrentlyExecuting = true; + m_apStateLock->unlock(); + execute(); + m_apStateLock->lock(); + m_bCurrentlyExecuting = false; + m_apStateLock->unlock(); + printTrace("SignalThread| %s - finished execute() function", Thread::getName().c_str()); + } + m_bShouldExecute = false; + m_apConditionLock->unlock(); + } +} + +bool SignalThread::isExecuting() const +{ + bool retval = false; + m_apStateLock->lock(); + retval = m_bCurrentlyExecuting; + m_apStateLock->unlock(); + + return retval; +} diff --git a/src/MTS_System.cpp b/src/MTS_System.cpp new file mode 100644 index 0000000..e1ed348 --- /dev/null +++ b/src/MTS_System.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_System.h> +#include <fstream> +#include <sstream> +#include <cassert> + +#ifdef WIN32 +#include <windows.h> + +//WIN32: FILETIME structure has a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. + +static int64_t getEpochTimeMicros() { + const SYSTEMTIME EPOCH = {1970, 1, 4, 1, 0, 0, 0, 0}; + FILETIME ft; + BOOL ok = SystemTimeToFileTime(&EPOCH, &ft); + assert(ok); + int64_t epochTimeMicros = ((static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime) / 10; + return epochTimeMicros; +} + +static int64_t getSystemTimeMicros() { + SYSTEMTIME st; + GetSystemTime(&st); + FILETIME ft; + BOOL ok = SystemTimeToFileTime(&st, &ft); + assert(ok); + int64_t systemTimeMicros = ((static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime) / 10; + return systemTimeMicros; +} + +static int64_t getClockFrequency() { + LARGE_INTEGER freq; + BOOL ok = QueryPerformanceFrequency(&freq); + assert(ok); + return freq.QuadPart; +} + +static int64_t getClockValue() { + LARGE_INTEGER value; + BOOL ok = QueryPerformanceCounter(&value); + assert(ok); + return value.QuadPart; +} + +#else +#include <time.h> +#endif + +using namespace MTS; + +uint64_t System::timeMicros() { + int64_t micros = 0; +#ifdef WIN32 + static const int64_t EPOCH_TIME_MICROS = getEpochTimeMicros(); + micros = getSystemTimeMicros() - EPOCH_TIME_MICROS; +#else + timespec ts; + int result = clock_gettime(CLOCK_REALTIME, &ts); + if (result == 0) { + micros = (static_cast<int64_t>(ts.tv_sec) * 1000000) + + (ts.tv_nsec / 1000); + } +#endif + return micros; +} + +uint64_t System::precisionTimeMicros() { + int64_t micros = 0; +#ifdef WIN32 + static const double TO_MICROS = 1000000.0 / getClockFrequency(); + int64_t value = getClockValue(); + micros = static_cast<int64_t>(value * TO_MICROS); +#else + micros = timeMicros(); +#endif + return micros; +} + +bool System::isBigEndian() { + static union { + uint32_t i; + char c[4]; + } endian = { 0x01020304 }; + + return endian.c[0] == 1; +} + +void System::swapBytes(uint8_t* const pBuffer, const uint32_t iSize) { + if (iSize > 1 && pBuffer != 0) { + uint8_t cByte = 0; + uint32_t i; + uint32_t j; + for (i = 0, j = iSize - 1; i < j; i++, j--) { + cByte = pBuffer[i]; + pBuffer[i] = pBuffer[j]; + pBuffer[j] = cByte; + } + } +} + +int32_t System::cmd(const std::string& cmd, std::string& result) { + std::string output; + FILE * stream; + const int max_buffer = 256; + char buffer[max_buffer]; + int32_t code = -1; + + stream = popen(cmd.c_str(), "r"); + if (stream) { + while (!feof(stream)) + if (fgets(buffer, max_buffer, stream) != NULL) + output.append(buffer); + code = pclose(stream); + } + + result = output; + + return code; +} + +int32_t System::readFile(const std::string& path, std::string& result) { + std::ifstream infile(path.c_str()); + std::stringstream ss; + + if (!infile.is_open()) { + return -1; + } + + ss << infile.rdbuf(); + + infile.close(); + + result = ss.str(); + + return 0; +} + diff --git a/src/MTS_Text.cpp b/src/MTS_Text.cpp new file mode 100644 index 0000000..d823bfe --- /dev/null +++ b/src/MTS_Text.cpp @@ -0,0 +1,701 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Text.h> +//#include <mts/MTS_Logger.h> +#include <algorithm> +#include <sstream> +#include <iostream> +#include <limits> + +using namespace MTS; + +//strftime +//%a Abbreviated weekday name * Thu +//%A Full weekday name * Thursday +//%b Abbreviated month name * Aug +//%B Full month name * August +//%c Date and time representation * Thu Aug 23 14:55:02 2001 +//%d Day of the month (01-31) 23 +//%H Hour in 24h format (00-23) 14 +//%I Hour in 12h format (01-12) 02 +//%j Day of the year (001-366) 235 +//%m Month as a decimal number (01-12) 08 +//%M Minute (00-59) 55 +//%p AM or PM designation PM +//%S Second (00-61) 02 +//%U Week number with the first Sunday as the first day of week one (00-53) 33 +//%w Weekday as a decimal number with Sunday as 0 (0-6) 4 +//%W Week number with the first Monday as the first day of week one (00-53) 34 +//%x Date representation * 08/23/01 +//%X Time representation * 14:55:02 +//%y Year, last two digits (00-99) 01 +//%Y Year 2001 +//%Z Timezone name or abbreviation CDT +//%% A % sign % + +//Example +///* strftime example */ +//#include <stdio.h> +//#include <time.h> +// +//int main () +//{ +// time_t rawtime; +// struct tm * timeinfo; +// char buffer [80]; +// +// time ( &rawtime ); +// timeinfo = localtime ( &rawtime ); +// +// strftime (buffer,80,"Now it's %I:%M%p.",timeinfo); +// puts (buffer); +// +// return 0; +//} + +std::string Text::time(const uint64_t& iTimeMicros, const TIMEFORMAT& eTime) { + int64_t now = iTimeMicros / 1000; + int64_t millis = now % 1000; + int64_t secs = (now / 1000) % 60; + int64_t mins = (now / 60000) % 60; + int64_t hours = (now / 3600000) % 24; + std::stringstream sBuffer; + + switch (eTime) { + case HHcMMcSScmmm: + sBuffer << hours << ":" << mins << ":" << secs << ":" << millis; + return sBuffer.str(); + break; + case HHcMMcSS: + sBuffer << (hours < 10 ? "0" : "") << hours << ":" << (mins < 10 ? "0" : "") << mins << ":" << (secs < 10 ? "0" : "") << secs; + return sBuffer.str(); + break; + + } + return std::string("UNKNOWN-TIME-FORMAT"); +} + +std::string Text::date(const tm& stTime, const DATEFORMAT& eDate) { + char buffer[80]; + + switch (eDate) { + case MMsDDsYY: + strftime(buffer, 80, "%x", &stTime); + return std::string(buffer); + break; + case MMsDDsYY_HHcMMcSS: + strftime(buffer, 80, "%m/%d/%Y %H:%M:%S", &stTime); + return std::string(buffer); + break; + case RFC_1123: + std::stringstream sBuffer; + //Thu, 01 Jan 1970 00:00:01 GMT + //Week + switch (stTime.tm_wday) { + case 0: + sBuffer << "Sun, "; + break; + case 1: + sBuffer << "Mon, "; + break; + case 2: + sBuffer << "Tue, "; + break; + case 3: + sBuffer << "Wed, "; + break; + case 4: + sBuffer << "Thu, "; + break; + case 5: + sBuffer << "Fri, "; + break; + case 6: + sBuffer << "Sat, "; + break; + } + + //Day of Month + sBuffer << (stTime.tm_mday < 10 ? "0" : "") << stTime.tm_mday; + + //Month + switch (stTime.tm_mon) { + case 0: + sBuffer << " Jan "; + break; + case 1: + sBuffer << " Feb "; + break; + case 2: + sBuffer << " Mar "; + break; + case 3: + sBuffer << " Apr "; + break; + case 4: + sBuffer << " May "; + break; + case 5: + sBuffer << " Jun "; + break; + case 6: + sBuffer << " Jul "; + break; + case 7: + sBuffer << " Aug "; + break; + case 8: + sBuffer << " Sep "; + break; + case 9: + sBuffer << " Oct "; + break; + case 10: + sBuffer << " Nov "; + break; + case 11: + sBuffer << " Dec "; + break; + } + + sBuffer << (stTime.tm_year + 1900); + sBuffer << (stTime.tm_hour < 10 ? " 0" : " ") << stTime.tm_hour << ":" << (stTime.tm_min < 10 ? "0" : "") << stTime.tm_min << ":" << (stTime.tm_sec < 10 ? "0" : "") + << stTime.tm_sec; + sBuffer << " GMT"; + return sBuffer.str(); + break; + } + return std::string("UNKNOWN-DATE-FORMAT"); +} + +bool Text::datetimeIsBefore(const std::string& time1, const std::string& time2) { + + struct tm tm1; + struct tm tm2; + + strptime(time1.c_str(), "%x %T", &tm1); + strptime(time2.c_str(), "%x %T", &tm2); + + return difftime(mktime(&tm2), mktime(&tm1)) > 0; +} + +std::vector<std::string> Text::split(const std::string& str, char delimiter, int limit) { + return split(str, std::string(1, delimiter), limit); +} + +std::vector<std::string> Text::split(const std::string& str, const std::string& delimiter, int limit) { + std::vector<std::string> result; + if(str.size() == 0) { + return result; + } + if (limit <= 0) { + limit = std::numeric_limits<int>::max(); + } + size_t start = 0; + size_t end = str.find(delimiter, start); + for (int i = 1; (i < limit) && (end != std::string::npos); ++i) { + result.push_back(str.substr(start, end - start)); + start = end + delimiter.length(); + end = str.find(delimiter, start); + } + result.push_back(str.substr(start)); + return result; +} + +std::string Text::join(std::vector<std::string> list, char delimiter) { + + std::stringstream ss; + for (uint32_t i = 0; i < list.size(); i++) { + ss << list[i]; + if (i < list.size() - 1) + ss << delimiter; + } + return ss.str(); +} + +std::string Text::replace(const std::string& original, const std::string& from, const std::string& to) { + size_t start_pos = 0; + std::string str(original); + while ((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' + } + return str; +} + +uint32_t Text::count(const std::string& str, const std::string& element) { + uint32_t count = 0; + size_t start_pos = 0; + while ((start_pos = str.find(element, start_pos)) != std::string::npos) { + start_pos++; + count++; + } + return count; +} + +uint32_t Text::count(const std::string& str, const uint8_t& element) { + uint32_t count = 0; + size_t start_pos = 0; + while ((start_pos = str.find(element, start_pos)) != std::string::npos) { + start_pos++; + count++; + } + return count; +} + +bool Text::endsWith(const std::string& str, const std::string& key) { + if (key.size() > str.size()) return false; + return std::equal(str.begin() + str.size() - key.size(), str.end(), key.begin()); +} + +std::string Text::getLine(const std::string& source, const size_t& start, size_t& cursor) { + char delimiters[2]; + delimiters[0] = '\n'; + delimiters[1] = '\r'; + if(start > source.size()) { + cursor = std::string::npos; + return ""; + } + size_t end = source.find_first_of(delimiters, start, 2); + std::string line(source.substr(start, end - start)); + //printDebug("[TEXT] Start [%d] Cursor[%d] Size[%d] Line: %s", start, end, source.size(), line.c_str()); + if (end < source.size()) { + if (end < source.size() - 1) + if ((source[end] == '\n' && source[end + 1] == '\r') || (source[end] == '\r' && source[end + 1] == '\n')) { + //Advance an additional character in scenarios where lines end in \r\n or \n\r + end++; + } + end++; + } + cursor = end; + return line; +} + +std::string Text::trim(const std::string& str) { + size_t length = str.length(); + size_t start = length; + for (size_t i = 0; i < length; ++i) { + if (!isspace(static_cast<unsigned char>(str[i]))) { + start = i; + break; + } + } + size_t end = std::string::npos; + for (size_t i = length - 1; i != std::string::npos; --i) { + if (!isspace(static_cast<unsigned char>(str[i]))) { + end = i + 1; + break; + } + } + return str.substr(start, end - start); +} + +std::string Text::trim(const std::string& str, const uint8_t& element) { + size_t length = str.length(); + size_t start = length; + for (size_t i = 0; i < length; ++i) { + if (static_cast<unsigned char>(str[i]) != element) { + start = i; + break; + } + } + size_t end = std::string::npos; + for (size_t i = length - 1; i != std::string::npos; --i) { + if (static_cast<unsigned char>(str[i]) != element) { + end = i + 1; + break; + } + } + return str.substr(start, end - start); +} + + +std::string Text::strip(const std::string& str, const std::vector<uint8_t>& elements) { + std::string result(str); + for (uint32_t i = 0; i < elements.size(); i++) { + result.erase (std::remove(result.begin(), result.end(), elements[i]), result.end()); + } + return result; +} + +std::string Text::strip(const std::string& str, const uint8_t& element) { + std::string result(str); + result.erase (std::remove(result.begin(), result.end(), element), result.end()); + return result; +} + +std::string Text::toLowerCase(const std::string& str) { + std::string result(str); + size_t length = result.length(); + for (size_t i = 0; i < length; ++i) { + result[i] = static_cast<char>(tolower(static_cast<unsigned char>(result[i]))); + } + return result; +} + +std::string Text::toUpperCase(const std::string& str) { + std::string result(str); + size_t length = result.length(); + for (size_t i = 0; i < length; ++i) { + result[i] = static_cast<char>(toupper(static_cast<unsigned char>(result[i]))); + } + return result; +} + +std::string Text::toCapitalized(const std::string& str) { + std::string result; + result = str; + if (str.size() == 0) + return result; + else if (str.size() == 1) + return toUpperCase(result); + else + return toUpperCase(result.substr(0, 1)) + toLowerCase(result.substr(1)); +} + +std::string Text::toCamelCase(const std::string& str) { + std::string result; + if (str.size() == 0) { + return result; + } + + std::vector<std::string> parts = MTS::Text::split(str, ' '); + + if (parts.size() == 0 || parts[0].size() == 0) { + return result; + } + result.append(MTS::Text::toLowerCase(parts[0])); + + for (uint32_t i = 1; i < parts.size(); i++) { + result.append(MTS::Text::toCapitalized(parts[i])); + } + + return result; +} + +std::string Text::toCommandLineEscaped(const std::string& str) { + std::string result(str); + result = Text::replace(result, "#", "\\#"); + result = Text::replace(result, ".", "\\."); + result = Text::replace(result, "&", "\\&"); + result = Text::replace(result, "?", "\\?"); + return result; +} + +std::wstring Text::widen(const std::string& str) { + std::wstringstream wss; + size_t length = str.length(); + for (size_t i = 0; i < length; ++i) { + wss << wss.widen(str[i]); + } + return wss.str(); +} + +std::string Text::narrow(const std::wstring& str) { + std::wstringstream wss; + std::stringstream ss; + size_t length = str.length(); + for (size_t i = 0; i < length; ++i) { + ss << wss.narrow(str[i], '?'); + } + return ss.str(); +} + +std::string Text::format(bool value) { + std::stringstream ss; + ss.setf(ss.boolalpha); + ss << value; + return ss.str(); +} + +std::string Text::format(double value, std::streamsize percision) { + std::stringstream ss; + ss.setf(ss.fixed, ss.floatfield); + ss.precision(percision); + ss << value; + std::string str = ss.str(); + // strip trailing zeros + size_t pos = str.find_last_not_of('0'); + if (pos != std::string::npos) { + if (str[pos] == '.') { + pos += 2; + } else { + pos += 1; + } + } + return str.substr(0, pos); +} + +std::string Text::format(int8_t value) { + return format(static_cast<int64_t>(value)); +} + +std::string Text::format(int16_t value) { + return format(static_cast<int64_t>(value)); +} + +std::string Text::format(int32_t value) { + return format(static_cast<int64_t>(value)); +} + +std::string Text::format(int64_t value) { + std::stringstream ss; + ss.setf(ss.dec, ss.basefield); + ss << value; + return ss.str(); +} + +std::string Text::format(uint8_t value) { + return format(static_cast<uint64_t>(value)); +} + +std::string Text::format(uint16_t value) { + return format(static_cast<uint64_t>(value)); +} + +std::string Text::format(uint32_t value) { + return format(static_cast<uint64_t>(value)); +} + +std::string Text::format(uint64_t value) { + std::stringstream ss; + ss.setf(ss.dec, ss.basefield); + ss << value; + return ss.str(); +} + +static std::string toHexString(uint64_t value, bool pad, std::streamsize padSize) { + std::stringstream ss; + ss.unsetf(ss.showbase); + ss.setf(ss.hex, ss.basefield); + ss.setf(ss.uppercase); + if (pad) { + ss.width(padSize); + ss.fill('0'); + } + ss << value; + return ss.str(); +} + +std::string Text::formatHex(int8_t value, bool pad) { + return formatHex(static_cast<uint8_t>(value), pad); +} + +std::string Text::formatHex(int16_t value, bool pad) { + return formatHex(static_cast<uint16_t>(value), pad); +} + +std::string Text::formatHex(int32_t value, bool pad) { + return formatHex(static_cast<uint32_t>(value), pad); +} + +std::string Text::formatHex(int64_t value, bool pad) { + return formatHex(static_cast<uint64_t>(value), pad); +} + +std::string Text::formatHex(uint8_t value, bool pad) { + return toHexString(value, pad, 2); +} + +std::string Text::formatHex(uint16_t value, bool pad) { + return toHexString(value, pad, 4); +} + +std::string Text::formatHex(uint32_t value, bool pad) { + return toHexString(value, pad, 8); +} + +std::string Text::formatHex(uint64_t value, bool pad) { + return toHexString(value, pad, 16); +} + +std::string Text::formatHex(const Buffer& value) { + char hex[4]; + std::string hexstr; + for (uint32_t i = 0; i < value.getSize(); i++) { + sprintf(hex, "%X", value.at(i)); + hexstr.append(hex); + } + return hexstr; +} + +bool Text::parse(bool& value, const std::string& str) { + if (str.empty()) { + return false; + } + std::istringstream ss(str); + ss.setf(ss.boolalpha); + ss.unsetf(ss.skipws); + ss >> value; + return ((uint8_t) ss.rdstate() == RDSTATE_SUCCESS_MASK); +} + +bool Text::parse(double& value, const std::string& str) { + if (str.empty()) { + return false; + } + std::istringstream ss(str); + ss.setf(ss.fixed, ss.basefield); + ss.unsetf(ss.skipws); + ss >> value; + return ((uint8_t) ss.rdstate() == RDSTATE_SUCCESS_MASK); +} + +bool Text::parse(int8_t& value, const std::string& str) { + int64_t i64 = 0; + if (!parse(i64, str)) { + return false; + } + if (i64 < INT8_MIN || i64 > INT8_MAX) { + return false; + } + value = static_cast<int8_t>(i64); + return true; +} + +bool Text::parse(int16_t& value, const std::string& str) { + int64_t i64 = 0; + if (!parse(i64, str)) { + return false; + } + if (i64 < INT16_MIN || i64 > INT16_MAX) { + return false; + } + value = static_cast<int16_t>(i64); + return true; +} + +bool Text::parse(int32_t& value, const std::string& str) { + int64_t i64 = 0; + if (!parse(i64, str)) { + return false; + } + if (i64 < INT32_MIN || i64 > INT32_MAX) { + return false; + } + value = static_cast<int32_t>(i64); + return true; +} + +bool Text::parse(int64_t& value, const std::string& str) { + if (str.empty()) { + return false; + } + std::istringstream ss(str); + ss.setf(ss.dec, ss.basefield); + ss.unsetf(ss.skipws); + ss >> value; + return ((uint8_t) ss.rdstate() == RDSTATE_SUCCESS_MASK); +} + +bool Text::parse(uint8_t& value, const std::string& str) { + uint64_t u64 = 0; + if (!parse(u64, str)) { + return false; + } + if (u64 > UINT8_MAX) { + return false; + } + value = static_cast<uint8_t>(u64); + return true; +} + +bool Text::parse(uint16_t& value, const std::string& str) { + uint64_t u64 = 0; + if (!parse(u64, str)) { + return false; + } + if (u64 > UINT16_MAX) { + return false; + } + value = static_cast<uint16_t>(u64); + return true; +} + +bool Text::parse(uint32_t& value, const std::string& str) { + uint64_t u64 = 0; + if (!parse(u64, str)) { + return false; + } + if (u64 > UINT32_MAX) { + return false; + } + value = static_cast<uint32_t>(u64); + return true; +} + +bool Text::parse(uint64_t& value, const std::string& str) { + if (str.empty()) { + return false; + } + std::istringstream ss(str); + ss.setf(ss.dec, ss.basefield); + ss.unsetf(ss.skipws); + ss >> value; + return ((uint8_t) ss.rdstate() == RDSTATE_SUCCESS_MASK); +} + +bool Text::parseHex(uint8_t& value, const std::string& str) { + uint64_t u64 = 0; + if (!parseHex(u64, str)) { + return false; + } + if (u64 > UINT8_MAX) { + return false; + } + value = static_cast<uint8_t>(u64); + return true; +} + +bool Text::parseHex(uint16_t& value, const std::string& str) { + uint64_t u64 = 0; + if (!parseHex(u64, str)) { + return false; + } + if (u64 > UINT16_MAX) { + return false; + } + value = static_cast<uint16_t>(u64); + return true; +} + +bool Text::parseHex(uint32_t& value, const std::string& str) { + uint64_t u64 = 0; + if (!parseHex(u64, str)) { + return false; + } + if (u64 > UINT32_MAX) { + return false; + } + value = static_cast<uint32_t>(u64); + return true; +} + +bool Text::parseHex(uint64_t& value, const std::string& str) { + + if (str.empty()) { + return false; + } + std::istringstream ss(str); + ss >> std::hex >> value; + return ((uint8_t) ss.rdstate() == RDSTATE_SUCCESS_MASK); +} + diff --git a/src/MTS_Thread.cpp b/src/MTS_Thread.cpp new file mode 100644 index 0000000..3537731 --- /dev/null +++ b/src/MTS_Thread.cpp @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Thread.h> +#include <mts/MTS_Logger.h> +#include <new> +#include <cassert> + +using namespace MTS; + +Thread::Thread(const std::string& name, bool managed) +: m_pThread(NULL) +, m_sName(name) +, m_bManaged(managed) +, m_bComplete(true) +, m_bCanceled(true) +{ + printConfig("Thread| %s()", getName().c_str()); + m_apThreadLock.reset(new Lock()); + m_apStateLock.reset(new Lock()); + m_apCompleteCondition.reset(m_apStateLock->createCondition()); +} + +Thread::~Thread() { + m_bCanceled = true; + Thread::stop(); + m_apCompleteCondition.reset(); + m_apStateLock.reset(); + m_apThreadLock.reset(); + printConfig("Thread| %s - deconstructed", getName().c_str()); +} + +void Thread::sleep(uint32_t millis) { +#ifdef WIN32 + Sleep(millis); +#else + Lock lock; + Condition* condition = lock.createCondition(); + lock.lock(); + condition->wait(millis); + lock.unlock(); + delete condition; +#endif +} + +const std::string& Thread::getName() const { + return m_sName; +} + +void Thread::start() { + m_apThreadLock->lock(); + try { + if (m_pThread == NULL) { + reset(); +#ifdef WIN32 + m_pThread = CreateThread(NULL, 0, &doInBackground, this, 0, NULL); +#else + m_pThread = new (std::nothrow) pthread_t; + if (m_pThread != NULL) { + const int result = pthread_create(m_pThread, NULL, + &doInBackground, this); + assert(result == 0); + if (result != 0) { + delete m_pThread; + m_pThread = NULL; + } + } + +#endif + assert(m_pThread != NULL); + if (m_pThread != NULL) { + printConfig("Thread| %s - started (%p)", + getName().c_str(), m_pThread); + } else { + printWarning("Thread| Failed to start runnable %s", + getName().c_str()); + m_apStateLock->lock(); + m_bCanceled = true; + m_bComplete = true; + m_apStateLock->unlock(); + } + } + } catch (...) { + printWarning("Thread| Failed to start runnable %s", getName().c_str()); + assert(false); + } + m_apThreadLock->unlock(); +} + +void Thread::stop() { + m_apThreadLock->lock(); + cancel(); + if (m_pThread != NULL) { + wait(1500); + +#ifdef WIN32 + if (!isDone()) { + TerminateThread(m_pThread, 1); + printConfig("Thread| %s - terminated", getName().c_str()); + } + const BOOL ok = CloseHandle(m_pThread); + assert(ok); +#else + if (!isDone()) { + printConfig("Thread| %s - terminated", getName().c_str()); + } + delete m_pThread; +#endif + m_pThread = NULL; + } else if (!isDone()) { + done(); + } + m_apThreadLock->unlock(); +} + +void Thread::wait() { + m_apStateLock->lock(); + if (!m_bComplete) { + m_apCompleteCondition->wait(); + } + m_apStateLock->unlock(); +} + +void Thread::wait(uint32_t millis) { + m_apStateLock->lock(); + if (!m_bComplete) { + m_apCompleteCondition->wait(millis); + } + m_apStateLock->unlock(); +} + +bool Thread::isAlive() const { + bool result = false; + m_apThreadLock->lock(); + result = (m_pThread != NULL); + m_apThreadLock->unlock(); + return result; +} + +bool Thread::isCanceled() const { + bool result = false; + m_apStateLock->lock(); + result = m_bCanceled; + m_apStateLock->unlock(); + return result; +} + +void Thread::cancel() { + m_apStateLock->lock(); + if (!m_bCanceled) { + m_bCanceled = true; + printConfig("Thread| %s - cancelled", getName().c_str()); + } + m_apStateLock->unlock(); +} + +bool Thread::isDone() const { + bool result = false; + m_apStateLock->lock(); + result = m_bComplete; + m_apStateLock->unlock(); + return result; +} + +void Thread::done() { + m_apStateLock->lock(); + m_bComplete = true; + m_apCompleteCondition->signal(); + printConfig("Thread| %s - done", getName().c_str()); + m_apStateLock->unlock(); +} + +void Thread::reset() { + m_apStateLock->lock(); + m_bCanceled = false; + m_bComplete = false; + m_apStateLock->unlock(); +} + +bool Thread::isManaged() const { + return m_bManaged; +} + +#ifdef WIN32 +DWORD WINAPI Thread::doInBackground(__in LPVOID parameter) { +#else +void* Thread::doInBackground(void* parameter) { +#endif + + Thread* runnable = static_cast<Thread*>(parameter); + assert(runnable != NULL); + if (runnable != NULL) { + printConfig("Thread| %s - initializing\n", runnable->getName().c_str()); + try { + runnable->run(); + } catch (...) { + printWarning("Thread| exception caught while running %s", + runnable->getName().c_str()); + } + printConfig("Thread| %s - finalizing", runnable->getName().c_str()); + bool managed = runnable->isManaged(); + runnable->done(); + if (!managed) { + printConfig("Thread| %s - deleted", runnable->getName().c_str()); + delete runnable; + } + } + return 0; +} + diff --git a/src/MTS_Timer.cpp b/src/MTS_Timer.cpp new file mode 100644 index 0000000..2158c29 --- /dev/null +++ b/src/MTS_Timer.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_Timer.h> +#include <mts/MTS_System.h> + +using namespace MTS; + +Timer::Timer() +: m_iStart(0) +, m_iPause(0) +, m_bStarted(false) +, m_bPaused(false) +{ + +} + +Timer::~Timer() { + +} + +void Timer::start() { + if(m_bStarted) { + return; + } + + m_iStart = System::timeMicros(); + m_bStarted = true; + m_bPaused = false; +} + +void Timer::stop() { + m_bStarted = false; +} + +void Timer::pause() { + if(m_bPaused || !m_bStarted) { + return; + } + + m_iPause = System::timeMicros(); + m_bPaused = true; +} + +void Timer::resume() { + if(!m_bPaused) { + return; + } + + m_iStart += System::timeMicros() + m_iPause; + m_bPaused = false; +} + +void Timer::reset() { + m_iStart = System::timeMicros(); + m_bPaused = false; +} + +bool Timer::isRunning() { + return !m_bPaused && m_bStarted; +} + +uint64_t Timer::getMicros() { + if(!m_bStarted) { + return 0; + } + + if(m_bPaused) { + return m_iPause - m_iStart; + } + + return System::timeMicros() - m_iStart; +} + +uint64_t Timer::getMillis() { + return getMicros() / 1000; +} + +uint64_t Timer::getSeconds() { + return getMicros() / 1000000; +} + +uint64_t Timer::getMinutes() { + return getMicros() / (1000000*60); +} + diff --git a/src/MTS_TimerThread.cpp b/src/MTS_TimerThread.cpp new file mode 100644 index 0000000..5a69c46 --- /dev/null +++ b/src/MTS_TimerThread.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015 by Multi-Tech Systems + * + * This file is part of libmts. + * + * libmts is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <mts/MTS_TimerThread.h> +#include <mts/MTS_Logger.h> + +using namespace MTS; + +TimerThread::TimerThread(const std::string& name) +: Thread(name, true) +, m_bCurrentlyExecuting(false) +, m_bExecutionStopped(false) +, m_ui32IntervalMillis(1000) +{ + init(); +} + +TimerThread::TimerThread(const std::string& name, uint32_t intervalMillis) +: Thread(name, true) +, m_bCurrentlyExecuting(false) +, m_bExecutionStopped(false) +, m_ui32IntervalMillis(intervalMillis) +{ + init(); +} + +void TimerThread::init() +{ + printConfig("TimerThread| %s - starting up", Thread::getName().c_str()); + m_apStateLock.reset(new MTS::Lock); +} + +TimerThread::~TimerThread() +{ + stop(); + m_apStateLock.reset(); + printConfig("TimerThread| %s - shutting down", Thread::getName().c_str()); +} + +void TimerThread::stopExecution() +{ + m_apStateLock->lock(); + m_bExecutionStopped = true; + m_apStateLock->unlock(); + printDebug("TimerThread| %s - stopping execution of task", Thread::getName().c_str()); +} + +void TimerThread::restartExecution() +{ + m_apStateLock->lock(); + m_bExecutionStopped = false; + m_apStateLock->unlock(); + printDebug("TimerThread| %s - restarting execution of task", Thread::getName().c_str()); +} + +void TimerThread::run() +{ + uint32_t intervalMillis; + bool executionStopped; + + while (! Thread::isCanceled()) + { + m_apStateLock->lock(); + intervalMillis = m_ui32IntervalMillis; + executionStopped = m_bExecutionStopped; + m_apStateLock->unlock(); + + if (! executionStopped) + { + printTrace("TimerThread| %s - starting execute() function", Thread::getName().c_str()); + m_apStateLock->lock(); + m_bCurrentlyExecuting = true; + m_apStateLock->unlock(); + execute(); + m_apStateLock->lock(); + m_bCurrentlyExecuting = false; + m_apStateLock->unlock(); + printTrace("TimerThread| %s - finished execute() function", Thread::getName().c_str()); + } + Thread::sleep(intervalMillis); + } +} + +bool TimerThread::isExecuting() const +{ + bool retval = false; + m_apStateLock->lock(); + retval = m_bCurrentlyExecuting; + m_apStateLock->unlock(); + + return retval; +} + +void TimerThread::updateIntervalMillis(uint32_t newMillis) +{ + m_apStateLock->lock(); + m_ui32IntervalMillis = newMillis; + m_apStateLock->unlock(); +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..602b159 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,9 @@ +project (TestRunnerClient) + +include_directories (../include) +link_directories (..) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -DCPPUNIT_MAIN=main") + +add_executable (TestRunnerClient TestRunnerClient.cpp Test_MTS_Text.cpp) +target_link_libraries (TestRunnerClient cppunit mts rt pthread) diff --git a/test/TestRunnerClient.cpp b/test/TestRunnerClient.cpp new file mode 100644 index 0000000..fcb9c75 --- /dev/null +++ b/test/TestRunnerClient.cpp @@ -0,0 +1,566 @@ +/******************************************************************************* + * Copyright (c) 2008 Gerhard Leonhartsberger. + * 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 + *******************************************************************************/ + +#include "TestRunnerClient.h" + +#ifdef CPPUNIT_MAIN + +#include "cppunit/XmlOutputter.h" +#include "cppunit/TextOutputter.h" +#include "cppunit/TestSuite.h" +#include "cppunit/TestResult.h" +#include "cppunit/TestFailure.h" +#include "cppunit/SourceLine.h" +#include "cppunit/Exception.h" +#include "cppunit/extensions/TestFactoryRegistry.h" +#include "cppunit/extensions/TestDecorator.h" +#include "cppunit/ui/text/TestRunner.h" + +#include <iostream> +#include <sstream> +#include <typeinfo> +#include <vector> + +#include <errno.h> +#include <unistd.h> +#include <sys/time.h> + +#ifdef _WIN32 // Bugzilla 40710 +#include <windows.h> +#include <winbase.h> +#include <winsock.h> +#else +#include <netinet/in.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netdb.h> +#endif + +#define MAX_HOSTNAME_SIZE 255 + +/* + * CppUnitServer protocol constants + */ +static const std::string TRACE_START = "%TRACES "; +static const std::string TRACE_END = "%TRACEE "; +static const std::string TEST_RUN_START = "%TESTC "; +static const std::string TEST_START = "%TESTS "; +static const std::string TEST_END = "%TESTE "; +static const std::string TEST_ERROR = "%ERROR "; +static const std::string TEST_FAILED = "%FAILED "; +static const std::string TEST_RUN_END = "%RUNTIME"; +static const std::string TEST_STOPPED = "%TSTSTP "; +static const std::string TEST_TREE = "%TSTTREE"; + +TestRunnerClient::TestRunnerClient() +{ + fTestResult = 0; + fClientSocket = -1; + fPort = 0; + fKeepAlive = 0; + fDebugMode = 0; + + fHost = (char *) malloc(MAX_HOSTNAME_SIZE); + strcpy(fHost, ""); +} + +TestRunnerClient::~TestRunnerClient() { + + if (fHost != NULL) { + free(fHost); + } +} + +int TestRunnerClient::Run() +{ + if (fDebugMode) + { + std::cerr << "TestRunnerClient: Starting client." << std::endl; + } + + if (Connect() == -1) { + return -1; + } + + InstallListeners(); + + RunTests(); + + UninstallListeners(); + + if(fTestResult != NULL) + { + fTestResult->stop(); + fTestResult= NULL; + } + + ShutDown(); + + return 0; +} + +void TestRunnerClient::Init(int n, char *args[]) +{ + ParseCommandLine(n, args); + DefineHostName(); +} + +void TestRunnerClient::ParseCommandLine(int n, char *args[]) +{ + // parse all arguments passed by args + for(int i = 0; i < n; i++) + { + std::string arg(args[i]); + + // port option + std::string portOption("-port="); + int pos = arg.find(portOption); + if(pos> -1) + { + std::string v = arg.substr(pos + portOption.length(), arg.length()); + fPort = atoi(v.c_str()); + } + + // debug option + std::string debugOption("-debug"); + pos = arg.find(debugOption); + if(pos> - 1) + { + fDebugMode = 1; + } + } +} + +void TestRunnerClient::DefineHostName() +{ + // set fHost to hostname or localhost + int ret = gethostname(fHost, MAX_HOSTNAME_SIZE); + if (ret == -1) + { + strcpy(fHost, "localhost"); + } +} + +int TestRunnerClient::Connect() +{ + +#ifdef _WIN32 // Bugzilla 40710 + if (fDebugMode) + { + std::cerr << "TestRunnerClient: Starting Windows Sockets WSAStartup()." << std:endl; + } + + // start up Windows Sockets + WSADATA WSAData; + int result = WSAStartup (MAKEWORD(1, 1), &WSAData); + if (result != NO_ERROR) + { + std::cerr << "TestRunnerClient: WSAStartup() failed! Error code: " << result << std::endl; + return -1; + } +#endif + + if (fDebugMode) + { + std::cerr << "TestRunnerClient: Trying to connect to " << fHost << ":" << fPort << std::endl; + } + + fClientSocket = socket(AF_INET, SOCK_STREAM, 0); + if (fClientSocket == -1) + { + std::cerr << "TestRunnerClient: Socket creation failed! error code: " << fClientSocket << std::endl; + return -1; + } + + struct hostent *host = gethostbyname(fHost); + if (host == NULL) + { + std::cerr << "TestRunnerClient: Cannot find host address for " << fHost << "." << std::endl; + fClientSocket = -1; + return -1; + } + + struct sockaddr_in name; + memset((void *)&name, 0, sizeof(struct sockaddr_in)); + name.sin_family = AF_INET; + name.sin_port = htons(fPort); + + memcpy(&name.sin_addr, host->h_addr, host->h_length); + + if (fDebugMode) { + std::cerr << "TestRunnerClient: Waiting for the JVM to listen ... (trying 3 times)" << std::endl; + } + + int ret = -1; + int j = 0; + while ((j < 3) && (ret == -1)) + { + ret = ::connect(fClientSocket, (struct sockaddr *) &name, sizeof(struct sockaddr_in)); + if (ret == -1) + { + if (fDebugMode) { + std::cerr << "TestRunnerClient: Connection request, waiting 1 second. " + << ((j-3)*-1) << " times left." << std::endl; + } + PrivateSleep(1000); + j++; + } + } + if (ret == -1) + { + std::cerr << "TestRunnerClient: No connection established. Error code: " << errno << std::endl; + fClientSocket = -1; + return -1; + } + + if (fDebugMode) { + std::cerr << "TestRunnerClient: Connection established." << std::endl; + } + return 0; +} + +void TestRunnerClient::InstallListeners() +{ + fTestResult = new CppUnit::TestResult(); + fTestResult->addListener(this); + fTestResult->addListener(&resultCollector); +} + +void TestRunnerClient::UninstallListeners() +{ + fTestResult->removeListener(this); +} + +void TestRunnerClient::RunTests() +{ + + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + CppUnit::Test *suite = registry.makeTest(); + int count = suite->countTestCases(); + NotifyTestRunStarted(count); + + if (count == 0) + { + NotifyTestRunEnded(0); + } + + long startTime = CurrentTimeMillis(); + if (fDebugMode) + { + std::cerr <<"TestRunnerClient: Start sending test case tree ..." << std::endl; + } + + SendTestTree(suite); + + int elapsedTime = CurrentTimeMillis() - startTime; + if (fDebugMode) { + std::cerr << "TestRunnerClient: Done sending test case tree. Elapsed time is " + << elapsedTime << "ms." << std::endl; + } + + long testStartTime = CurrentTimeMillis(); + if (fDebugMode) { + std::cerr << "TestRunnerClient: Test start time is " << testStartTime + << "ms." << std::endl; + } + + suite->run(fTestResult); + + if (fTestResult == NULL || fTestResult->shouldStop()) + { + NotifyTestRunStopped(CurrentTimeMillis() - testStartTime); + } + else + { + NotifyTestRunEnded(CurrentTimeMillis() - testStartTime); + } +} + +void TestRunnerClient::ShutDown() +{ + if (fClientSocket != -1) + { + if (fDebugMode) { + std::cerr << "TestRunnerClient: Closing connection to CppUnit sever at " + << fHost << ":" << fPort << std::endl; + } + +#ifdef _WIN32 // Bugzilla 40710 + // TODO: std:err output for error return codes + closesocket(fClientSocket); + WSACleanup(); +#else + int result = close(fClientSocket); + if (result != 0) + { + std::cerr << "TestRunnerClient: Close connection error: " << errno << std::endl; + } +#endif + + fClientSocket = -1; + } +} + +void TestRunnerClient::Stop() +{ + if (fTestResult != NULL) + { + fTestResult->stop(); + } +} + +void TestRunnerClient::SendTestTree(CppUnit::Test *test) +{ + if (typeid(*test) == typeid(CppUnit::TestDecorator)) + { + class TmpClass : public CppUnit::TestDecorator { + + public: + TmpClass(Test *t):CppUnit::TestDecorator(t) + { + // nothing to do + } + + ~TmpClass() // Bugzilla 39894 + { + // nothing to do + } + + CppUnit::Test *getTest() + { + return m_test; + } + }; + + TmpClass *t = (TmpClass *)test; + SendTestTree(t->getTest()); + } + else if (typeid(*test) == typeid(CppUnit::TestSuite)) + { + CppUnit::TestSuite *suite = (CppUnit::TestSuite *)test; + const std::vector<CppUnit::Test *> &x = suite->getTests(); + + std::ostringstream os; + os << suite->getName() << ",true," << x.size(); + NotifyTestTreeEntry(os.str()); + + for(unsigned int i=0; i < x.size(); i++) + { + SendTestTree(x[i]); + } + } + else + { + std::ostringstream os; + os << test->getName() << ",false," << test->countTestCases(); + NotifyTestTreeEntry(os.str()); + } +} + +void TestRunnerClient::SendMessage(std::string msg) +{ + if (fClientSocket == -1) + { + return; + } + +#ifdef _WIN32 // Bugzilla 40710 + send (fClientSocket, msg.c_str(), msg.length(), 0); + send (fClientSocket, "\n", 1, 0); +#else + write(fClientSocket, msg.c_str(), msg.length()); + write(fClientSocket, "\n", 1); +#endif + + if (fDebugMode) + { + std::cerr << "TestRunnerClient: Sent message \"" << msg << "\"" + << std::endl; + } +} + +void TestRunnerClient::NotifyTestRunStarted(int testCount) +{ + std::ostringstream os; + os << TEST_RUN_START << testCount; + SendMessage(os.str()); +} + +void TestRunnerClient::NotifyTestRunEnded(long elapsedTime) +{ + std::ostringstream os; + os << TEST_RUN_END << elapsedTime; + SendMessage(os.str()); +} + +void TestRunnerClient::NotifyTestRunStopped(long elapsedTime) +{ + std::ostringstream os; + os << TEST_STOPPED << elapsedTime; + SendMessage(os.str()); +} + +void TestRunnerClient::NotifyTestTreeEntry(std::string treeEntry) +{ + SendMessage(TEST_TREE + treeEntry); +} + +void TestRunnerClient::NotifyTestStarted(std::string testName) +{ + SendMessage(TEST_START + testName); +} + +void TestRunnerClient::NotifyTestEnded(std::string testName) +{ + SendMessage(TEST_END + testName); +} + +void TestRunnerClient::NotifyTestFailed(std::string status, std::string testName, std::string trace) +{ + SendMessage(status + testName); + SendMessage(TRACE_START); + SendMessage(trace); + SendMessage(TRACE_END); +} + +// From TestListener +void TestRunnerClient::startTest(CppUnit::Test *test) +{ + NotifyTestStarted(test->getName()); +} + +// From TestListener +void TestRunnerClient::addFailure(const CppUnit::TestFailure &failure) +{ + if(failure.isError()) + { + NotifyTestFailed(TEST_ERROR,failure.failedTestName(),GetTrace(failure)); + } + else + { + NotifyTestFailed(TEST_FAILED,failure.failedTestName(),GetTrace(failure)); + } +} + +// From TestListener +void TestRunnerClient::endTest(CppUnit::Test *test) +{ + NotifyTestEnded(test->getName()); +} + +std::string TestRunnerClient::GetTrace(const CppUnit::TestFailure &failure) +{ + std::ostringstream os; + + CppUnit::Exception *e=failure.thrownException(); + if(e->sourceLine().lineNumber()!=-1) + { + os << "File " << e->sourceLine().fileName() << ":" << e->sourceLine().lineNumber() << "\n"; + } + else + { + os << "File Unknown:1\n"; + } + /* TODO: expected, actual value implementation + if(typeid(*e)==typeid(CppUnit::NotEqualException)) + { + CppUnit::NotEqualException *ne=(CppUnit::NotEqualException *)e; + + os << "Expected Value: " << ne->expectedValue() << "\n"; + os << "Actual Value: " << ne->expectedValue() << "\n"; + os << "Additional Message: " << ne->additionalMessage() << "\n"; + } + else + { + End */ + os << "Message: " << std::string(e->what()) << "\n"; + /* } */ + + return(os.str()); +} + +long TestRunnerClient::CurrentTimeMillis() +{ +#ifdef _WIN32 // Bugzilla 40710 + unsigned long long p; + __asm__ __volatile__ ("rdtsc" : "=A" (p)); + return (unsigned long)p; +#else + struct timeval tv; + gettimeofday(&tv, NULL); + + return((long)(tv.tv_sec*1000) + (tv.tv_usec/1000)); +#endif +} + +void TestRunnerClient::PrivateSleep(int millisecs) +{ + struct timeval delta; + delta.tv_sec = (millisecs * 1000L) / 1000000L; + delta.tv_usec = (millisecs * 1000L) % 1000000L; + select (0, NULL, NULL, NULL, &delta); +} + +CppUnit::TestResultCollector& TestRunnerClient::getResultCollector() { + return resultCollector; +} + +/*! + * This is the main routine. The TestRunnerClient is initialized and run. The + * CppUnit tests are created, executed, and sent to the CppUnitServer. + * If no connection to the CppUnitServer was established the CppUnit tests are + * displayed on the console. + * + * @return <code>0</code> if the results of the CppUnit tests were sent to the + * CppUnitServer successfully. + * <code>-1</code> if a connection could not be established to the + * CppUnitServer. + */ +int CPPUNIT_MAIN(int n, char *arg[]) +{ + std::ofstream xmlFileOut("cppunit_results.xml"); + + TestRunnerClient client; + client.Init(n, arg); + int ret = client.Run(); + if (ret == -1) + { + //The Test Runner Client has failed + //Create the event manager and test controller + + CppUnit::TestResult controller; + + // Add a listener that collects test result + CppUnit::TestResultCollector result; + controller.addListener ( &result ); + + CppUnit::XmlOutputter xmlOutputter ( &result, xmlFileOut ); + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + CppUnit::Test *suite = registry.makeTest(); + + CppUnit::TextUi::TestRunner *runner = new CppUnit::TextUi::TestRunner(); + runner->addTest(suite); + runner->run(controller); + + // Output to XML + xmlOutputter.write(); + } else { + + CppUnit::TextOutputter textOutputter (&client.getResultCollector(), std::cout); + textOutputter.write(); + + // Output to XML + CppUnit::XmlOutputter xmlOutputter ( &client.getResultCollector(), xmlFileOut ); + xmlOutputter.write(); + } + + + xmlFileOut.close(); +} + +#endif /*CPPUNIT_MAIN*/ diff --git a/test/TestRunnerClient.h b/test/TestRunnerClient.h new file mode 100644 index 0000000..4dc4460 --- /dev/null +++ b/test/TestRunnerClient.h @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2008 Gerhard Leonhartsberger. + * 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 + *******************************************************************************/ + +#ifndef TESTRUNNERSERVER_H_ +#define TESTRUNNERSERVER_H_ + +#ifdef CPPUNIT_MAIN + +#include "cppunit/TestResultCollector.h" +#include "cppunit/TestListener.h" + +#include <vector> +#include <string> +#include <string.h> +#include <stdlib.h> + + +/*! + * Class <code>TestRunnerClient</code> handles the network connection to the + * <code>CppUnitServer</code> and executes all registered CppUnit tests. + * <p> + * The meta data of the CppUnit tests and the test results are sent to the + * <code>CppUnitServer</code> for displaying. + * </p> + * <p> + * For debugging purposes class <code>TestRunnerClient</code> displays debug + * messages on <code>std.cerr</code>. The debug modus is activated by specifying + * <code>debug</code> command line option. The command line is parsed by method + * <code>Init()</code>. + * </p> + * <p> + * Note: This class is not intended to be subclassed by clients. This class is + * based on the original <code>RemoteTestRunner</code> class provided by + * <code>org.eclipse.cdt.cppunit</code>. + * </p> + * + * @author Gerhard Leonhartsberger + */ +class TestRunnerClient: public CppUnit::TestListener +{ +private: + CppUnit::TestResult *fTestResult; + CppUnit::TestResultCollector resultCollector; + int fClientSocket; + char *fHost; + int fPort; + int fDebugMode; + int fKeepAlive; + +public: + TestRunnerClient(); + virtual ~TestRunnerClient(); + + CppUnit::TestResultCollector& getResultCollector(); + + /*! + * Initializes the <code>TestRunnerClient</code>. + * <p> + * The given <code>args</code> are parsed. The syntax for the arguments is + * defined in EBNF as follows: <code>{-option=value}</code> + * </p> + * + * @param n The number of arguments. + * @param args The argument values. Valid options are: + * <li><code>-debug</code> When present the TestRunnerClient + * is run in debug modus and displays debug messages.</li> + * <li><code>-port=number</code> Defines the port where + * CppUnitServer is listening for client connections.</li> + */ + void Init(int n,char *args[]); + + /*! + * Runs the TestRunnerClient. A trial to connect to the CppUnitServer is done. + * The test results are sent to the CppUnitServer. + * + * @return The return value is <code>0</code> when the CppUnitServer was connected successfully + * otherwise the return value is <code>-1</code>. + */ + int Run(); + + /*! + * Stops processing <code>CppUnit</code> from executing tests. + */ + void Stop(); + + /*! + * Method defined in <code>CppUnit::TestListener</code>. + */ + void startTest(CppUnit::Test *test); + + /*! + * Method defined in <code>CppUnit::TestListener</code>. + */ + void addFailure(const CppUnit::TestFailure &failure); + + /*! + * Method defined in <code>CppUnit::TestListener</code>. + */ + void endTest(CppUnit::Test *test); + +private: + int Connect(); + void RunTests(); + void ShutDown(); + + // utility methods + void ParseCommandLine(int n, char *args[]); + void DefineHostName(); + void InstallListeners(); + void UninstallListeners(); + + /*! + * Sends the given test to the CppUnitView. + * <p> + * In case of test is of type CppUnit::Test the following protocol is sent: + * <code>TSTTREE name, false, testCaseCount</code> + * </p> + * <p> + * In case of test is of type CppUnit::TestSuite the following protocol is sent: + * TSTTREE name, true, testCount + * </p> + * @param test the CppUnit test + */ + void SendTestTree(CppUnit::Test *test); + void SendMessage(std::string msg); + + // Notification methods + void NotifyTestRunStarted(int testCount); + void NotifyTestRunEnded(long elapsedTime); + void NotifyTestRunStopped(long elapsedTime); + void NotifyTestTreeEntry(std::string treeEntry); + void NotifyTestStarted(std::string testName); + void NotifyTestEnded(std::string testName); + void NotifyTestFailed(std::string status, std::string testName, std::string trace); + + std::string GetTrace(const CppUnit::TestFailure &failure); + long CurrentTimeMillis(); + void PrivateSleep(int millisecs); +}; + +#endif /*CPPUNIT_MAIN*/ +#endif /*TESTRUNNERSERVER_H_*/ diff --git a/test/Test_MTS_Text.cpp b/test/Test_MTS_Text.cpp new file mode 100644 index 0000000..b158fc1 --- /dev/null +++ b/test/Test_MTS_Text.cpp @@ -0,0 +1,392 @@ +#include "Test_MTS_Text.h" +#include <mts/MTS_Logger.h> +#include <sstream> + +CPPUNIT_TEST_SUITE_REGISTRATION(Test_MTS_Text); + +void Test_MTS_Text::testText__datetimeIsBefore() { + CPPUNIT_ASSERT(MTS::Text::datetimeIsBefore("08/10/12 12:00:00", "08/10/12 12:00:01")); + CPPUNIT_ASSERT(!MTS::Text::datetimeIsBefore("08/10/12 12:00:01", "08/10/12 12:00:00")); + CPPUNIT_ASSERT(MTS::Text::datetimeIsBefore("08/10/10 12:00:00", "08/10/12 12:00:00")); + CPPUNIT_ASSERT(MTS::Text::datetimeIsBefore("08/09/12 12:00:00", "08/10/12 12:00:01")); +} + +void Test_MTS_Text::testis_base64() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testbase64_encode() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testbase64_decode() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__time() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__date() { + std::string sZero("Thu, 01 Jan 1970 00:00:02 GMT"); + + std::string sDate; + time_t iTime = 2; + tm* pTime = gmtime(&iTime); + + sDate = MTS::Text::date(*pTime, MTS::Text::DATEFORMAT::RFC_1123); + printDebug("MTS::Text::date [%s]", sDate.c_str()); + CPPUNIT_ASSERT(sZero == sDate); +} + +void Test_MTS_Text::testText__split() { + std::string test = ",test"; + std::vector<std::string> list = MTS::Text::split(test, ","); + + CPPUNIT_ASSERT(list.size() == 2); + CPPUNIT_ASSERT(list[0] == ""); + CPPUNIT_ASSERT(list[1] == "test"); +} + +void Test_MTS_Text::testText__split_limit() { + std::string path = "stats"; + std::vector<std::string> parts = MTS::Text::split(path, '/', 3); + CPPUNIT_ASSERT(parts.size() == 1); + CPPUNIT_ASSERT(parts[0] == "stats"); + + std::string path1 = "stats/radio"; + std::vector<std::string> parts1 = MTS::Text::split(path1, '/', 3); + CPPUNIT_ASSERT(parts1.size() == 2); + CPPUNIT_ASSERT(parts1[0] == "stats"); + CPPUNIT_ASSERT(parts1[1] == "radio"); + + std::string path2 = "stats/radio/debug/hardware"; + std::vector<std::string> parts2 = MTS::Text::split(path2, '/'); + CPPUNIT_ASSERT(parts2.size() == 4); + CPPUNIT_ASSERT(parts2[0] == "stats"); + CPPUNIT_ASSERT(parts2[1] == "radio"); + CPPUNIT_ASSERT(parts2[2] == "debug"); + CPPUNIT_ASSERT(parts2[3] == "hardware"); + + std::string path3 = "stats/radio/debug/hardware"; + std::vector<std::string> parts3 = MTS::Text::split(path3, '/', -2); + CPPUNIT_ASSERT(parts3.size() == 4); + CPPUNIT_ASSERT(parts3[0] == "stats"); + CPPUNIT_ASSERT(parts3[1] == "radio"); + CPPUNIT_ASSERT(parts3[2] == "debug"); +} + +void Test_MTS_Text::testText__split_values() { + std::string path = "stats/radio/debug"; + std::vector<std::string> parts = MTS::Text::split(path, '/', 3); + CPPUNIT_ASSERT(parts.size() == 3); + CPPUNIT_ASSERT(parts[0] == "stats"); + CPPUNIT_ASSERT(parts[1] == "radio"); + CPPUNIT_ASSERT(parts[2] == "debug"); + + std::string path1 = "stats/radio/debug/hardware"; + std::vector<std::string> parts1 = MTS::Text::split(path1, '/', 3); + CPPUNIT_ASSERT(parts1.size() == 3); + CPPUNIT_ASSERT(parts1[0] == "stats"); + CPPUNIT_ASSERT(parts1[1] == "radio"); + CPPUNIT_ASSERT(parts1[2] == "debug/hardware"); + + std::string path2 = "stats/radio/debug/hardware"; + std::vector<std::string> parts2 = MTS::Text::split(path2, '/', 2); + CPPUNIT_ASSERT(parts2.size() == 2); + CPPUNIT_ASSERT(parts2[0] == "stats"); + CPPUNIT_ASSERT(parts2[1] == "radio/debug/hardware"); +} + +void Test_MTS_Text::testText__getLine() { + + std::string line1("-----------------------------13456055954665194976790380"); + std::string line2("Content-Disposition: form-data; name=\"archivo\"; filename=\"test\""); + std::string line3("Content-Type: application/octet-stream"); + std::string line4(""); + std::string line5("**HELLOWORLD**"); + std::string line6(""); + std::string line7("-----------------------------13456055954665194976790380--"); + + std::stringstream ss; + ss << line1 << "\n"; + ss << line2 << "\n\r"; + ss << line3 << "\n"; + ss << line4 << "\r\n"; + ss << line5 << "\n"; + ss << line6 << "\n"; + ss << line7 << "\n"; + + std::string test(ss.str()); + + size_t pos = 0; + CPPUNIT_ASSERT(line1 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT(line2 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT(line3 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT(line4 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT(line5 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT(line6 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT(line7 == MTS::Text::getLine(test, pos, pos)); + CPPUNIT_ASSERT("" == MTS::Text::getLine(test, pos, pos)); + +} + +void Test_MTS_Text::testText__trim() { + std::string test = " test "; + std::string result = MTS::Text::trim(test); + //std::printf("(%s)\n", result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "test"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "test\t\t"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "\t\ttest"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "\ttest\t"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "\n\nte st\n\n"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "te st"); + + test = "\n\ntest\n\n"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "\n\rtest\n\r"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "test\n\r"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = "\r\n\n\rtest\r\n\r\r\n\n\r\n"; + result = MTS::Text::trim(test); + //std::printf("before: (%s) after: (%s)\n", test.c_str(), result.c_str()); + CPPUNIT_ASSERT(result == "test"); + + test = " "; + result = MTS::Text::trim(test); + CPPUNIT_ASSERT(result == ""); +} + + +void Test_MTS_Text::testText__strip() { + std::string phonenum = "(763) 785-3500"; + std::string hw = "H*E*L*L*O WORLD!"; + std::string result; + std::vector<uint8_t> vElements; + + vElements.push_back('('); + vElements.push_back(')'); + vElements.push_back(' '); + vElements.push_back('-'); + + result = MTS::Text::strip(phonenum, vElements); + CPPUNIT_ASSERT(result == "7637853500"); + + result = MTS::Text::strip(hw, '*'); + CPPUNIT_ASSERT(result == "HELLO WORLD!"); +} + + +void Test_MTS_Text::testText__toLowerCase() { + std::string test = "TeSt"; + CPPUNIT_ASSERT(MTS::Text::toLowerCase(test) == "test"); +} + +void Test_MTS_Text::testText__toUpperCase() { + std::string test = "TeSt"; + CPPUNIT_ASSERT(MTS::Text::toUpperCase(test) == "TEST"); +} + +void Test_MTS_Text::testText__toCapitalized() { + std::string test = "test"; + CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "Test"); + test = "TEST\0"; + CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "Test"); + test = "\0"; + CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == ""); + test = "a\0"; + printDebug("[%s] [%s]", test.c_str(), MTS::Text::toCapitalized(test).c_str()); + CPPUNIT_ASSERT(MTS::Text::toCapitalized(test) == "A"); +} + +void Test_MTS_Text::testText__toCamelCase() { + std::string test("Hello World"); + CPPUNIT_ASSERT(MTS::Text::toCamelCase(test) == "helloWorld"); +} + +void Test_MTS_Text::testText__toBase64() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__toBase64_1() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__fromBase64() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__widen() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__narrow() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_1() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_2() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_3() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_4() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_5() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_6() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_7() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_8() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__format_9() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testtoHexString() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_1() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_2() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_3() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_4() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_5() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_6() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_7() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__formatHex_8() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_1() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_2() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_3() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_4() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_5() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_6() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_7() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_8() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parse_9() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parseHex() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parseHex_1() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parseHex_2() { + CPPUNIT_ASSERT(false); +} + +void Test_MTS_Text::testText__parseHex_3() { + CPPUNIT_ASSERT(false); +} + diff --git a/test/Test_MTS_Text.h b/test/Test_MTS_Text.h new file mode 100644 index 0000000..d9a9ea3 --- /dev/null +++ b/test/Test_MTS_Text.h @@ -0,0 +1,121 @@ +#ifndef TEST_Test_MTS_Text +#define TEST_Test_MTS_Text +#include <mts/MTS_Text.h> +#include "cppunit/extensions/HelperMacros.h" + +class Test_MTS_Text : public CppUnit::TestFixture { +public: + void testis_base64(); + void testbase64_encode(); + void testbase64_decode(); + void testText__time(); + void testText__date(); + void testText__split(); + void testText__split_limit(); + void testText__split_values(); + void testText__getLine(); + void testText__trim(); + void testText__strip(); + void testText__toLowerCase(); + void testText__toUpperCase(); + void testText__toCapitalized(); + void testText__toCamelCase(); + void testText__toBase64(); + void testText__toBase64_1(); + void testText__fromBase64(); + void testText__widen(); + void testText__narrow(); + void testText__format(); + void testText__format_1(); + void testText__format_2(); + void testText__format_3(); + void testText__format_4(); + void testText__format_5(); + void testText__format_6(); + void testText__format_7(); + void testText__format_8(); + void testText__format_9(); + void testtoHexString(); + void testText__formatHex(); + void testText__formatHex_1(); + void testText__formatHex_2(); + void testText__formatHex_3(); + void testText__formatHex_4(); + void testText__formatHex_5(); + void testText__formatHex_6(); + void testText__formatHex_7(); + void testText__formatHex_8(); + void testText__parse(); + void testText__parse_1(); + void testText__parse_2(); + void testText__parse_3(); + void testText__parse_4(); + void testText__parse_5(); + void testText__parse_6(); + void testText__parse_7(); + void testText__parse_8(); + void testText__parse_9(); + void testText__parseHex(); + void testText__parseHex_1(); + void testText__parseHex_2(); + void testText__parseHex_3(); + void testText__datetimeIsBefore(); + CPPUNIT_TEST_SUITE(Test_MTS_Text); +// CPPUNIT_TEST(testis_base64); +// CPPUNIT_TEST(testbase64_encode); +// CPPUNIT_TEST(testbase64_decode); +// CPPUNIT_TEST(testText__time); + CPPUNIT_TEST(testText__date); + CPPUNIT_TEST(testText__split); + CPPUNIT_TEST(testText__split_limit); + CPPUNIT_TEST(testText__split_values); + CPPUNIT_TEST(testText__getLine); + CPPUNIT_TEST(testText__trim); + CPPUNIT_TEST(testText__strip); + CPPUNIT_TEST(testText__toLowerCase); + CPPUNIT_TEST(testText__toUpperCase); + CPPUNIT_TEST(testText__toCapitalized); + CPPUNIT_TEST(testText__toCamelCase); +// CPPUNIT_TEST(testText__toBase64); +// CPPUNIT_TEST(testText__toBase64_1); +// CPPUNIT_TEST(testText__fromBase64); +// CPPUNIT_TEST(testText__widen); +// CPPUNIT_TEST(testText__narrow); +// CPPUNIT_TEST(testText__format); +// CPPUNIT_TEST(testText__format_1); +// CPPUNIT_TEST(testText__format_2); +// CPPUNIT_TEST(testText__format_3); +// CPPUNIT_TEST(testText__format_4); +// CPPUNIT_TEST(testText__format_5); +// CPPUNIT_TEST(testText__format_6); +// CPPUNIT_TEST(testText__format_7); +// CPPUNIT_TEST(testText__format_8); +// CPPUNIT_TEST(testText__format_9); +// CPPUNIT_TEST(testtoHexString); +// CPPUNIT_TEST(testText__formatHex); +// CPPUNIT_TEST(testText__formatHex_1); +// CPPUNIT_TEST(testText__formatHex_2); +// CPPUNIT_TEST(testText__formatHex_3); +// CPPUNIT_TEST(testText__formatHex_4); +// CPPUNIT_TEST(testText__formatHex_5); +// CPPUNIT_TEST(testText__formatHex_6); +// CPPUNIT_TEST(testText__formatHex_7); +// CPPUNIT_TEST(testText__formatHex_8); +// CPPUNIT_TEST(testText__parse); +// CPPUNIT_TEST(testText__parse_1); +// CPPUNIT_TEST(testText__parse_2); +// CPPUNIT_TEST(testText__parse_3); +// CPPUNIT_TEST(testText__parse_4); +// CPPUNIT_TEST(testText__parse_5); +// CPPUNIT_TEST(testText__parse_6); +// CPPUNIT_TEST(testText__parse_7); +// CPPUNIT_TEST(testText__parse_8); +// CPPUNIT_TEST(testText__parse_9); +// CPPUNIT_TEST(testText__parseHex); +// CPPUNIT_TEST(testText__parseHex_1); +// CPPUNIT_TEST(testText__parseHex_2); +// CPPUNIT_TEST(testText__parseHex_3); + CPPUNIT_TEST(testText__datetimeIsBefore); + CPPUNIT_TEST_SUITE_END(); +}; +#endif @@ -0,0 +1 @@ +VERSION=0.3 |