Browse Source

First pass on error_code

Brian Aker 12 years ago
parent
commit
7a20ecaf11
5 changed files with 140 additions and 2 deletions
  1. 1 0
      Makefile.am
  2. 2 2
      configure.ac
  3. 1 0
      libgearman/common.h
  4. 117 0
      libgearman/error_code.gperf
  5. 19 0
      libgearman/include.am

+ 1 - 0
Makefile.am

@@ -22,6 +22,7 @@ man1_MANS=
 man3_MANS=
 man3_MANS=
 man8_MANS=
 man8_MANS=
 DISTCLEANFILES=
 DISTCLEANFILES=
+MAINTAINERCLEANFILES=
 EXTRA_DIST=
 EXTRA_DIST=
 CLEANFILES=
 CLEANFILES=
 BUILT_SOURCES=
 BUILT_SOURCES=

+ 2 - 2
configure.ac

@@ -93,13 +93,13 @@ AX_ENABLE_LIBHIREDIS
 
 
 # Checks for programs.
 # Checks for programs.
 AC_CHECK_PROGS([VALGRIND],['valgrind'])
 AC_CHECK_PROGS([VALGRIND],['valgrind'])
+AC_PATH_PROG([GPERF],['gperf'])
 AC_PROG_AWK
 AC_PROG_AWK
 AC_PROG_INSTALL
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
 AC_PROG_MAKE_SET
-AX_PROG_SPHINX_BUILD
 AX_PROG_MEMCACHED
 AX_PROG_MEMCACHED
-AC_PATH_PROG([GPERF])
+AX_PROG_SPHINX_BUILD
 
 
 # Checks for header files.
 # Checks for header files.
 AC_HEADER_STDC
 AC_HEADER_STDC

+ 1 - 0
libgearman/common.h

@@ -58,6 +58,7 @@ struct gearman_universal_st;
 #include "libgearman/aggregator.hpp"
 #include "libgearman/aggregator.hpp"
 
 
 #include "libgearman/error.hpp"
 #include "libgearman/error.hpp"
+#include "libgearman/error_code.hpp"
 
 
 /* These are private not to be installed headers */
 /* These are private not to be installed headers */
 #include "libgearman/byteorder.h"
 #include "libgearman/byteorder.h"

+ 117 - 0
libgearman/error_code.gperf

@@ -0,0 +1,117 @@
+%compare-lengths
+%compare-strncmp
+%define lookup-function-name string2error_code
+%ignore-case
+%language=ANSI-C
+%readonly-tables
+
+%{ 
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Gearmand client and server library.
+ *
+ *  Copyright (C) 2013 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include <cstring>
+#include "libgearman-1.0/return.h"
+
+namespace org {
+namespace gearman {
+
+%}
+
+struct error_code_st
+{ 
+  const char* name;
+  const gearman_return_t code;
+};
+%%
+GEARMAN_SUCCESS, GEARMAN_SUCCESS
+GEARMAN_ARGUMENT_TOO_LARGE, GEARMAN_ARGUMENT_TOO_LARGE
+GEARMAN_COULD_NOT_CONNECT, GEARMAN_COULD_NOT_CONNECT
+GEARMAN_DATA_TOO_LARGE, GEARMAN_DATA_TOO_LARGE
+GEARMAN_ECHO_DATA_CORRUPTION, GEARMAN_ECHO_DATA_CORRUPTION
+GEARMAN_ERRNO, GEARMAN_ERRNO
+GEARMAN_EVENT, GEARMAN_EVENT
+GEARMAN_FLUSH_DATA, GEARMAN_FLUSH_DATA
+GEARMAN_GETADDRINFO, GEARMAN_GETADDRINFO
+GEARMAN_IGNORE_PACKET, GEARMAN_IGNORE_PACKET
+GEARMAN_INVALID_ARGUMENT, GEARMAN_INVALID_ARGUMENT
+GEARMAN_INVALID_COMMAND, GEARMAN_INVALID_COMMAND
+GEARMAN_INVALID_FUNCTION_NAME, GEARMAN_INVALID_FUNCTION_NAME
+GEARMAN_INVALID_MAGIC, GEARMAN_INVALID_MAGIC
+GEARMAN_INVALID_PACKET, GEARMAN_INVALID_PACKET
+GEARMAN_INVALID_WORKER_FUNCTION, GEARMAN_INVALID_WORKER_FUNCTION
+GEARMAN_IN_PROGRESS, GEARMAN_IN_PROGRESS
+GEARMAN_IO_WAIT, GEARMAN_IO_WAIT
+GEARMAN_JOB_EXISTS, GEARMAN_JOB_EXISTS
+GEARMAN_JOB_QUEUE_FULL, GEARMAN_JOB_QUEUE_FULL
+GEARMAN_LOST_CONNECTION, GEARMAN_LOST_CONNECTION
+GEARMAN_MEMORY_ALLOCATION_FAILURE, GEARMAN_MEMORY_ALLOCATION_FAILURE
+GEARMAN_NEED_WORKLOAD_FN, GEARMAN_NEED_WORKLOAD_FN
+GEARMAN_NOT_CONNECTED, GEARMAN_NOT_CONNECTED
+GEARMAN_NOT_FLUSHING, GEARMAN_NOT_FLUSHING
+GEARMAN_NO_ACTIVE_FDS, GEARMAN_NO_ACTIVE_FDS
+GEARMAN_NO_JOBS, GEARMAN_NO_JOBS
+GEARMAN_NO_REGISTERED_FUNCTION, GEARMAN_NO_REGISTERED_FUNCTION
+GEARMAN_NO_REGISTERED_FUNCTIONS, GEARMAN_NO_REGISTERED_FUNCTIONS
+GEARMAN_NO_SERVERS, GEARMAN_NO_SERVERS
+GEARMAN_PAUSE, GEARMAN_PAUSE
+GEARMAN_PIPE_EOF, GEARMAN_PIPE_EOF
+GEARMAN_PTHREAD, GEARMAN_PTHREAD
+GEARMAN_QUEUE_ERROR, GEARMAN_QUEUE_ERROR
+GEARMAN_RECV_IN_PROGRESS, GEARMAN_RECV_IN_PROGRESS
+GEARMAN_SEND_BUFFER_TOO_SMALL, GEARMAN_SEND_BUFFER_TOO_SMALL
+GEARMAN_SEND_IN_PROGRESS, GEARMAN_SEND_IN_PROGRESS
+GEARMAN_SERVER_ERROR, GEARMAN_SERVER_ERROR
+GEARMAN_SHUTDOWN, GEARMAN_SHUTDOWN
+GEARMAN_SHUTDOWN_GRACEFUL, GEARMAN_SHUTDOWN_GRACEFUL
+GEARMAN_TIMEOUT, GEARMAN_TIMEOUT
+GEARMAN_TOO_MANY_ARGS, GEARMAN_TOO_MANY_ARGS
+GEARMAN_UNEXPECTED_PACKET, GEARMAN_UNEXPECTED_PACKET
+GEARMAN_UNKNOWN_OPTION, GEARMAN_UNKNOWN_OPTION
+GEARMAN_UNKNOWN_STATE, GEARMAN_UNKNOWN_STATE
+GEARMAN_WORK_DATA, GEARMAN_WORK_DATA
+GEARMAN_WORK_ERROR, GEARMAN_WORK_ERROR
+GEARMAN_WORK_EXCEPTION, GEARMAN_WORK_EXCEPTION
+GEARMAN_WORK_FAIL, GEARMAN_WORK_FAIL
+GEARMAN_WORK_STATUS, GEARMAN_WORK_STATUS
+GEARMAN_WORK_WARNING, GEARMAN_WORK_WARNING
+GEARMAN_INVALID_SERVER_OPTION, GEARMAN_INVALID_SERVER_OPTION
+%%
+
+} // namespace gearman
+} // namespace org

+ 19 - 0
libgearman/include.am

@@ -147,3 +147,22 @@ noinst_LTLIBRARIES+= libgearman/libgearman-hostile.la
 libgearman_libgearman_hostile_la_LIBADD= $(libgearman_libgearman_la_LIBADD)
 libgearman_libgearman_hostile_la_LIBADD= $(libgearman_libgearman_la_LIBADD)
 libgearman_libgearman_hostile_la_SOURCES= $(libgearman_libgearman_la_SOURCES)
 libgearman_libgearman_hostile_la_SOURCES= $(libgearman_libgearman_la_SOURCES)
 libgearman_libgearman_hostile_la_CXXFLAGS= $(libgearman_libgearman_la_CXXFLAGS)
 libgearman_libgearman_hostile_la_CXXFLAGS= $(libgearman_libgearman_la_CXXFLAGS)
+
+# Handling the Gperf code
+GPERFFLAGS= --compare-strncmp --switch=1
+
+MAINTAINERCLEANFILES+= libgearman/error_code.hpp
+
+BUILT_SOURCES+= libgearman/error_code.hpp
+libgearman_libgearman_la_SOURCES+= libgearman/error_code.hpp
+libgearman/error_code.hpp: libgearman/error_code.gperf
+	if $(GPERF) $(GPERFFLAGS) --key-positions=9,10,11,17 --struct-type \
+	  libgearman/error_code.gperf >$@t; then \
+	  mv $@t $@; \
+	  elif $(GPERF) --version >/dev/null 2>&1; then \
+	  rm $@t; \
+	  exit 1; \
+	  else \
+	  rm $@t; \
+	  touch $@; \
+	  fi