Browse Source

Remove impl() usage from Job.

Brian Aker 11 years ago
parent
commit
944c188dbe

+ 1 - 0
libgearman-1.0/include.am

@@ -9,6 +9,7 @@ nobase_include_HEADERS+= libgearman-1.0/interface/client.h
 nobase_include_HEADERS+= libgearman-1.0/interface/status.h
 nobase_include_HEADERS+= libgearman-1.0/interface/task.h
 nobase_include_HEADERS+= libgearman-1.0/interface/worker.h
+nobase_include_HEADERS+= libgearman-1.0/interface/job.h
 nobase_include_HEADERS+= libgearman-1.0/status.h
 nobase_include_HEADERS+= \
 			 libgearman-1.0/actions.h \

+ 63 - 0
libgearman-1.0/interface/job.h

@@ -0,0 +1,63 @@
+/*  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
+
+#ifdef __cplusplus
+struct Job;
+#endif
+
+struct gearman_job_st
+{
+  struct {
+    bool is_allocated;
+    bool is_initialized;
+  } options;
+  void *_impl;
+#ifdef __cplusplus
+  struct Job* impl() const
+  {
+    return (Job*)(_impl);
+  }
+
+  void impl(Job* impl_)
+  {
+    _impl= impl_;
+  }
+#endif
+};
+

+ 2 - 0
libgearman-1.0/job.h

@@ -43,6 +43,8 @@
 
 #pragma once
 
+#include <libgearman-1.0/interface/job.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif

+ 2 - 4
libgearman/command.cc

@@ -2,7 +2,7 @@
  * 
  *  Gearmand client and server library.
  *
- *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ *  Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
  *  Copyright (C) 2008 Brian Aker, Eric Day
  *  All rights reserved.
  *
@@ -45,8 +45,6 @@
 
 #include "libgearman/assert.hpp"
 
-using namespace org::gearman;
-
 /**
  * Command info. Update GEARMAN_MAX_COMMAND_ARGS to the largest number in the
  * args column.
@@ -123,6 +121,6 @@ const gearman_command_info_st *gearman_command_info(gearman_command_t command)
 
 const struct gearman_command_info_st * gearman_command_lookup (register const char *str, register unsigned int len)
 {
-  const struct gearman_command_string_st* com_str=  command_string2command_code (str, len);
+  const struct gearman_command_string_st* com_str= String2gearman_command_t::in_word_set(str, len);
   return gearman_command_info(com_str->code);
 }

+ 3 - 8
libgearman/command.gperf

@@ -1,11 +1,12 @@
 %compare-lengths
 %compare-strncmp
-%define lookup-function-name command_string2command_code
 %define word-array-name gearman_command_string_st
+%define class-name String2gearman_command_t
 %global-table
 %ignore-case
-%language=ANSI-C
+%language=C++
 %readonly-tables
+%includes
 
 %{ 
 /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
@@ -54,9 +55,6 @@
 #include "libgearman/assert.hpp"
 #include "libgearman/command.h"
 
-namespace org {
-namespace gearman {
-
 %}
 
 struct gearman_command_string_st
@@ -109,6 +107,3 @@ JOB_ASSIGN_ALL, GEARMAN_COMMAND_JOB_ASSIGN_ALL
 GET_STATUS_UNIQUE, GEARMAN_COMMAND_GET_STATUS_UNIQUE
 STATUS_RES_UNIQUE, GEARMAN_COMMAND_STATUS_RES_UNIQUE
 %%
-
-} // namespace gearman
-} // namespace org

+ 1 - 3
libgearman/error_code.cc

@@ -40,11 +40,9 @@
 #include "libgearman/error_code.h"
 #include "libgearman/error_code.hpp"
 
-using namespace org::gearman;
-
 gearman_return_t string2return_code(const char* str, size_t len)
 {
-  const struct error_code_st* code= error_string2return_code(str, (uint32_t)(len));
+  const struct error_code_st* code= String2gearman_return_t::in_word_set(str, (uint32_t)(len));
 
   if (code)
   {

+ 3 - 12
libgearman/error_code.gperf

@@ -1,9 +1,10 @@
 %compare-lengths
 %compare-strncmp
-%define lookup-function-name error_string2return_code
+%define class-name String2gearman_return_t
 %ignore-case
-%language=ANSI-C
+%language=C++
 %readonly-tables
+%includes
 
 %{ 
 /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
@@ -45,15 +46,8 @@
 
 #pragma once
 
-#include <cstddef>
-#include <cstdlib>
-#include <cstring>
-
 #include "libgearman-1.0/return.h"
 
-namespace org {
-namespace gearman {
-
 %}
 
 struct error_code_st
@@ -115,6 +109,3 @@ GEARMAN_WORK_STATUS, GEARMAN_WORK_STATUS
 GEARMAN_WORK_WARNING, GEARMAN_WORK_WARNING
 GEARMAN_INVALID_SERVER_OPTION, GEARMAN_INVALID_SERVER_OPTION
 %%
-
-} // namespace gearman
-} // namespace org

+ 4 - 2
libgearman/function/function_v1.hpp

@@ -55,15 +55,17 @@ public:
     return bool(_worker_fn);
   }
 
-  gearman_function_error_t callback(gearman_job_st* job, void *context_arg)
+  gearman_function_error_t callback(gearman_job_st* job_shell, void *context_arg)
   {
+    Job* job= job_shell->impl();
+
     if (gearman_job_is_map(job))
     {
       gearman_job_build_reducer(job, NULL);
     }
 
     job->_error_code= GEARMAN_SUCCESS;
-    job->_worker.work_result= _worker_fn(job, context_arg, &(job->_worker.work_result_size), &job->_error_code);
+    job->_worker.work_result= _worker_fn(job_shell, context_arg, &(job->_worker.work_result_size), &job->_error_code);
 
     if (job->_error_code == GEARMAN_LOST_CONNECTION)
     {

+ 3 - 2
libgearman/function/function_v2.cc

@@ -45,14 +45,15 @@
 /*
   FunctionV2 function
 */
-gearman_function_error_t FunctionV2::callback(gearman_job_st* job, void *context_arg)
+gearman_function_error_t FunctionV2::callback(gearman_job_st* job_shell, void *context_arg)
 {
+  Job* job= job_shell->impl();
   if (gearman_job_is_map(job))
   {
     gearman_job_build_reducer(job, NULL);
   }
 
-  gearman_return_t error= _function(job, context_arg);
+  gearman_return_t error= _function(job_shell, context_arg);
   switch (error)
   {
   case GEARMAN_SHUTDOWN:

+ 4 - 2
libgearman/function/partition.cc

@@ -45,14 +45,16 @@
 /*
   Partition function
 */
-gearman_function_error_t Partition::callback(gearman_job_st* job, void *context_arg)
+gearman_function_error_t Partition::callback(gearman_job_st* job_shell, void *context_arg)
 {
+  Job* job= job_shell->impl();
+
   if (gearman_job_is_map(job))
   {
     gearman_job_build_reducer(job, aggregator_fn);
   }
 
-  gearman_return_t error= _partition_fn(job, context_arg);
+  gearman_return_t error= _partition_fn(job_shell, context_arg);
   switch (error)
   {
   case GEARMAN_FATAL:

Some files were not shown because too many files changed in this diff