コード例 #1
0
ファイル: ijs_server.c プロジェクト: lorf/epsoneplijs
IjsServerCtx *
ijs_server_init (void)
{
  ijs_bool ok = TRUE;
  char helo_buf[8];
  char resp_buf[8];
  int nbytes;
  IjsServerCtx *ctx = (IjsServerCtx *)malloc (sizeof(IjsServerCtx));
  int fd_from, fd_to;

  memcpy (resp_buf, IJS_RESP_STR, sizeof(resp_buf));

  fd_from = 0;
  fd_to = 1;
  /* MSVC    defines _MSC_VER     and _WIN32
     Mingw   defines __MINGW32__  and _WIN32
     Watcom  defines __WATCOMC__  and _WIN32
     borland defines __BORLANDC__ and _WIN32 */
#ifdef _WIN32
#if !defined(__BORLANDC__)
  /* MSVC, mingw, watcom */
  /* mingw and watcom have both _setmode and setmode */
  _setmode(fd_from, _O_BINARY);
  _setmode(fd_to, _O_BINARY);
#else
  /* borland has setmode but not _setmode */
  setmode(fd_from, _O_BINARY);
  setmode(fd_to, _O_BINARY);
#endif /* !__BORLANDC__ */
#endif
#ifdef VERBOSE
  fprintf (stderr, "fd_from = %d, fd_to = %d\n", fd_from, fd_to);
#endif
  ijs_recv_init (&ctx->recv_chan, fd_from);
  ijs_send_init (&ctx->send_chan, fd_to);
  nbytes = read (ctx->recv_chan.fd, helo_buf, sizeof(helo_buf));

  if (nbytes != sizeof(helo_buf))
    ok = FALSE;

  if (ok)
    nbytes = write (ctx->send_chan.fd, resp_buf, sizeof(resp_buf));
  if (nbytes != sizeof(resp_buf))
    ok = FALSE;

  ctx->in_job = FALSE;
  ctx->job_id = -1;

  ctx->ph = NULL;
  ctx->in_page = FALSE;
  ctx->buf = NULL;
  ctx->overflow_buf = NULL;

  ctx->begin_cb = ijs_server_dummy_begin_cb;
  ctx->end_cb = ijs_server_dummy_end_cb;

  if (ok)
    return ctx;
  else
    {
      ijs_server_done (ctx);
      return NULL;
    }
}
コード例 #2
0
ファイル: hpijs.cpp プロジェクト: csteacherd22/hplip
int main (int argc, char *argv[], char *evenp[])
{
   UXServices *pSS = NULL;
   IjsServerCtx *ctx = NULL;
   char *raster = NULL, *k_raster = NULL;
   int status = EXIT_FAILURE;
   int ret, n, i, kn=0, width, k_width;
   char user_name[32]={0,};
        
   openlog("hpijs", LOG_PID,  LOG_DAEMON);

   if (argc > 1)
   {
      const char *arg = argv[1];
      if ((arg[0] == '-') && (arg[1] == 'h'))
      {
         fprintf(stdout, "\nHewlett-Packard Co. Inkjet Server %s\n", VERSION);
         fprintf(stdout, "Copyright (c) 2001-2004, Hewlett-Packard Co.\n");
         exit(0);
      }
   }

   if (argc > 2)
        strncpy(user_name, argv[2], sizeof(user_name));

#ifdef HAVE_LIBHPIP
   char *pDev;
   if ((pDev = getenv ("DEVICE_URI")) &&
       ((strncmp (pDev, "hpfax:", 6)) == 0))
   {
       exit ( hpijsFaxServer (argc, argv));
   }
#endif

   ctx = ijs_server_init();
   if (ctx == NULL)
   {
      BUG("unable to init hpijs server\n");
      goto BUGOUT;
   }

   pSS = new UXServices();
   if (pSS->constructor_error != NO_ERROR)
   {
      BUG("unable to open Services object err=%d\n", pSS->constructor_error);
      goto BUGOUT;
   }

   setLogLevel(pSS, user_name);

#ifdef CAPTURE
   char szCapOutFile[MAX_FILE_PATH_LEN];
   snprintf(szCapOutFile, sizeof(szCapOutFile),"%s/hp_%s_ijs_capout_XXXXXX",CUPS_TMP_DIR, user_name);
   if ((pSS->InitScript(szCapOutFile, TRUE)) != NO_ERROR)
      BUG("unable to init capture");
#endif

   
   pSS->pPC = new PrintContext (pSS, 0, 0);

   /* Ignore JOB_CANCELED. This a bi-di hack that allows the job to continue even if bi-di communication failed. */
   if (pSS->pPC->constructor_error > 0 && pSS->DisplayStatus != DISPLAY_PRINTING_CANCELED)
   {
      BUG("unable to open PrintContext object err=%d\n", pSS->pPC->constructor_error);
      goto BUGOUT;
   }

/*
 *  Ignore the WARN_MODE_MISMATCH warning. This will happen if we are talking to a monochrome printer.
 *  We will select the correct printmode later.
 */

    if (pSS->pPC->constructor_error < 0 &&
        pSS->pPC->constructor_error != WARN_MODE_MISMATCH)
    {
        BUG ("WARNING: %s\n", pSS->GetDriverMessage (pSS->pPC->constructor_error));
		switch (pSS->pPC->constructor_error)
		{
			case WARN_LOW_INK_BOTH_PENS:
			case WARN_LOW_INK_BLACK:
			case WARN_LOW_INK_COLOR:
			case WARN_LOW_INK_PHOTO:
			case WARN_LOW_INK_GREY:
			case WARN_LOW_INK_BLACK_PHOTO:
			case WARN_LOW_INK_COLOR_PHOTO:
			case WARN_LOW_INK_GREY_PHOTO:
			case WARN_LOW_INK_COLOR_GREY:
			case WARN_LOW_INK_COLOR_GREY_PHOTO:
			case WARN_LOW_INK_COLOR_BLACK_PHOTO:
			case WARN_LOW_INK_CYAN:
			case WARN_LOW_INK_MAGENTA:
			case WARN_LOW_INK_YELLOW:
			case WARN_LOW_INK_MULTIPLE_PENS:
                        {
                           fputs("STATE: +marker-supply-low-warning\n", stderr);
                           break;
                        }
			default:
                           fputs("STATE: +marker-supply-low-warning\n", stderr);
		}
    }

#if 0
   BUG("device model=%s\n", pSS->pPC->PrinterModel());
   BUG("device class=%s\n",  pSS->pPC->PrintertypeToString(pSS->pPC->SelectedDevice()));
   BUG("default pen=%d\n",  pSS->pPC->GetDefaultPenSet());
   BUG("installed pen=%d\n",  pSS->pPC->GetInstalledPens());
#endif

   ijs_server_install_status_cb (ctx, hpijs_status_cb, pSS);
   ijs_server_install_list_cb (ctx, hpijs_list_cb, pSS);
   ijs_server_install_enum_cb (ctx, hpijs_enum_cb, pSS);
   ijs_server_install_set_cb (ctx, hpijs_set_cb, pSS);
   ijs_server_install_get_cb (ctx, hpijs_get_cb, pSS);

   while (1)
   {
      if ((ret = ijs_server_get_page_header(ctx, &pSS->ph)) < 0)
      {
         BUG("unable to read client data err=%d\n", ret);
         goto BUGOUT;
      }

      if (pSS->Model == -1)
         goto BUGOUT;      /* no device selected */

      if (ret)
      {
         status = 0; /* normal exit */
         break;
      }

      if (pSS->FirstRaster)
      {
          char  *pEnv = getenv ("COPY_COUNT");
          if (pEnv)
          {
              i = atoi (pEnv);
              pSS->pPC->SetCopyCount (i);
          }

         pSS->FirstRaster = 0;

         width = (int)(pSS->ph.xres * pSS->pPC->PrintableWidth() + 0.5);

         /* Desensitize input width, may be off by one due to paper size conversions. */
         if (pSS->ph.width < width)
            width = pSS->ph.width;

         if ((ret = pSS->pPC->SetPixelsPerRow(width, width)) != NO_ERROR)
         {
            BUG("unable to SetPixelsPerRow width=%d, err=%d\n", pSS->ph.width, ret);
         }

         /* Turn off any bi-di support. Allow bi-di for printer capabilities only. */
//         pSS->IOMode.bDevID = pSS->IOMode.bStatus = FALSE;
         pSS->ResetIOMode (FALSE, FALSE);

//       Turn off SpeedMech in duplex printing mode
         if (pSS->Duplex)
	 {
	     pSS->EnableSpeedMech (FALSE);
	 }

	 if (pSS->IsSpeedMechEnabled ())
	 {
	     pSS->InitSpeedMechBuffer ();
	 }

         if (pSS->pJob != NULL)
            delete pSS->pJob;
         pSS->pJob = new Job(pSS->pPC);
         if (pSS->pJob->constructor_error != NO_ERROR)
         {
            BUG("unable to create Job object err=%d\n", pSS->pJob->constructor_error);
            goto BUGOUT;
         }

         if (pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE)
         {
            if ((pSS->pPC->QueryDuplexMode() == DUPLEXMODE_BOOK) && pSS->pPC->RotateImageForBackPage())
               pSS->InitDuplexBuffer();
            pSS->BackPage = FALSE;
         }

         pSS->KRGB=0;
         if (strcmp(pSS->ph.cs, "KRGB") == 0)
            pSS->KRGB=1;
         
#if 0
         BUG("papersize=%d\n", pSS->pPC->GetPaperSize());
         BUG("width=%d, height=%d\n", pSS->ph.width, pSS->ph.height);
         BUG("EffResX=%d, EffResY=%d, InPixelsPerRow=%d, OutPixelsPerRow=%d\n", 
            pSS->pPC->EffectiveResolutionX(), pSS->pPC->EffectiveResolutionY(), 
            pSS->pPC->InputPixelsPerRow(), pSS->pPC->OutputPixelsPerRow());
         BUG("device=%s\n", pSS->pPC->PrinterModel());
#endif
      } // pSS->FirstRaster

      if ((raster = (char *)malloc(pSS->ph.width*3)) == NULL)
      {
         BUG("unable to allocate raster buffer size=%d: %m\n", pSS->ph.width*3);
         goto BUGOUT;
      }

      k_width = (pSS->ph.width + 7) >> 3;  /* width of k plane in bytes, byte aligned */

      if ((k_raster = (char *)malloc(k_width)) == NULL)
      {
         BUG("unable to allocate black raster buffer size=%d: %m\n", k_width);
         goto BUGOUT;
      }
      memset(k_raster, 0, k_width);

      pSS->SendPreviousPage ();
      for (i=0; i < pSS->ph.height; i++)      
      {
         if ((n = hpijs_get_client_raster(ctx, raster, pSS->ph.width*3, 0xff)) < 0)
            break;    /* error */
         if (pSS->KRGB)
         {
            if ((kn = hpijs_get_client_raster(ctx, k_raster, k_width, 0)) < 0)
               break;    /* error */
         }
         if (n == 0 && kn == 0)
            pSS->ProcessRaster((char *)0, (char *)0);  /* blank raster */
         else if (kn == 0)
            pSS->ProcessRaster(raster, (char *)0);
         else if (n == 0)
            pSS->ProcessRaster((char *)0, k_raster);
         else 
            pSS->ProcessRaster(raster, k_raster);
      }

      free(raster);
      raster = NULL;
      free(k_raster);
      k_raster = NULL;

      if (pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE)
      {
         if ((pSS->pPC->QueryDuplexMode() == DUPLEXMODE_BOOK) && pSS->pPC->RotateImageForBackPage() && pSS->BackPage)
         {
            pSS->SendBackPage();
         }
         pSS->BackPage = (BOOL)((int)pSS->BackPage + 1) % 2;
      }

      pSS->pJob->NewPage();

      
   } /* end while (1) */

   if (pSS->pPC->QueryDuplexMode() != DUPLEXMODE_NONE)
   {
      if (pSS->BackPage)
      {
         /* Send extra blank line & newpage to eject the page. (for VIP printers). */
         /* For malibu send enough blank lines to cause at least two blank rasters in Job::sendrasters(). 5/1/03, des */
         //         for (int i = 0; i < 201; i++)
         for (int i = 0; i < 401; i++)
            pSS->pJob->SendRasters((unsigned char *)0);
         pSS->pJob->NewPage();
      }
   }

BUGOUT:
   if (pSS != NULL)
   {
      if (pSS->pJob != NULL)
         delete pSS->pJob;
      if (pSS->pPC != NULL)
         delete pSS->pPC;
#ifdef CAPTURE
      pSS->EndScript();
#endif
      delete pSS;
   }
   if (raster != NULL)
      free(raster);
   if (k_raster != NULL)
      free(k_raster);
   if (ctx != NULL)
      ijs_server_done(ctx);

   exit(status);
}