1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 2 * 3 * Gearmand client and server library. 4 * 5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/ 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are 10 * met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * * Redistributions in binary form must reproduce the above 16 * copyright notice, this list of conditions and the following disclaimer 17 * in the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * * The names of its contributors may not be used to endorse or 21 * promote products derived from this software without specific prior 22 * written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 * 36 */ 37 38 39 #include <sys/types.h> 40 41 #include <libgearman/gearman.h> 42 #include <libtest/visibility.h> 43 44 #include <boost/shared_ptr.hpp> 45 46 #include "tests/workers/v2/called.h" 47 48 struct worker_handle_st 49 { 50 public: 51 worker_handle_st(); 52 ~worker_handle_st(); 53 54 void set_shutdown(); 55 bool is_shutdown(); 56 bool shutdown(); 57 void kill(); 58 59 void set_worker_id(gearman_worker_st*); 60 61 libtest::thread::Barrier* sync_point(); 62 63 void wait(); 64 bool check(); 65 66 volatile bool failed_startup; 67 boost::shared_ptr<libtest::thread::Thread> _thread; 68 69 private: 70 bool _shutdown; 71 libtest::thread::Mutex _shutdown_lock; 72 gearman_id_t _worker_id; 73 libtest::thread::Barrier _sync_point; 74 }; 75 76 struct worker_handles_st 77 { 78 worker_handles_st(); 79 ~worker_handles_st(); 80 81 // Warning, this will not clean up memory 82 void kill_all(); 83 84 void reset(); 85 86 void push(worker_handle_st *arg); 87 88 private: 89 std::vector<worker_handle_st *> _workers; 90 }; 91 92 #pragma once 93 94 LIBTEST_API 95 struct worker_handle_st *test_worker_start(in_port_t port, 96 const char *namespace_key, 97 const char *function_name, 98 const gearman_function_t &worker_fn, 99 void *context, 100 gearman_worker_options_t options, 101 int timeout= 0); 102 103 LIBTEST_API 104 bool test_worker_stop(struct worker_handle_st *); 105