JobControl.c++
上传用户:weiyuanprp
上传日期:2020-05-20
资源大小:1169k
文件大小:6k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. /* $Id: JobControl.c++,v 1.5 2007/12/05 02:13:53 faxguy Exp $ */
  2. /*
  3.  * Copyright (c) 1994-1996 Sam Leffler
  4.  * Copyright (c) 1994-1996 Silicon Graphics, Inc.
  5.  * HylaFAX is a trademark of Silicon Graphics
  6.  *
  7.  * Permission to use, copy, modify, distribute, and sell this software and 
  8.  * its documentation for any purpose is hereby granted without fee, provided
  9.  * that (i) the above copyright notices and this permission notice appear in
  10.  * all copies of the software and related documentation, and (ii) the names of
  11.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  12.  * publicity relating to the software without the specific, prior written
  13.  * permission of Sam Leffler and Silicon Graphics.
  14.  * 
  15.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  16.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  17.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  18.  * 
  19.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  20.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  21.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  23.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  24.  * OF THIS SOFTWARE.
  25.  */
  26. #include <ctype.h>
  27. #include "Sys.h"
  28. #include "JobControl.h"
  29. #include "faxQueueApp.h"
  30. #include "FaxTrace.h"
  31. #include "FaxRequest.h"
  32. #define DCI_MAXCONCURRENTCALLS 0x0001
  33. #define DCI_TIMEOFDAY 0x0002
  34. #define DCI_MAXSENDPAGES 0x0004
  35. #define DCI_MAXDIALS 0x0008
  36. #define DCI_MAXTRIES 0x0010
  37. #define DCI_USEXVRES 0x0020
  38. #define DCI_VRES 0x0040
  39. #define DCI_PRIORITY 0x0080
  40. #define DCI_DESIREDDF 0x0100
  41. #define DCI_NOTIFY 0x0200
  42. #define isDefined(b) (defined & b)
  43. #define setDefined(b) (defined |= b)
  44. JobControlInfo::JobControlInfo()   { defined = 0; }
  45. JobControlInfo::JobControlInfo(const JobControlInfo& other)
  46.     : rejectNotice(other.rejectNotice)
  47.     , modem(other.modem)
  48.     , tod(other.tod)
  49.     , args(other.args)
  50. {
  51.     defined = other.defined;
  52.     maxConcurrentCalls = other.maxConcurrentCalls;
  53.     maxSendPages = other.maxSendPages;
  54.     maxDials = other.maxDials;
  55.     maxTries = other.maxTries;
  56.     usexvres = other.usexvres;
  57.     vres = other.vres;
  58.     priority = other.priority;
  59.     desireddf = other.desireddf;
  60.     notify = other.notify;
  61. }
  62. JobControlInfo::JobControlInfo (const fxStr& buffer)
  63. {
  64.     defined = 0;
  65.     u_int pos = 0;
  66.     u_int last_pos = 0;
  67.     int loop = 0;
  68.     while ( (pos = buffer.next(last_pos, 'n')) < buffer.length() )
  69.     {
  70.      // Quick safety-net
  71. if (loop++ > 100)
  72.     break;
  73.      fxStr l(buffer.extract(last_pos, pos - last_pos));
  74. last_pos = pos+1;
  75. readConfigItem(l);
  76.     }
  77. }
  78. JobControlInfo::~JobControlInfo() {}
  79. void
  80. JobControlInfo::configError (const char* fmt, ...)
  81. {
  82.     va_list ap;
  83.     va_start(ap, fmt);
  84.     vlogError(fxStr::format("JobControl: %s", fmt) , ap);
  85.     va_end(ap);
  86. }
  87. void
  88. JobControlInfo::configTrace (const char*, ...)
  89. {
  90.    // We don't trace JobControl parsing...
  91. }
  92. bool
  93. JobControlInfo::setConfigItem (const char* tag, const char* value)
  94. {
  95.     if (streq(tag, "rejectnotice")) {
  96. rejectNotice = value;
  97.     } else if (streq(tag, "modem")) {
  98. modem = value;
  99.     } else if (streq(tag, "maxconcurrentjobs")) { // backwards compatibility
  100. maxConcurrentCalls = getNumber(value);
  101. setDefined(DCI_MAXCONCURRENTCALLS);
  102.     } else if (streq(tag, "maxconcurrentcalls")) {
  103. maxConcurrentCalls = getNumber(value);
  104. setDefined(DCI_MAXCONCURRENTCALLS);
  105.     } else if (streq(tag, "maxsendpages")) {
  106. maxSendPages = getNumber(value);
  107. setDefined(DCI_MAXSENDPAGES);
  108.     } else if (streq(tag, "maxdials")) {
  109. maxDials = getNumber(value);
  110. setDefined(DCI_MAXDIALS);
  111.     } else if (streq(tag, "maxtries")) {
  112. maxTries = getNumber(value);
  113. setDefined(DCI_MAXTRIES);
  114.     } else if (streq(tag, "timeofday")) {
  115. tod.parse(value);
  116. setDefined(DCI_TIMEOFDAY);
  117.     } else if (streq(tag, "usexvres")) {
  118. usexvres = getNumber(value);
  119. setDefined(DCI_USEXVRES);
  120.     } else if (streq(tag, "vres")) {
  121. vres = getNumber(value);
  122. setDefined(DCI_VRES);
  123.     } else if (streq(tag, "priority")) {
  124. priority = getNumber(value);
  125. setDefined(DCI_PRIORITY);
  126.     } else if (streq(tag, "notify")) {
  127. notify = -1;
  128. if (strcmp("none", value) == 0) notify = FaxRequest::no_notice;
  129. if (strcmp("when done", value) == 0) notify = FaxRequest::when_done;
  130. if (strcmp("when requeued", value) == 0) notify = FaxRequest::when_requeued;
  131. if (strcmp("when done+requeued", value) == 0) notify = FaxRequest::notify_any;
  132. if (notify != -1) setDefined(DCI_NOTIFY);
  133.     } else {
  134. if (streq(tag, "desireddf")) { // need to pass desireddf to faxsend, also
  135.     desireddf = getNumber(value);
  136.     setDefined(DCI_DESIREDDF);
  137. }
  138. if( args != "" )
  139.     args.append('');
  140. args.append(fxStr::format("-c%c%s:"%s"",
  141.     '', tag, (const char*) value));
  142.     }
  143.     return true;
  144. }
  145. u_int
  146. JobControlInfo::getMaxConcurrentCalls() const
  147. {
  148.     if (isDefined(DCI_MAXCONCURRENTCALLS))
  149. return maxConcurrentCalls;
  150.     else
  151. return faxQueueApp::instance().getMaxConcurrentCalls();
  152. }
  153. u_int
  154. JobControlInfo::getMaxSendPages() const
  155. {
  156.     if (isDefined(DCI_MAXSENDPAGES))
  157. return maxSendPages;
  158.     else
  159. return faxQueueApp::instance().getMaxSendPages();
  160. }
  161. u_int
  162. JobControlInfo::getMaxDials() const
  163. {
  164.     if (isDefined(DCI_MAXDIALS))
  165. return maxDials;
  166.     else
  167. return faxQueueApp::instance().getMaxDials();
  168. }
  169. u_int
  170. JobControlInfo::getMaxTries() const
  171. {
  172.     if (isDefined(DCI_MAXTRIES))
  173. return maxTries;
  174.     else
  175. return faxQueueApp::instance().getMaxTries();
  176. }
  177. const fxStr&
  178. JobControlInfo::getRejectNotice() const
  179. {
  180.     return rejectNotice;
  181. }
  182. const fxStr&
  183. JobControlInfo::getModem() const
  184. {
  185.     return modem;
  186. }
  187. time_t
  188. JobControlInfo::nextTimeToSend(time_t t) const
  189. {
  190.     if (isDefined(DCI_TIMEOFDAY))
  191. return tod.nextTimeOfDay(t);
  192.     else
  193. return faxQueueApp::instance().nextTimeToSend(t);
  194. }
  195. int
  196. JobControlInfo::getUseXVRes() const
  197. {
  198.     if (isDefined(DCI_USEXVRES))
  199. return usexvres;
  200.     else
  201. return -1;
  202. }
  203. u_int
  204. JobControlInfo::getVRes() const
  205. {
  206.     if (isDefined(DCI_VRES))
  207. return vres;
  208.     else
  209. return 0;
  210. }
  211. int
  212. JobControlInfo::getPriority() const
  213. {
  214.     if (isDefined(DCI_PRIORITY))
  215. return priority;
  216.     else
  217. return -1;
  218. }
  219. int
  220. JobControlInfo::getDesiredDF() const
  221. {
  222.     if (isDefined(DCI_DESIREDDF))
  223. return desireddf;
  224.     else
  225. return -1;
  226. }
  227. int
  228. JobControlInfo::getNotify() const
  229. {
  230.     if (isDefined(DCI_NOTIFY))
  231. return notify;
  232.     else
  233. return -1;
  234. }
  235. bool
  236. JobControlInfo::isNotify(u_int what) const
  237. {
  238.     if (isDefined(DCI_NOTIFY) && (notify & (u_short) what) != 0)
  239. return true;
  240.     else
  241. return false;
  242. }