<commit_before>// @(#)root/net:$Name:  $:$Id: TCastorFile.cxx,v 1.5 2003/11/29 01:47:13 rdm Exp $
// Author: Fons Rademakers + Jean-Damien Durand  17/09/2003

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TCastorFile                                                          //
//                                                                      //
// A TCastorFile is like a normal TNetFile except that it obtains the   //
// remote node (disk server) via the CASTOR API, once the disk server   //
// and the local file path are determined, the file will be accessed    //
// via the rootd daemon. File names have to be specified like:          //
//    castor:/castor/cern.ch/user/r/rdm/bla.root.                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TCastorFile.h"

#include <stdlib.h>
#include <errno.h>

#ifdef _WIN32
#include <WinDef.h>
#include <WinSock2.h>
#endif

#define RFIO_KERNEL           // Get access to extra symbols in the headers
#include <stage_api.h>        // Dial with CASTOR stager
#include <rfio_api.h>         // Util routines from rfio
#include <Cns_api.h>          // Dial with CASTOR Name Server

ClassImp(TCastorFile)

//______________________________________________________________________________
TCastorFile::TCastorFile(const char *url, Option_t *option, const char *ftitle,
                         Int_t compress, Int_t netopt)
   : TNetFile(url, ftitle, compress, kFALSE)
{
   // Create a TCastorFile. A TCastorFile is like a normal TNetFile except
   // that it obtains the remote node (disk server) via the CASTOR API, once
   // the disk server and the local file path are determined, the file will
   // be accessed via the rootd daemon. File names have to be specified like:
   //    castor:/castor/cern.ch/user/r/rdm/bla.root.
   // The other arguments are the same as for TNetFile and TFile.

   fIsCastor  = kFALSE;
   fWrittenTo = kFALSE;

   // file is always created by stage_out_hsm() and therefore
   // exists when opened by rootd
   TString opt = option;
   opt.ToUpper();
   if (opt == "NEW" || opt == "CREATE")
      opt = "RECREATE";

   Create(url, opt, netopt);
}

//______________________________________________________________________________
void TCastorFile::FindServerAndPath()
{
   // Find the CASTOR disk server and internal file path.

   struct stgcat_entry *stcp_output = 0;

   if (rfio_HsmIf_IsHsmFile(fUrl.GetFile()) == RFIO_HSM_CNS) {
      // This is a CASTOR file
      int flags = O_RDONLY;
      struct Cns_filestat st;
      int rc;
      char stageoutbuf[1025];
      char stageerrbuf[1025];

      // Check with internal stage limits - preventing overflow afterwards
      if (strlen(fUrl.GetFile()) > STAGE_MAX_HSMLENGTH) {
         serrno = ENAMETOOLONG;
         Error("FindServerAndPath", "can't open %s, error %d (%s)", fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }

      // Prepare the flags
      if (fOption == "CREATE" || fOption == "RECREATE" || fOption == "UPDATE")
         flags |= O_RDWR;
      if (fOption == "CREATE" || fOption == "RECREATE")
         flags |= O_CREAT | O_TRUNC;

      // Check if an existing file is going to be updated
      memset(&st, 0, sizeof(st));
      rc = Cns_stat(fUrl.GetFile(), &st);

      // Make sure that filesize is 0 if file doesn't exist
      // or that we will create (stage_out) if O_TRUNC.
      if (rc == -1 || ((flags & O_TRUNC) != 0)) st.filesize = 0;

      // Makes sure stage api does not write automatically to stdout/stderr
      if (stage_setoutbuf(stageoutbuf, 1024) != 0) {
         Error("FindServerAndPath", "can't open %s, stage_setoutbuf, error %d (%s)", fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }
      if (stage_seterrbuf(stageerrbuf, 1024) != 0) {
         Error("FindServerAndPath", "can't open %s, stage_seterrbuf, error %d (%s)", fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }

      struct stgcat_entry stcp_input;
      int nstcp_output;

      memset(&stcp_input, 0, sizeof(struct stgcat_entry));
      strcpy(stcp_input.u1.h.xfile, fUrl.GetFile());
      if (flags == O_RDONLY || st.filesize > 0) {
         // Do a recall
         if (stage_in_hsm((u_signed64) 0,          // Ebusy is possible...
                          (int) flags,             // open flags
                          (char *) 0,              // hostname
                          (char *) 0,              // pooluser
                          (int) 1,                 // nstcp_input
                          (struct stgcat_entry *) &stcp_input, // stcp_input
                          (int *) &nstcp_output,   // nstcp_output
                          (struct stgcat_entry **) &stcp_output, // stcp_output
                          (int) 0,                   // nstpp_input
                          (struct stgpath_entry *) 0 // stpp_input
             ) != 0) {
            Error("FindServerAndPath", "can't open %s, stage_in_hsm error %d (%s)",
                  fUrl.GetFile(), serrno, sstrerror(serrno));
            return;
         }
      } else {
         // Do a creation
         if (stage_out_hsm((u_signed64) 0,          // Ebusy is possible...
                           (int) flags,             // open flags
                           (mode_t) 0666,           // open mode (c.f. also umask)
                           // Note: This is
                           //       S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
                           // (c.f. fopen(2))
                           (char *) 0,              // hostname
                           (char *) 0,              // pooluser
                           (int) 1,                 // nstcp_input
                           (struct stgcat_entry *) &stcp_input, // stcp_input
                           (int *) &nstcp_output,   // nstcp_output
                           (struct stgcat_entry **) &stcp_output, // stcp_output
                           (int) 0,                       // nstpp_input
                           (struct stgpath_entry *) 0     // stpp_input
             ) != 0) {
            Error("FindServerAndPath", "can't open %s, stage_out_hsm error %d (%s)",
                  fUrl.GetFile(), serrno, sstrerror(serrno));
            return;
         }
      }
      if ((nstcp_output != 1) || (stcp_output == 0) ||
          (*(stcp_output->ipath) == '\0')) {
         // Impossible
         serrno = SEINTERNAL;
         if (stcp_output != 0) free(stcp_output);
         Error("FindServerAndPath", "can't open %s, error %d (%s)",
               fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }

      // Parse orig string to get disk server host
      char *filename;
      char *realhost = 0;
      rfio_parse(stcp_output->ipath, &realhost, &filename);
      if (realhost == 0) {
         serrno = SEINTERNAL;
         Error("FindServerAndPath",
               "can't open %s, get disk server hostname from %s error %d (%s)",
               fUrl.GetFile(), stcp_output->ipath, errno, sstrerror(serrno));
         free(stcp_output);
         return;
      }
      // Save real host and internal path
      fDiskServer = realhost;
      if (filename[0] != '/') {
         // Make file 'local' to the host
         fInternalPath  = "/";
         fInternalPath += filename;
      } else
         fInternalPath = filename;

      if (st.filesize == 0) {
         // Will force notification to stage when the file is closed
         fWrittenTo = kTRUE;
      }
   }
   //
   // Set the protocol prefix for TNetFile.
   // For the cern.ch domain we set the default authentication
   // method to UidGid, i.e. as for rfiod; for this we need
   // the full FQDN or address in "nnn.mmm.iii.jjj" form
   // (it can be changed by a proper directive in $HOME/.rootauthrc)
   TString r;
   TString fqdn;
   TInetAddress addr = gSystem->GetHostByName(fDiskServer);
   if (addr.IsValid()) {
      fqdn = addr.GetHostName();
      if (fqdn == "UnNamedHost")
         fqdn = addr.GetHostAddress();
      if (fqdn.EndsWith(".cern.ch") || fqdn.BeginsWith("137.138."))
         r = "rootug://";
      else
         r = "root://";
   } else
      r = "root://";

   // Update fUrl with new path
   r += fDiskServer + "/";
   r += fInternalPath;
   TUrl rurl(r);
   fUrl = rurl;

   // Now ipath is not null and contains the real internal path on the disk
   // server 'host', e.g. it is fDiskServer:fInternalPath
   fInternalPath = stcp_output->ipath;
   free(stcp_output);

   fIsCastor = kTRUE;
}

//______________________________________________________________________________
Int_t TCastorFile::SysClose(Int_t fd)
{
   // Close currently open file.

   Int_t r = TNetFile::SysClose(fd);

   if (fIsCastor && fWrittenTo) {
      // CASTOR file was created or modified
      rfio_HsmIf_reqtoput((char *)fInternalPath.Data());
      fWrittenTo = kFALSE;
   }

   return r;
}

//______________________________________________________________________________
Bool_t TCastorFile::WriteBuffer(const char *buf, Int_t len)
{
   // Write specified byte range to remote file via rootd daemon.
   // Returns kTRUE in case of error.

   if (TNetFile::WriteBuffer(buf, len))
      return kTRUE;

   if (fIsCastor && !fWrittenTo && len > 0) {
      stage_hsm_t hsmfile;

      // Change status of file in stage catalog from STAGED to STAGEOUT
      memset(&hsmfile, 0, sizeof(hsmfile));
      strcpy(hsmfile.upath, fInternalPath);
      if (stage_updc_filchg(0, &hsmfile) < 0) {
         Error("WriteBuffer", "error calling stage_updc_filchg");
         return kTRUE;
      }
      fWrittenTo = kTRUE;
   }

   return kFALSE;
}

//______________________________________________________________________________
void TCastorFile::ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt,
                                Int_t tcpwindowsize, Bool_t forceOpen,
                                Bool_t forceRead)
{
   // Connect to remote rootd server on CASTOR disk server.

   FindServerAndPath();

   TNetFile::ConnectServer(stat, kind, netopt, tcpwindowsize, forceOpen, forceRead);
}
<commit_msg>correct typo in cvs indentification string.<commit_after>// @(#)root/rfio:$Name:  $:$Id: TCastorFile.cxx,v 1.6 2005/03/16 16:10:19 rdm Exp $
// Author: Fons Rademakers + Jean-Damien Durand  17/09/2003

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TCastorFile                                                          //
//                                                                      //
// A TCastorFile is like a normal TNetFile except that it obtains the   //
// remote node (disk server) via the CASTOR API, once the disk server   //
// and the local file path are determined, the file will be accessed    //
// via the rootd daemon. File names have to be specified like:          //
//    castor:/castor/cern.ch/user/r/rdm/bla.root.                       //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TCastorFile.h"

#include <stdlib.h>
#include <errno.h>

#ifdef _WIN32
#include <WinDef.h>
#include <WinSock2.h>
#endif

#define RFIO_KERNEL           // Get access to extra symbols in the headers
#include <stage_api.h>        // Dial with CASTOR stager
#include <rfio_api.h>         // Util routines from rfio
#include <Cns_api.h>          // Dial with CASTOR Name Server

ClassImp(TCastorFile)

//______________________________________________________________________________
TCastorFile::TCastorFile(const char *url, Option_t *option, const char *ftitle,
                         Int_t compress, Int_t netopt)
   : TNetFile(url, ftitle, compress, kFALSE)
{
   // Create a TCastorFile. A TCastorFile is like a normal TNetFile except
   // that it obtains the remote node (disk server) via the CASTOR API, once
   // the disk server and the local file path are determined, the file will
   // be accessed via the rootd daemon. File names have to be specified like:
   //    castor:/castor/cern.ch/user/r/rdm/bla.root.
   // The other arguments are the same as for TNetFile and TFile.

   fIsCastor  = kFALSE;
   fWrittenTo = kFALSE;

   // file is always created by stage_out_hsm() and therefore
   // exists when opened by rootd
   TString opt = option;
   opt.ToUpper();
   if (opt == "NEW" || opt == "CREATE")
      opt = "RECREATE";

   Create(url, opt, netopt);
}

//______________________________________________________________________________
void TCastorFile::FindServerAndPath()
{
   // Find the CASTOR disk server and internal file path.

   struct stgcat_entry *stcp_output = 0;

   if (rfio_HsmIf_IsHsmFile(fUrl.GetFile()) == RFIO_HSM_CNS) {
      // This is a CASTOR file
      int flags = O_RDONLY;
      struct Cns_filestat st;
      int rc;
      char stageoutbuf[1025];
      char stageerrbuf[1025];

      // Check with internal stage limits - preventing overflow afterwards
      if (strlen(fUrl.GetFile()) > STAGE_MAX_HSMLENGTH) {
         serrno = ENAMETOOLONG;
         Error("FindServerAndPath", "can't open %s, error %d (%s)", fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }

      // Prepare the flags
      if (fOption == "CREATE" || fOption == "RECREATE" || fOption == "UPDATE")
         flags |= O_RDWR;
      if (fOption == "CREATE" || fOption == "RECREATE")
         flags |= O_CREAT | O_TRUNC;

      // Check if an existing file is going to be updated
      memset(&st, 0, sizeof(st));
      rc = Cns_stat(fUrl.GetFile(), &st);

      // Make sure that filesize is 0 if file doesn't exist
      // or that we will create (stage_out) if O_TRUNC.
      if (rc == -1 || ((flags & O_TRUNC) != 0)) st.filesize = 0;

      // Makes sure stage api does not write automatically to stdout/stderr
      if (stage_setoutbuf(stageoutbuf, 1024) != 0) {
         Error("FindServerAndPath", "can't open %s, stage_setoutbuf, error %d (%s)", fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }
      if (stage_seterrbuf(stageerrbuf, 1024) != 0) {
         Error("FindServerAndPath", "can't open %s, stage_seterrbuf, error %d (%s)", fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }

      struct stgcat_entry stcp_input;
      int nstcp_output;

      memset(&stcp_input, 0, sizeof(struct stgcat_entry));
      strcpy(stcp_input.u1.h.xfile, fUrl.GetFile());
      if (flags == O_RDONLY || st.filesize > 0) {
         // Do a recall
         if (stage_in_hsm((u_signed64) 0,          // Ebusy is possible...
                          (int) flags,             // open flags
                          (char *) 0,              // hostname
                          (char *) 0,              // pooluser
                          (int) 1,                 // nstcp_input
                          (struct stgcat_entry *) &stcp_input, // stcp_input
                          (int *) &nstcp_output,   // nstcp_output
                          (struct stgcat_entry **) &stcp_output, // stcp_output
                          (int) 0,                   // nstpp_input
                          (struct stgpath_entry *) 0 // stpp_input
             ) != 0) {
            Error("FindServerAndPath", "can't open %s, stage_in_hsm error %d (%s)",
                  fUrl.GetFile(), serrno, sstrerror(serrno));
            return;
         }
      } else {
         // Do a creation
         if (stage_out_hsm((u_signed64) 0,          // Ebusy is possible...
                           (int) flags,             // open flags
                           (mode_t) 0666,           // open mode (c.f. also umask)
                           // Note: This is
                           //       S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
                           // (c.f. fopen(2))
                           (char *) 0,              // hostname
                           (char *) 0,              // pooluser
                           (int) 1,                 // nstcp_input
                           (struct stgcat_entry *) &stcp_input, // stcp_input
                           (int *) &nstcp_output,   // nstcp_output
                           (struct stgcat_entry **) &stcp_output, // stcp_output
                           (int) 0,                       // nstpp_input
                           (struct stgpath_entry *) 0     // stpp_input
             ) != 0) {
            Error("FindServerAndPath", "can't open %s, stage_out_hsm error %d (%s)",
                  fUrl.GetFile(), serrno, sstrerror(serrno));
            return;
         }
      }
      if ((nstcp_output != 1) || (stcp_output == 0) ||
          (*(stcp_output->ipath) == '\0')) {
         // Impossible
         serrno = SEINTERNAL;
         if (stcp_output != 0) free(stcp_output);
         Error("FindServerAndPath", "can't open %s, error %d (%s)",
               fUrl.GetFile(), serrno, sstrerror(serrno));
         return;
      }

      // Parse orig string to get disk server host
      char *filename;
      char *realhost = 0;
      rfio_parse(stcp_output->ipath, &realhost, &filename);
      if (realhost == 0) {
         serrno = SEINTERNAL;
         Error("FindServerAndPath",
               "can't open %s, get disk server hostname from %s error %d (%s)",
               fUrl.GetFile(), stcp_output->ipath, errno, sstrerror(serrno));
         free(stcp_output);
         return;
      }
      // Save real host and internal path
      fDiskServer = realhost;
      if (filename[0] != '/') {
         // Make file 'local' to the host
         fInternalPath  = "/";
         fInternalPath += filename;
      } else
         fInternalPath = filename;

      if (st.filesize == 0) {
         // Will force notification to stage when the file is closed
         fWrittenTo = kTRUE;
      }
   }
   //
   // Set the protocol prefix for TNetFile.
   // For the cern.ch domain we set the default authentication
   // method to UidGid, i.e. as for rfiod; for this we need
   // the full FQDN or address in "nnn.mmm.iii.jjj" form
   // (it can be changed by a proper directive in $HOME/.rootauthrc)
   TString r;
   TString fqdn;
   TInetAddress addr = gSystem->GetHostByName(fDiskServer);
   if (addr.IsValid()) {
      fqdn = addr.GetHostName();
      if (fqdn == "UnNamedHost")
         fqdn = addr.GetHostAddress();
      if (fqdn.EndsWith(".cern.ch") || fqdn.BeginsWith("137.138."))
         r = "rootug://";
      else
         r = "root://";
   } else
      r = "root://";

   // Update fUrl with new path
   r += fDiskServer + "/";
   r += fInternalPath;
   TUrl rurl(r);
   fUrl = rurl;

   // Now ipath is not null and contains the real internal path on the disk
   // server 'host', e.g. it is fDiskServer:fInternalPath
   fInternalPath = stcp_output->ipath;
   free(stcp_output);

   fIsCastor = kTRUE;
}

//______________________________________________________________________________
Int_t TCastorFile::SysClose(Int_t fd)
{
   // Close currently open file.

   Int_t r = TNetFile::SysClose(fd);

   if (fIsCastor && fWrittenTo) {
      // CASTOR file was created or modified
      rfio_HsmIf_reqtoput((char *)fInternalPath.Data());
      fWrittenTo = kFALSE;
   }

   return r;
}

//______________________________________________________________________________
Bool_t TCastorFile::WriteBuffer(const char *buf, Int_t len)
{
   // Write specified byte range to remote file via rootd daemon.
   // Returns kTRUE in case of error.

   if (TNetFile::WriteBuffer(buf, len))
      return kTRUE;

   if (fIsCastor && !fWrittenTo && len > 0) {
      stage_hsm_t hsmfile;

      // Change status of file in stage catalog from STAGED to STAGEOUT
      memset(&hsmfile, 0, sizeof(hsmfile));
      strcpy(hsmfile.upath, fInternalPath);
      if (stage_updc_filchg(0, &hsmfile) < 0) {
         Error("WriteBuffer", "error calling stage_updc_filchg");
         return kTRUE;
      }
      fWrittenTo = kTRUE;
   }

   return kFALSE;
}

//______________________________________________________________________________
void TCastorFile::ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt,
                                Int_t tcpwindowsize, Bool_t forceOpen,
                                Bool_t forceRead)
{
   // Connect to remote rootd server on CASTOR disk server.

   FindServerAndPath();

   TNetFile::ConnectServer(stat, kind, netopt, tcpwindowsize, forceOpen, forceRead);
}
<|endoftext|>


<commit_before>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "vm/globals.h"
#if defined(TARGET_OS_FUCHSIA)

#include "vm/os.h"

#include <errno.h>
#include <magenta/syscalls.h>
#include <magenta/types.h>

#include "platform/assert.h"
#include "vm/zone.h"

namespace dart {

#ifndef PRODUCT

DEFINE_FLAG(bool, generate_perf_events_symbols, false,
    "Generate events symbols for profiling with perf");

#endif  // !PRODUCT

const char* OS::Name() {
  return "fuchsia";
}

intptr_t OS::ProcessId() {
  return static_cast<intptr_t>(getpid());
}

const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
  UNIMPLEMENTED();
  return "";
}

int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
  UNIMPLEMENTED();
  return 0;
}

int OS::GetLocalTimeZoneAdjustmentInSeconds() {
  UNIMPLEMENTED();
  return 0;
}

int64_t OS::GetCurrentTimeMillis() {
  return GetCurrentTimeMicros() / 1000;
}

int64_t OS::GetCurrentTimeMicros() {
  return mx_current_time() / 1000;
}

int64_t OS::GetCurrentMonotonicTicks() {
  return mx_current_time();
}

int64_t OS::GetCurrentMonotonicFrequency() {
  return kNanosecondsPerSecond;
}

int64_t OS::GetCurrentMonotonicMicros() {
  int64_t ticks = GetCurrentMonotonicTicks();
  ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond);
  return ticks / kNanosecondsPerMicrosecond;
}

int64_t OS::GetCurrentThreadCPUMicros() {
  UNIMPLEMENTED();
  return 0;
}

void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) {
  const int kMinimumAlignment = 16;
  ASSERT(Utils::IsPowerOfTwo(alignment));
  ASSERT(alignment >= kMinimumAlignment);
  void* p = memalign(alignment, size);
  if (p == NULL) {
    UNREACHABLE();
  }
  return p;
}

void OS::AlignedFree(void* ptr) {
  free(ptr);
}

// TODO(5411554):  May need to hoist these architecture dependent code
// into a architecture specific file e.g: os_ia32_fuchsia.cc
intptr_t OS::ActivationFrameAlignment() {
#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
    defined(TARGET_ARCH_ARM64)
  const int kMinimumAlignment = 16;
#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_DBC)
  const int kMinimumAlignment = 8;
#else
#error Unsupported architecture.
#endif
  intptr_t alignment = kMinimumAlignment;
  // TODO(5411554): Allow overriding default stack alignment for
  // testing purposes.
  // Flags::DebugIsInt("stackalign", &alignment);
  ASSERT(Utils::IsPowerOfTwo(alignment));
  ASSERT(alignment >= kMinimumAlignment);
  return alignment;
}

intptr_t OS::PreferredCodeAlignment() {
#if defined(TARGET_ARCH_IA32) ||                                               \
    defined(TARGET_ARCH_X64) ||                                                \
    defined(TARGET_ARCH_ARM64) ||                                              \
    defined(TARGET_ARCH_DBC)
  const int kMinimumAlignment = 32;
#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS)
  const int kMinimumAlignment = 16;
#else
#error Unsupported architecture.
#endif
  intptr_t alignment = kMinimumAlignment;
  // TODO(5411554): Allow overriding default code alignment for
  // testing purposes.
  // Flags::DebugIsInt("codealign", &alignment);
  ASSERT(Utils::IsPowerOfTwo(alignment));
  ASSERT(alignment >= kMinimumAlignment);
  ASSERT(alignment <= OS::kMaxPreferredCodeAlignment);
  return alignment;
}

bool OS::AllowStackFrameIteratorFromAnotherThread() {
  UNIMPLEMENTED();
  return false;
}

int OS::NumberOfAvailableProcessors() {
  return sysconf(_SC_NPROCESSORS_CONF);
}

void OS::Sleep(int64_t millis) {
  mx_nanosleep(
      millis * kMicrosecondsPerMillisecond * kNanosecondsPerMicrosecond);
}

void OS::SleepMicros(int64_t micros) {
  mx_nanosleep(
      micros * kNanosecondsPerMicrosecond);
}

void OS::DebugBreak() {
  UNIMPLEMENTED();
}

char* OS::StrNDup(const char* s, intptr_t n) {
  return strndup(s, n);
}

intptr_t OS::StrNLen(const char* s, intptr_t n) {
  return strnlen(s, n);
}

void OS::Print(const char* format, ...) {
  va_list args;
  va_start(args, format);
  VFPrint(stdout, format, args);
  va_end(args);
}

void OS::VFPrint(FILE* stream, const char* format, va_list args) {
  vfprintf(stream, format, args);
  fflush(stream);
}

int OS::SNPrint(char* str, size_t size, const char* format, ...) {
  va_list args;
  va_start(args, format);
  int retval = VSNPrint(str, size, format, args);
  va_end(args);
  return retval;
}

int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
  int retval = vsnprintf(str, size, format, args);
  if (retval < 0) {
    FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
  }
  return retval;
}

char* OS::SCreate(Zone* zone, const char* format, ...) {
  va_list args;
  va_start(args, format);
  char* buffer = VSCreate(zone, format, args);
  va_end(args);
  return buffer;
}

char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
  // Measure.
  va_list measure_args;
  va_copy(measure_args, args);
  intptr_t len = VSNPrint(NULL, 0, format, measure_args);
  va_end(measure_args);

  char* buffer;
  if (zone) {
    buffer = zone->Alloc<char>(len + 1);
  } else {
    buffer = reinterpret_cast<char*>(malloc(len + 1));
  }
  ASSERT(buffer != NULL);

  // Print.
  va_list print_args;
  va_copy(print_args, args);
  VSNPrint(buffer, len + 1, format, print_args);
  va_end(print_args);
  return buffer;
}

bool OS::StringToInt64(const char* str, int64_t* value) {
  ASSERT(str != NULL && strlen(str) > 0 && value != NULL);
  int32_t base = 10;
  char* endptr;
  int i = 0;
  if (str[0] == '-') {
    i = 1;
  }
  if ((str[i] == '0') &&
      (str[i + 1] == 'x' || str[i + 1] == 'X') &&
      (str[i + 2] != '\0')) {
    base = 16;
  }
  errno = 0;
  *value = strtoll(str, &endptr, base);
  return ((errno == 0) && (endptr != str) && (*endptr == 0));
}

void OS::RegisterCodeObservers() {
#ifndef PRODUCT
  if (FLAG_generate_perf_events_symbols) {
    UNIMPLEMENTED();
  }
#endif  // !PRODUCT
}

void OS::PrintErr(const char* format, ...) {
  va_list args;
  va_start(args, format);
  VFPrint(stderr, format, args);
  va_end(args);
}

void OS::InitOnce() {
  // TODO(5411554): For now we check that initonce is called only once,
  // Once there is more formal mechanism to call InitOnce we can move
  // this check there.
  static bool init_once_called = false;
  ASSERT(init_once_called == false);
  init_once_called = true;
}

void OS::Shutdown() {
}

void OS::Abort() {
  abort();
}

void OS::Exit(int code) {
  UNIMPLEMENTED();
}

}  // namespace dart

#endif  // defined(TARGET_OS_FUCHSIA)
<commit_msg>[Fuchsia] Fix build<commit_after>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "vm/globals.h"
#if defined(TARGET_OS_FUCHSIA)

#include "vm/os.h"

#include <errno.h>
#include <magenta/syscalls.h>
#include <magenta/types.h>

#include "platform/assert.h"
#include "vm/zone.h"

namespace dart {

#ifndef PRODUCT

DEFINE_FLAG(bool, generate_perf_events_symbols, false,
    "Generate events symbols for profiling with perf");

#endif  // !PRODUCT

const char* OS::Name() {
  return "fuchsia";
}

intptr_t OS::ProcessId() {
  return static_cast<intptr_t>(getpid());
}

const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) {
  UNIMPLEMENTED();
  return "";
}

int OS::GetTimeZoneOffsetInSeconds(int64_t seconds_since_epoch) {
  UNIMPLEMENTED();
  return 0;
}

int OS::GetLocalTimeZoneAdjustmentInSeconds() {
  UNIMPLEMENTED();
  return 0;
}

int64_t OS::GetCurrentTimeMillis() {
  return GetCurrentTimeMicros() / 1000;
}

int64_t OS::GetCurrentTimeMicros() {
  return mx_current_time() / 1000;
}

int64_t OS::GetCurrentMonotonicTicks() {
  return mx_current_time();
}

int64_t OS::GetCurrentMonotonicFrequency() {
  return kNanosecondsPerSecond;
}

int64_t OS::GetCurrentMonotonicMicros() {
  int64_t ticks = GetCurrentMonotonicTicks();
  ASSERT(GetCurrentMonotonicFrequency() == kNanosecondsPerSecond);
  return ticks / kNanosecondsPerMicrosecond;
}

int64_t OS::GetCurrentThreadCPUMicros() {
  UNIMPLEMENTED();
  return 0;
}

void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) {
  const int kMinimumAlignment = 16;
  ASSERT(Utils::IsPowerOfTwo(alignment));
  ASSERT(alignment >= kMinimumAlignment);
  void* p = memalign(alignment, size);
  if (p == NULL) {
    UNREACHABLE();
  }
  return p;
}

void OS::AlignedFree(void* ptr) {
  free(ptr);
}

// TODO(5411554):  May need to hoist these architecture dependent code
// into a architecture specific file e.g: os_ia32_fuchsia.cc
intptr_t OS::ActivationFrameAlignment() {
#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) || \
    defined(TARGET_ARCH_ARM64)
  const int kMinimumAlignment = 16;
#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_DBC)
  const int kMinimumAlignment = 8;
#else
#error Unsupported architecture.
#endif
  intptr_t alignment = kMinimumAlignment;
  // TODO(5411554): Allow overriding default stack alignment for
  // testing purposes.
  // Flags::DebugIsInt("stackalign", &alignment);
  ASSERT(Utils::IsPowerOfTwo(alignment));
  ASSERT(alignment >= kMinimumAlignment);
  return alignment;
}

intptr_t OS::PreferredCodeAlignment() {
#if defined(TARGET_ARCH_IA32) ||                                               \
    defined(TARGET_ARCH_X64) ||                                                \
    defined(TARGET_ARCH_ARM64) ||                                              \
    defined(TARGET_ARCH_DBC)
  const int kMinimumAlignment = 32;
#elif defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS)
  const int kMinimumAlignment = 16;
#else
#error Unsupported architecture.
#endif
  intptr_t alignment = kMinimumAlignment;
  // TODO(5411554): Allow overriding default code alignment for
  // testing purposes.
  // Flags::DebugIsInt("codealign", &alignment);
  ASSERT(Utils::IsPowerOfTwo(alignment));
  ASSERT(alignment >= kMinimumAlignment);
  ASSERT(alignment <= OS::kMaxPreferredCodeAlignment);
  return alignment;
}

bool OS::AllowStackFrameIteratorFromAnotherThread() {
  UNIMPLEMENTED();
  return false;
}

int OS::NumberOfAvailableProcessors() {
  return sysconf(_SC_NPROCESSORS_CONF);
}

uintptr_t OS::MaxRSS() {
  UNIMPLEMENTED();
  return 0;
}

void OS::Sleep(int64_t millis) {
  mx_nanosleep(
      millis * kMicrosecondsPerMillisecond * kNanosecondsPerMicrosecond);
}

void OS::SleepMicros(int64_t micros) {
  mx_nanosleep(
      micros * kNanosecondsPerMicrosecond);
}

void OS::DebugBreak() {
  UNIMPLEMENTED();
}

char* OS::StrNDup(const char* s, intptr_t n) {
  return strndup(s, n);
}

intptr_t OS::StrNLen(const char* s, intptr_t n) {
  return strnlen(s, n);
}

void OS::Print(const char* format, ...) {
  va_list args;
  va_start(args, format);
  VFPrint(stdout, format, args);
  va_end(args);
}

void OS::VFPrint(FILE* stream, const char* format, va_list args) {
  vfprintf(stream, format, args);
  fflush(stream);
}

int OS::SNPrint(char* str, size_t size, const char* format, ...) {
  va_list args;
  va_start(args, format);
  int retval = VSNPrint(str, size, format, args);
  va_end(args);
  return retval;
}

int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
  int retval = vsnprintf(str, size, format, args);
  if (retval < 0) {
    FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
  }
  return retval;
}

char* OS::SCreate(Zone* zone, const char* format, ...) {
  va_list args;
  va_start(args, format);
  char* buffer = VSCreate(zone, format, args);
  va_end(args);
  return buffer;
}

char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
  // Measure.
  va_list measure_args;
  va_copy(measure_args, args);
  intptr_t len = VSNPrint(NULL, 0, format, measure_args);
  va_end(measure_args);

  char* buffer;
  if (zone) {
    buffer = zone->Alloc<char>(len + 1);
  } else {
    buffer = reinterpret_cast<char*>(malloc(len + 1));
  }
  ASSERT(buffer != NULL);

  // Print.
  va_list print_args;
  va_copy(print_args, args);
  VSNPrint(buffer, len + 1, format, print_args);
  va_end(print_args);
  return buffer;
}

bool OS::StringToInt64(const char* str, int64_t* value) {
  ASSERT(str != NULL && strlen(str) > 0 && value != NULL);
  int32_t base = 10;
  char* endptr;
  int i = 0;
  if (str[0] == '-') {
    i = 1;
  }
  if ((str[i] == '0') &&
      (str[i + 1] == 'x' || str[i + 1] == 'X') &&
      (str[i + 2] != '\0')) {
    base = 16;
  }
  errno = 0;
  *value = strtoll(str, &endptr, base);
  return ((errno == 0) && (endptr != str) && (*endptr == 0));
}

void OS::RegisterCodeObservers() {
#ifndef PRODUCT
  if (FLAG_generate_perf_events_symbols) {
    UNIMPLEMENTED();
  }
#endif  // !PRODUCT
}

void OS::PrintErr(const char* format, ...) {
  va_list args;
  va_start(args, format);
  VFPrint(stderr, format, args);
  va_end(args);
}

void OS::InitOnce() {
  // TODO(5411554): For now we check that initonce is called only once,
  // Once there is more formal mechanism to call InitOnce we can move
  // this check there.
  static bool init_once_called = false;
  ASSERT(init_once_called == false);
  init_once_called = true;
}

void OS::Shutdown() {
}

void OS::Abort() {
  abort();
}

void OS::Exit(int code) {
  UNIMPLEMENTED();
}

}  // namespace dart

#endif  // defined(TARGET_OS_FUCHSIA)
<|endoftext|>


<commit_before>/**
Copyright (c) 2013, Arlei Silva
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.
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 HOLDER 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.

@author: Arlei Silva (arleilps@gmail.com)
**/

/**
 *	FILE io.cc: Implementation of I/O operations.
**/

/*my includes*/
#include "io.h"

/*Setting default values for the parameters*/
std::string Parameters::graph_file_name = "";
std::string Parameters::values_file_name = "";
std::string Parameters::compression_algorithm = "";
std::string Parameters::output_file_name = "";
std::string Parameters::partition_sizes_file_name = "";
unsigned int Parameters::budget = 0;
unsigned int Parameters::num_partitions = 0;
double Parameters::sampling_rate = 0;
unsigned int Parameters::num_threads = 1;
double Parameters::delta = 0.9;
unsigned int Parameters::max_radius = USHRT_MAX;
double Parameters::rho = 1;
bool Parameters::directed = false;
bool Parameters::print_tree = false;
bool Parameters::exhaustive_split = false;
std::vector<std::string> Parameters::compression_algorithms;

/**
 * Prints the usage of this program
 * @param
 * @return
 * @throws
**/
void Parameters::print_usage()
{
	std::cout << "Usage: ./graph_compression [OPTIONS]..." << std::endl;
	std::cout << "Compresses the values in a graph using the specified algorithm" << std::endl;
	std::cout << " -g, --graph		input graph file" << std::endl;
	std::cout << " -v, --value		input values file" << std::endl;
	std::cout << " -o, --output		output file name" << std::endl;
	std::cout << " -c, --compression	compression algorithm" << std::endl;
	std::cout << " -b, --budget		one or more budget values (bytes)" << std::endl;
	std::cout << " -p, --numpart		one or more numbers of partitions" << std::endl;
	std::cout << " -n, --sampling-rate	sampling rate" << std::endl;
	std::cout << " -s, --partsizes		file with pre-computed partition sizes" << std::endl;
	std::cout << " -t, --numthreads		number of threads to be used" << std::endl;
	std::cout << " -d, --delta		confidence parameter for compression" << std::endl;
	std::cout << " -m, --maxradius		max radius for slice tree compression" << std::endl;
	std::cout << " -r, --rho		approximation constant" << std::endl;
	std::cout << " -e, --directed		if the input graph is directed" << std::endl;
	std::cout << " -i, --print-tree		prints the ST (only when comrression is ST/STUS/STBS) " << std::endl;
	std::cout << " -x, --exhaustive-split		Exhaustively compares slices in all partitions (ST/STBS/STUS only). Significantly slower when set. " << std::endl;
}

/**
 * Reads the input parameters for the compression
 * @param argc size of the command line
 * @param argv string command line
 * @return
 * @throws invalidParameterSettingException
**/
bool Parameters::read(int argc, char** argv) throw (InvalidParameterSettingException)
{
	InvalidParameterSettingException invalid_parameters;

	try
	{
		GetOpt::GetOpt_pp ops(argc, argv);

		if (ops >> GetOpt::OptionPresent('e', "directed"))
		{
			directed = true;
		}
		if (ops >> GetOpt::OptionPresent('i', "print-tree"))
		{
			print_tree = true;
		}
		if (ops >> GetOpt::OptionPresent('x', "exhaustive-split"))
		{
			exhaustive_split = true;
		}

		if (ops >> GetOpt::OptionPresent('h', "help"))
		{
			print_usage();

			return false;
		}

		ops >> GetOpt::Option('g', "graph", graph_file_name, "")
		>> GetOpt::Option('v', "values", values_file_name, "")
		>> GetOpt::Option('o', "output", output_file_name, "")
		>> GetOpt::Option('c', "compression", compression_algorithm, "")
		>> GetOpt::Option('b', "budget", budget)
		>> GetOpt::Option('p', "numpart", num_partitions)
		>> GetOpt::Option('n', "sampling-rate", sampling_rate)
		>> GetOpt::Option('s', "partsizes", partition_sizes_file_name)
		>> GetOpt::Option('t', "numthreads", num_threads)
		>> GetOpt::Option('d', "delta", delta)
		>> GetOpt::Option('m', "maxradius", max_radius)
		>> GetOpt::Option('r', "rho", rho)
		;
	}
	catch(GetOpt::GetOptEx& e)
	{
		std::cerr << "Fatal error while parsing the command line parameters!" << std::endl;
		std::cerr << "Try \'./graph_compression --help\' for more information." << std::endl;
		throw invalid_parameters;
	}

	return true;
}

/**
 * Prints the input parameters on the terminal
 * @param
 * @return
 * @throws
**/
void Parameters::print()
{
	std::cout << "graph: " << graph_file_name << std::endl;
	std::cout << "values: " << values_file_name << "\n";
	std::cout << "compression algorithm: " << compression_algorithm << std::endl;
	std::cout << "output: " << output_file_name << std::endl;
	std::cout << "budget: " << budget << std::endl;
	std::cout << "num_partitions: " << num_partitions << std::endl;
}

/**
 * Sets the list of valid compression algorithms, so that
 * an algorithm given as input can be checked
 * @param algorithms vector with the valid algorithm identifiers
 * @return
 * @throws
 **/
void Parameters::set_compression_algorithms(std::vector<std::string>& algorithms)
{
	compression_algorithms = algorithms;
}

<commit_msg>Fix option typo and formatting.<commit_after>/**
Copyright (c) 2013, Arlei Silva
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.
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 HOLDER 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.

@author: Arlei Silva (arleilps@gmail.com)
**/

/**
 *	FILE io.cc: Implementation of I/O operations.
**/

/*my includes*/
#include "io.h"

/*Setting default values for the parameters*/
std::string Parameters::graph_file_name = "";
std::string Parameters::values_file_name = "";
std::string Parameters::compression_algorithm = "";
std::string Parameters::output_file_name = "";
std::string Parameters::partition_sizes_file_name = "";
unsigned int Parameters::budget = 0;
unsigned int Parameters::num_partitions = 0;
double Parameters::sampling_rate = 0;
unsigned int Parameters::num_threads = 1;
double Parameters::delta = 0.9;
unsigned int Parameters::max_radius = USHRT_MAX;
double Parameters::rho = 1;
bool Parameters::directed = false;
bool Parameters::print_tree = false;
bool Parameters::exhaustive_split = false;
std::vector<std::string> Parameters::compression_algorithms;

/**
 * Prints the usage of this program
 * @param
 * @return
 * @throws
**/
void Parameters::print_usage()
{
	std::cout << "Usage: ./graph_compression [OPTIONS]..." << std::endl;
	std::cout << "Compresses the values in a graph using the specified algorithm" << std::endl;
	std::cout << " -g, --graph             input graph file" << std::endl;
	std::cout << " -v, --values            input values file" << std::endl;
	std::cout << " -o, --output            output file name" << std::endl;
	std::cout << " -c, --compression	   compression algorithm" << std::endl;
	std::cout << " -b, --budget            one or more budget values (bytes)" << std::endl;
	std::cout << " -p, --numpart		   one or more numbers of partitions" << std::endl;
	std::cout << " -n, --sampling-rate     sampling rate" << std::endl;
	std::cout << " -s, --partsizes         file with pre-computed partition sizes" << std::endl;
	std::cout << " -t, --numthreads        number of threads to be used" << std::endl;
	std::cout << " -d, --delta             confidence parameter for compression" << std::endl;
	std::cout << " -m, --maxradius         max radius for slice tree compression" << std::endl;
	std::cout << " -r, --rho               approximation constant" << std::endl;
	std::cout << " -e, --directed          if the input graph is directed" << std::endl;
	std::cout << " -i, --print-tree        prints the ST (only when comrression is ST/STUS/STBS) " << std::endl;
	std::cout << " -x, --exhaustive-split  Exhaustively compares slices in all partitions (ST/STBS/STUS only). Significantly slower when set. " << std::endl;
}

/**
 * Reads the input parameters for the compression
 * @param argc size of the command line
 * @param argv string command line
 * @return
 * @throws invalidParameterSettingException
**/
bool Parameters::read(int argc, char** argv) throw (InvalidParameterSettingException)
{
	InvalidParameterSettingException invalid_parameters;

	try
	{
		GetOpt::GetOpt_pp ops(argc, argv);

		if (ops >> GetOpt::OptionPresent('e', "directed"))
		{
			directed = true;
		}
		if (ops >> GetOpt::OptionPresent('i', "print-tree"))
		{
			print_tree = true;
		}
		if (ops >> GetOpt::OptionPresent('x', "exhaustive-split"))
		{
			exhaustive_split = true;
		}

		if (ops >> GetOpt::OptionPresent('h', "help"))
		{
			print_usage();

			return false;
		}

		ops >> GetOpt::Option('g', "graph", graph_file_name, "")
		    >> GetOpt::Option('v', "values", values_file_name, "")
		    >> GetOpt::Option('o', "output", output_file_name, "")
		    >> GetOpt::Option('c', "compression", compression_algorithm, "")
		    >> GetOpt::Option('b', "budget", budget)
		    >> GetOpt::Option('p', "numpart", num_partitions)
		    >> GetOpt::Option('n', "sampling-rate", sampling_rate)
		    >> GetOpt::Option('s', "partsizes", partition_sizes_file_name)
		    >> GetOpt::Option('t', "numthreads", num_threads)
		    >> GetOpt::Option('d', "delta", delta)
		    >> GetOpt::Option('m', "maxradius", max_radius)
		    >> GetOpt::Option('r', "rho", rho);
	}
	catch(GetOpt::GetOptEx& e)
	{
		std::cerr << "Fatal error while parsing the command line parameters!" << std::endl;
		std::cerr << "Try \'./graph_compression --help\' for more information." << std::endl;
		throw invalid_parameters;
	}

	return true;
}

/**
 * Prints the input parameters on the terminal
 * @param
 * @return
 * @throws
**/
void Parameters::print()
{
	std::cout << "graph: " << graph_file_name << std::endl;
	std::cout << "values: " << values_file_name << "\n";
	std::cout << "compression algorithm: " << compression_algorithm << std::endl;
	std::cout << "output: " << output_file_name << std::endl;
	std::cout << "budget: " << budget << std::endl;
	std::cout << "num_partitions: " << num_partitions << std::endl;
}

/**
 * Sets the list of valid compression algorithms, so that
 * an algorithm given as input can be checked
 * @param algorithms vector with the valid algorithm identifiers
 * @return
 * @throws
 **/
void Parameters::set_compression_algorithms(std::vector<std::string>& algorithms)
{
	compression_algorithms = algorithms;
}

<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "coretext/common.h"

#ifdef MACOSX

#include "aqua/salframe.h"
#include "coretext/salgdi.h"

#else

#include <premac.h>
#include <UIKit/UIKit.h>
#include <postmac.h>

#include <basebmp/scanlineformats.hxx>

#include "saldatabasic.hxx"
#include "headless/svpframe.hxx"
#include "headless/svpgdi.hxx"

#endif

#include "coretext/salcoretextstyle.hxx"

#ifdef MACOSX

QuartzSalGraphics::QuartzSalGraphics()
    : mpFrame( NULL )
    , mxLayer( NULL )
    , mrContext( NULL )
    , mpXorEmulation( NULL )
    , mnXorMode( 0 )
    , mnWidth( 0 )
    , mnHeight( 0 )
    , mnBitmapDepth( 0 )
    , mnRealDPIX( 0 )
    , mnRealDPIY( 0 )
    , mfFakeDPIScale( 1.0 )
    , mxClipPath( NULL )
    , maLineColor( COL_WHITE )
    , maFillColor( COL_BLACK )
    , mbNonAntialiasedText( false )
    , mbPrinter( false )
    , mbVirDev( false )
    , mbWindow( false )
{
    SAL_INFO( "vcl.coretext.gr", "QuartzSalGraphics::QuartzSalGraphics() " << this );

    m_style = new CoreTextStyleInfo();
}

QuartzSalGraphics::~QuartzSalGraphics()
{
    SAL_INFO( "vcl.coretext.gr", "~QuartzSalGraphics(" << this << ")" );

    if(m_style)
    {
        delete m_style;
        m_style = NULL;
    }
}

#endif

inline bool QuartzSalGraphics::AddTempDevFont( ImplDevFontList*,
                                             const OUString& ,
                                             const OUString& )
{
    OSL_ASSERT( FALSE );
    return false;
}

void QuartzSalGraphics::DrawServerFontLayout( const ServerFontLayout& )
{
}

void QuartzSalGraphics::FreeEmbedFontData( const void* pData, long /*nDataLen*/ )
{
    // TODO: implementing this only makes sense when the implementation of
    //      QuartzSalGraphics::GetEmbedFontData() returns non-NULL
    (void)pData;
    DBG_ASSERT( (pData!=NULL), "QuartzSalGraphics::FreeEmbedFontData() is not implemented\n");
}

void QuartzSalGraphics::GetDevFontList( ImplDevFontList* pFontList )
{
    DBG_ASSERT( pFontList, "QuartzSalGraphics::GetDevFontList(NULL) !");

    SalData* pSalData = GetSalData();
    if (pSalData->mpFontList == NULL)
    {
        pSalData->mpFontList = new SystemFontList();
    }
    // Copy all PhysicalFontFace objects contained in the SystemFontList
    pSalData->mpFontList->AnnounceFonts( *pFontList );
}

void QuartzSalGraphics::ClearDevFontCache()
{
    SalData* pSalData = GetSalData();
    delete pSalData->mpFontList;
    pSalData->mpFontList = NULL;
}

void QuartzSalGraphics::GetDevFontSubstList( OutputDevice* )
{
    // nothing to do since there are no device-specific fonts on Aqua
}

const void* QuartzSalGraphics::GetEmbedFontData( const PhysicalFontFace*,
                              const sal_Ucs* /*pUnicodes*/,
                              sal_Int32* /*pWidths*/,
                              FontSubsetInfo&,
                              long* /*pDataLen*/ )
{
    return NULL;
}

const Ucs2SIntMap* QuartzSalGraphics::GetFontEncodingVector(const PhysicalFontFace*,
                                                          const Ucs2OStrMap** /*ppNonEncoded*/ )
{
    return NULL;
}

void QuartzSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int nFallbackLevel )
{
    (void)nFallbackLevel; // glyph-fallback on CoreText is done differently -> no fallback level

    pMetric->mbScalableFont = true;
    pMetric->mbKernableFont = true;
    CTFontRef font = m_style->GetFont();
    DBG_ASSERT(font, "GetFontMetric without font set in style");

    pMetric->mnAscent = static_cast<long>( CTFontGetAscent(font) * mfFakeDPIScale + 0.5);
    pMetric->mnDescent = static_cast<long>(CTFontGetDescent(font) * mfFakeDPIScale + 0.5);
    const long nExtDescent  = static_cast<long>((CTFontGetLeading(font) + CTFontGetDescent(font)) *
                                                mfFakeDPIScale + 0.5);
    pMetric->mnExtLeading   = nExtDescent + pMetric->mnDescent;
    pMetric->mnIntLeading   = 0;
    pMetric->mnWidth = m_style->GetFontStretchedSize();

    SAL_INFO( "vcl.coretext.gr",
              "GetFontMetric(" << this << ") returning: {ascent=" << pMetric->mnAscent <<
              ",descent=" << pMetric->mnDescent <<
              ",extleading=" << pMetric->mnExtLeading <<
              ",intleading=" << pMetric->mnIntLeading <<
              ",width=" << pMetric->mnWidth <<
              "}" );
}

sal_Bool QuartzSalGraphics::GetGlyphBoundRect( sal_GlyphId /*nGlyphId*/, Rectangle& /*rRect*/ )
{
    /* TODO: create a Ghyph iterator to keep track ot 'state' between call */
    return false;
}

sal_Bool QuartzSalGraphics::GetGlyphOutline( sal_GlyphId /*nGlyphId*/, basegfx::B2DPolyPolygon& /*rPolyPoly*/ )
{
    /* TODO */
    return false;
}

void QuartzSalGraphics::GetGlyphWidths( const PhysicalFontFace* /*pFontData*/, bool /*bVertical*/,
                                      Int32Vector& /*rGlyphWidths*/, Ucs2UIntMap& /*rUnicodeEnc*/ )
{
}

sal_uLong QuartzSalGraphics::GetKernPairs( sal_uLong, ImplKernPairData* )
{
    return 0;
}

bool QuartzSalGraphics::GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
{
    if( !m_style )
    {
        return false;
    }
    CoreTextPhysicalFontFace* font_face = m_style->GetFontFace();
    if( !font_face)
    {
        return false;
    }
    return font_face->GetImplFontCapabilities(rFontCapabilities);
}

const ImplFontCharMap* QuartzSalGraphics::GetImplFontCharMap() const
{
    if( !m_style )
    {
        return NULL;
    }
    CoreTextPhysicalFontFace* font_face = m_style->GetFontFace();
    if( !font_face)
    {
        return ImplFontCharMap::GetDefaultMap();
    }
    return font_face->GetImplFontCharMap();
}

#ifndef IOS

bool QuartzSalGraphics::GetRawFontData( const PhysicalFontFace* pFontFace,
                     std::vector<unsigned char>& rBuffer, bool* pJustCFF )
{
    const CoreTextPhysicalFontFace* font_face = static_cast<const CoreTextPhysicalFontFace*>(pFontFace);

    return font_face->GetRawFontData(rBuffer, pJustCFF);
}

#endif

SystemFontData QuartzSalGraphics::GetSysFontData( int /* nFallbacklevel */ ) const
{
    SystemFontData aSysFontData;
    aSysFontData.nSize = sizeof( SystemFontData );
    aSysFontData.bAntialias = true;

    CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 0.0, NULL);
    font = (CTFontRef)CFRetain(font);
    aSysFontData.rCTFont = font;

    CTFontRef italic_font = CTFontCreateCopyWithSymbolicTraits( font,
                                                                0.0,
                                                                NULL,
                                                                kCTFontItalicTrait,
                                                                kCTFontItalicTrait + kCTFontBoldTrait);
    aSysFontData.bFakeItalic = italic_font ? false : true;
    SafeCFRelease(italic_font);

    CTFontRef bold_font = CTFontCreateCopyWithSymbolicTraits( font,
                                                              0.0,
                                                              NULL,
                                                              kCTFontBoldTrait,
                                                              kCTFontItalicTrait + kCTFontBoldTrait);
    aSysFontData.bFakeBold = bold_font ? false : true;
    SafeCFRelease(bold_font);

    CTFontRef vertical_font = CTFontCreateCopyWithSymbolicTraits( font,
                                                                  0.0,
                                                                  NULL,
                                                                  kCTFontVerticalTrait,
                                                                  kCTFontVerticalTrait);
    aSysFontData.bVerticalCharacterType = vertical_font ? true : false;
    SafeCFRelease(vertical_font);

    return aSysFontData;
}

sal_uInt16 QuartzSalGraphics::SetFont( FontSelectPattern* pReqFont, int /*nFallbackLevel*/ )
{
    m_style->SetFont(pReqFont);

    return 0;
}

void QuartzSalGraphics::SetTextColor( SalColor nSalColor )
{
    m_style->SetColor(nSalColor);
}

#ifdef IOS

// Note that "QuartzSalGraphics" *is* SvpSalGraphics for iOS

bool SvpSalGraphics::CheckContext()
{
    basegfx::B2IVector size = m_aDevice->getSize();
    basebmp::RawMemorySharedArray pixelBuffer = m_aDevice->getBuffer();

    SAL_INFO( "vcl.ios", "CheckContext: device=" << m_aDevice.get() << " size=" << size.getX() << "x" << size.getY() << (m_aDevice->isTopDown() ? " top-down" : " bottom-up") << " stride=" << m_aDevice->getScanlineStride() );

    switch( m_aDevice->getScanlineFormat() ) {
    case basebmp::Format::EIGHT_BIT_PAL:
        mrContext = CGBitmapContextCreate(pixelBuffer.get(),
                                          size.getX(), size.getY(),
                                          8, m_aDevice->getScanlineStride(),
                                          CGColorSpaceCreateDeviceGray(),
                                          kCGImageAlphaNone);
        break;
    case basebmp::Format::THIRTYTWO_BIT_TC_MASK_RGBA:
        mrContext = CGBitmapContextCreate(pixelBuffer.get(),
                                          size.getX(), size.getY(),
                                          8, m_aDevice->getScanlineStride(),
                                          CGColorSpaceCreateDeviceRGB(),
                                          kCGImageAlphaNoneSkipLast);
        break;
    default:
        SAL_INFO( "vcl.ios", "CheckContext: unsupported color format " << basebmp::Format::formatName( m_aDevice->getScanlineFormat() ) );
    }

    SAL_WARN_IF( mrContext == NULL, "vcl.ios", "CheckContext() failed" );

    if( mrContext != NULL && m_aDevice->isTopDown() )
    {
        CGContextTranslateCTM( mrContext, 0, size.getY() );
        CGContextScaleCTM( mrContext, 1, -1 );
    }

    return ( mrContext != NULL );
}

CGContextRef SvpSalGraphics::GetContext()
{
    if ( !mrContext )
        CheckContext();

    return mrContext;
}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>Use my improved understanding of what a subset BitmapDevice is<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "coretext/common.h"

#ifdef MACOSX

#include "aqua/salframe.h"
#include "coretext/salgdi.h"

#else

#include <premac.h>
#include <UIKit/UIKit.h>
#include <postmac.h>

#include <basebmp/scanlineformats.hxx>

#include "saldatabasic.hxx"
#include "headless/svpframe.hxx"
#include "headless/svpgdi.hxx"

#endif

#include "coretext/salcoretextstyle.hxx"

#ifdef MACOSX

QuartzSalGraphics::QuartzSalGraphics()
    : mpFrame( NULL )
    , mxLayer( NULL )
    , mrContext( NULL )
    , mpXorEmulation( NULL )
    , mnXorMode( 0 )
    , mnWidth( 0 )
    , mnHeight( 0 )
    , mnBitmapDepth( 0 )
    , mnRealDPIX( 0 )
    , mnRealDPIY( 0 )
    , mfFakeDPIScale( 1.0 )
    , mxClipPath( NULL )
    , maLineColor( COL_WHITE )
    , maFillColor( COL_BLACK )
    , mbNonAntialiasedText( false )
    , mbPrinter( false )
    , mbVirDev( false )
    , mbWindow( false )
{
    SAL_INFO( "vcl.coretext.gr", "QuartzSalGraphics::QuartzSalGraphics() " << this );

    m_style = new CoreTextStyleInfo();
}

QuartzSalGraphics::~QuartzSalGraphics()
{
    SAL_INFO( "vcl.coretext.gr", "~QuartzSalGraphics(" << this << ")" );

    if(m_style)
    {
        delete m_style;
        m_style = NULL;
    }
}

#endif

inline bool QuartzSalGraphics::AddTempDevFont( ImplDevFontList*,
                                             const OUString& ,
                                             const OUString& )
{
    OSL_ASSERT( FALSE );
    return false;
}

void QuartzSalGraphics::DrawServerFontLayout( const ServerFontLayout& )
{
}

void QuartzSalGraphics::FreeEmbedFontData( const void* pData, long /*nDataLen*/ )
{
    // TODO: implementing this only makes sense when the implementation of
    //      QuartzSalGraphics::GetEmbedFontData() returns non-NULL
    (void)pData;
    DBG_ASSERT( (pData!=NULL), "QuartzSalGraphics::FreeEmbedFontData() is not implemented\n");
}

void QuartzSalGraphics::GetDevFontList( ImplDevFontList* pFontList )
{
    DBG_ASSERT( pFontList, "QuartzSalGraphics::GetDevFontList(NULL) !");

    SalData* pSalData = GetSalData();
    if (pSalData->mpFontList == NULL)
    {
        pSalData->mpFontList = new SystemFontList();
    }
    // Copy all PhysicalFontFace objects contained in the SystemFontList
    pSalData->mpFontList->AnnounceFonts( *pFontList );
}

void QuartzSalGraphics::ClearDevFontCache()
{
    SalData* pSalData = GetSalData();
    delete pSalData->mpFontList;
    pSalData->mpFontList = NULL;
}

void QuartzSalGraphics::GetDevFontSubstList( OutputDevice* )
{
    // nothing to do since there are no device-specific fonts on Aqua
}

const void* QuartzSalGraphics::GetEmbedFontData( const PhysicalFontFace*,
                              const sal_Ucs* /*pUnicodes*/,
                              sal_Int32* /*pWidths*/,
                              FontSubsetInfo&,
                              long* /*pDataLen*/ )
{
    return NULL;
}

const Ucs2SIntMap* QuartzSalGraphics::GetFontEncodingVector(const PhysicalFontFace*,
                                                          const Ucs2OStrMap** /*ppNonEncoded*/ )
{
    return NULL;
}

void QuartzSalGraphics::GetFontMetric( ImplFontMetricData* pMetric, int nFallbackLevel )
{
    (void)nFallbackLevel; // glyph-fallback on CoreText is done differently -> no fallback level

    pMetric->mbScalableFont = true;
    pMetric->mbKernableFont = true;
    CTFontRef font = m_style->GetFont();
    DBG_ASSERT(font, "GetFontMetric without font set in style");

    pMetric->mnAscent = static_cast<long>( CTFontGetAscent(font) * mfFakeDPIScale + 0.5);
    pMetric->mnDescent = static_cast<long>(CTFontGetDescent(font) * mfFakeDPIScale + 0.5);
    const long nExtDescent  = static_cast<long>((CTFontGetLeading(font) + CTFontGetDescent(font)) *
                                                mfFakeDPIScale + 0.5);
    pMetric->mnExtLeading   = nExtDescent + pMetric->mnDescent;
    pMetric->mnIntLeading   = 0;
    pMetric->mnWidth = m_style->GetFontStretchedSize();

    SAL_INFO( "vcl.coretext.gr",
              "GetFontMetric(" << this << ") returning: {ascent=" << pMetric->mnAscent <<
              ",descent=" << pMetric->mnDescent <<
              ",extleading=" << pMetric->mnExtLeading <<
              ",intleading=" << pMetric->mnIntLeading <<
              ",width=" << pMetric->mnWidth <<
              "}" );
}

sal_Bool QuartzSalGraphics::GetGlyphBoundRect( sal_GlyphId /*nGlyphId*/, Rectangle& /*rRect*/ )
{
    /* TODO: create a Ghyph iterator to keep track ot 'state' between call */
    return false;
}

sal_Bool QuartzSalGraphics::GetGlyphOutline( sal_GlyphId /*nGlyphId*/, basegfx::B2DPolyPolygon& /*rPolyPoly*/ )
{
    /* TODO */
    return false;
}

void QuartzSalGraphics::GetGlyphWidths( const PhysicalFontFace* /*pFontData*/, bool /*bVertical*/,
                                      Int32Vector& /*rGlyphWidths*/, Ucs2UIntMap& /*rUnicodeEnc*/ )
{
}

sal_uLong QuartzSalGraphics::GetKernPairs( sal_uLong, ImplKernPairData* )
{
    return 0;
}

bool QuartzSalGraphics::GetImplFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const
{
    if( !m_style )
    {
        return false;
    }
    CoreTextPhysicalFontFace* font_face = m_style->GetFontFace();
    if( !font_face)
    {
        return false;
    }
    return font_face->GetImplFontCapabilities(rFontCapabilities);
}

const ImplFontCharMap* QuartzSalGraphics::GetImplFontCharMap() const
{
    if( !m_style )
    {
        return NULL;
    }
    CoreTextPhysicalFontFace* font_face = m_style->GetFontFace();
    if( !font_face)
    {
        return ImplFontCharMap::GetDefaultMap();
    }
    return font_face->GetImplFontCharMap();
}

#ifndef IOS

bool QuartzSalGraphics::GetRawFontData( const PhysicalFontFace* pFontFace,
                     std::vector<unsigned char>& rBuffer, bool* pJustCFF )
{
    const CoreTextPhysicalFontFace* font_face = static_cast<const CoreTextPhysicalFontFace*>(pFontFace);

    return font_face->GetRawFontData(rBuffer, pJustCFF);
}

#endif

SystemFontData QuartzSalGraphics::GetSysFontData( int /* nFallbacklevel */ ) const
{
    SystemFontData aSysFontData;
    aSysFontData.nSize = sizeof( SystemFontData );
    aSysFontData.bAntialias = true;

    CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontSystemFontType, 0.0, NULL);
    font = (CTFontRef)CFRetain(font);
    aSysFontData.rCTFont = font;

    CTFontRef italic_font = CTFontCreateCopyWithSymbolicTraits( font,
                                                                0.0,
                                                                NULL,
                                                                kCTFontItalicTrait,
                                                                kCTFontItalicTrait + kCTFontBoldTrait);
    aSysFontData.bFakeItalic = italic_font ? false : true;
    SafeCFRelease(italic_font);

    CTFontRef bold_font = CTFontCreateCopyWithSymbolicTraits( font,
                                                              0.0,
                                                              NULL,
                                                              kCTFontBoldTrait,
                                                              kCTFontItalicTrait + kCTFontBoldTrait);
    aSysFontData.bFakeBold = bold_font ? false : true;
    SafeCFRelease(bold_font);

    CTFontRef vertical_font = CTFontCreateCopyWithSymbolicTraits( font,
                                                                  0.0,
                                                                  NULL,
                                                                  kCTFontVerticalTrait,
                                                                  kCTFontVerticalTrait);
    aSysFontData.bVerticalCharacterType = vertical_font ? true : false;
    SafeCFRelease(vertical_font);

    return aSysFontData;
}

sal_uInt16 QuartzSalGraphics::SetFont( FontSelectPattern* pReqFont, int /*nFallbackLevel*/ )
{
    m_style->SetFont(pReqFont);

    return 0;
}

void QuartzSalGraphics::SetTextColor( SalColor nSalColor )
{
    m_style->SetColor(nSalColor);
}

#ifdef IOS

// Note that "QuartzSalGraphics" *is* SvpSalGraphics for iOS

bool SvpSalGraphics::CheckContext()
{
    const basegfx::B2IVector size = m_aDevice->getSize();
    const basegfx::B2IVector bufferSize = m_aDevice->getBufferSize();
    const sal_Int32 scanlineStride = m_aDevice->getScanlineStride();
    basebmp::RawMemorySharedArray pixelBuffer = m_aDevice->getBuffer();

    SAL_INFO( "vcl.ios",
              "CheckContext: device=" << m_aDevice.get() <<
              " size=" << size.getX() << "x" << size.getY() <<
              (m_aDevice->isTopDown() ? " top-down" : " bottom-up") <<
              " stride=" << scanlineStride <<
              " bufferSize=(" << bufferSize.getX() << "," << bufferSize.getY() << ")" );

    switch( m_aDevice->getScanlineFormat() ) {
    case basebmp::Format::EIGHT_BIT_PAL:
        mrContext = CGBitmapContextCreate(pixelBuffer.get(),
                                          bufferSize.getX(), bufferSize.getY(),
                                          8, scanlineStride,
                                          CGColorSpaceCreateDeviceGray(),
                                          kCGImageAlphaNone);
        break;
    case basebmp::Format::THIRTYTWO_BIT_TC_MASK_RGBA:
        mrContext = CGBitmapContextCreate(pixelBuffer.get(),
                                          bufferSize.getX(), bufferSize.getY(),
                                          8, scanlineStride,
                                          CGColorSpaceCreateDeviceRGB(),
                                          kCGImageAlphaNoneSkipLast);
        break;
    default:
        SAL_INFO( "vcl.ios", "CheckContext: unsupported color format " << basebmp::Format::formatName( m_aDevice->getScanlineFormat() ) );
    }

    SAL_WARN_IF( mrContext == NULL, "vcl.ios", "CheckContext() failed" );

    // Should we also clip the context? (Then we need to add a
    // getBounds() function to BitmapDevice.)

    if( mrContext != NULL && m_aDevice->isTopDown() )
    {
        CGContextTranslateCTM( mrContext, 0, bufferSize.getY() );
        CGContextScaleCTM( mrContext, 1, -1 );
    }

    SAL_INFO( "vcl.ios", "CheckContext: context=" << mrContext );

    return ( mrContext != NULL );
}

CGContextRef SvpSalGraphics::GetContext()
{
    if ( !mrContext )
        CheckContext();

    return mrContext;
}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: bmpfast.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2007-07-24 09:57:51 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _SV_BMPFAST_HXX
#define _SV_BMPFAST_HXX

class BitmapWriteAccess;
class BitmapReadAccess;
struct BitmapBuffer;
class BitmapColor;
class Size;
class Point;
struct SalTwoRect;

// the bmpfast functions have signatures with good compatibility to
// their canonic counterparts, which employ the GetPixel/SetPixel methods

bool ImplFastBitmapConversion( BitmapBuffer& rDst, const BitmapBuffer& rSrc,
        const SalTwoRect& rTwoRect );

bool ImplFastBitmapBlending( BitmapWriteAccess& rDst,
    const BitmapReadAccess& rSrc, const BitmapReadAccess& rMask,
    const SalTwoRect& rTwoRect );

bool ImplFastEraseBitmap( BitmapBuffer&, const BitmapColor& );

#endif // _SV_BMPFAST_HXX
<commit_msg>INTEGRATION: CWS changefileheader (1.2.224); FILE MERGED 2008/03/28 15:44:09 rt 1.2.224.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: bmpfast.hxx,v $
 * $Revision: 1.3 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SV_BMPFAST_HXX
#define _SV_BMPFAST_HXX

class BitmapWriteAccess;
class BitmapReadAccess;
struct BitmapBuffer;
class BitmapColor;
class Size;
class Point;
struct SalTwoRect;

// the bmpfast functions have signatures with good compatibility to
// their canonic counterparts, which employ the GetPixel/SetPixel methods

bool ImplFastBitmapConversion( BitmapBuffer& rDst, const BitmapBuffer& rSrc,
        const SalTwoRect& rTwoRect );

bool ImplFastBitmapBlending( BitmapWriteAccess& rDst,
    const BitmapReadAccess& rSrc, const BitmapReadAccess& rMask,
    const SalTwoRect& rTwoRect );

bool ImplFastEraseBitmap( BitmapBuffer&, const BitmapColor& );

#endif // _SV_BMPFAST_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: saldata.hxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SV_SALDATA_HXX
#define _SV_SALDATA_HXX

#include <vcl/sv.h>
#include <vcl/svdata.hxx>
#include <vcl/salwtype.hxx>

class Os2SalInstance;
class Os2SalFrame;
class Os2SalObject;

extern "C" int debug_printf(const char *f, ...);

// --------------
// - SalIMEData -
// --------------

// YD FIXME #define ENABLE_IME

#ifdef ENABLE_IME

struct SalIMEData;

#ifdef OS2IM_INCLUDED

typedef APIRET (APIENTRY ImAssociateInstanceFunc)( HWND hwnd, HIMI himi, PHIMI phimiPrev );
typedef APIRET (APIENTRY ImGetInstanceFunc)( HWND hwnd, PHIMI phimi );
typedef APIRET (APIENTRY ImReleaseInstanceFunc)( HWND hwnd, HIMI himi );
typedef APIRET (APIENTRY ImSetConversionFontFunc)( HIMI himi, PFATTRS pFontAttrs );
typedef APIRET (APIENTRY ImSetConversionFontSizeFunc)( HIMI himi, PSIZEF psizfxBox );
typedef APIRET (APIENTRY ImGetConversionStringFunc)( HIMI himi, ULONG ulIndex, PVOID pBuf, PULONG pulBufLen );
typedef APIRET (APIENTRY ImGetResultStringFunc)( HIMI himi, ULONG ulIndex, PVOID pBuf, PULONG pulBufLen );
typedef APIRET (APIENTRY ImSetCandidateWindowPosFunc)( HIMI himi, PCANDIDATEPOS pCandidatePos );
typedef APIRET (APIENTRY ImQueryIMEPropertyFunc)( HIMI himi, ULONG ulIndex, PULONG pulProp );
typedef APIRET (APIENTRY ImRequestIMEFunc)( HIMI himi, ULONG ulAction, ULONG ulIndex, ULONG ulValue );
typedef APIRET (APIENTRY ImSetIMModeFunc)( HIMI himi, ULONG ulInputMode, ULONG ulConversionMode );
typedef APIRET (APIENTRY ImQueryIMModeFunc)( HIMI himi, PULONG pulInputMode, PULONG pulConversionMode );

struct SalIMEData
{
    HMODULE                         mhModIME;
    ImAssociateInstanceFunc*        mpAssocIME;
    ImGetInstanceFunc*              mpGetIME;
    ImReleaseInstanceFunc*          mpReleaseIME;
    ImSetConversionFontFunc*        mpSetConversionFont;
    ImSetConversionFontSizeFunc*    mpSetConversionFontSize;
    ImGetConversionStringFunc*      mpGetConversionString;
    ImGetResultStringFunc*          mpGetResultString;
    ImSetCandidateWindowPosFunc*    mpSetCandidateWin;
    ImQueryIMEPropertyFunc*         mpQueryIMEProperty;
    ImRequestIMEFunc*               mpRequestIME;
    ImSetIMModeFunc*                mpSetIMEMode;
    ImQueryIMModeFunc*              mpQueryIMEMode;
};

#endif

#endif

// --------------------
// - Icon cache       -
// --------------------

struct SalIcon
{
    int     nId;
    HPOINTER hIcon;
    SalIcon *pNext;
};

// -----------
// - SalData -
// -----------

struct SalData
{
    HAB                     mhAB;                   // anchor block handle
    HMQ                     mhMQ;                   // handle of os2 message queue
    int                     mnArgc;                 // commandline param count
    char**                  mpArgv;                 // commandline
    ULONG                   mnNewTimerMS;           // Neue Zeit, mit dem der Timer gestartet werden soll
    ULONG                           mnTimerMS;                  // Current Time (in MS) of the Timer
    ULONG                           mnTimerOrgMS;               // Current Original Time (in MS)
    ULONG                   mnNextTimerTime;
    ULONG                   mnLastEventTime;
    ULONG                   mnTimerId;          // os2 timer id
    BOOL                    mbInTimerProc;          // timer event is currently being dispatched
    //SALTIMERPROC              mpTimerProc;            // timer callback proc
    HWND                    mhWantLeaveMsg;         // window handle, that want a MOUSELEAVE message
    AutoTimer*              mpMouseLeaveTimer;      // Timer for MouseLeave Test
    Os2SalInstance*             mpFirstInstance;        // pointer of first instance
    Os2SalFrame*                mpFirstFrame;           // pointer of first frame
    Os2SalFrame*                mpCreateFrame;          // Create-Frame for WM_CREATE
    Os2SalObject*               mpFirstObject;          // pointer of first object window
    ULONG                   mnAppThreadId;          // Id from Applikation-Thread
    ULONG                   mnFontMetricCount;      // number of entries in the font list
    PFONTMETRICS                mpFontMetrics;          // cached font list
    BOOL                    mbObjClassInit;         // Ist SALOBJECTCLASS initialised
#ifdef ENABLE_IME
    SalIMEData*                 mpIMEData;              // SalIME-Data
    BOOL                    mbIMEInit;              // SalIME-Data-Init
#endif

    SalIcon*                mpFirstIcon;            // icon cache, points to first icon, NULL if none

};

inline void SetSalData( SalData* pData ) { ImplGetSVData()->mpSalData = (void*)pData; }
inline SalData* GetSalData() { return (SalData*)ImplGetSVData()->mpSalData; }
inline SalData* GetAppSalData() { return (SalData*)ImplGetAppSVData()->mpSalData; }

// --------------
// - SalShlData -
// --------------

#define OS2_VER_211     211
#define OS2_VER_WARP3   230
#define OS2_VER_WARP4   240

struct SalShlData
{
    HMODULE                 mhMod;                  // Module handle of SAL-DLL
    USHORT                  mnVersion;              // 211 = OS2 2.11; 230 = OS2 3.0; 240 = OS2 4.0
    PFNWP                   mpOldFrameProc;         // old frame proc
};

extern SalShlData aSalShlData;

BOOL SalImplHandleProcessMenu( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );

// --------------------------------------------
// - SALSHL.CXX - for accessing DLL resources -
// --------------------------------------------

HPOINTER ImplLoadSalCursor( int nId );
HBITMAP ImplLoadSalBitmap( int nId );
BOOL ImplLoadSalIcon( int nId, HPOINTER& rIcon);

// SALGDI.CXX
void ImplInitSalGDI();
void ImplFreeSalGDI();

// --------------
// - Prototypes -
// --------------

// \\OS2\SOURCE\APP\SALINST.CXX
void ImplSalYieldMutexAcquireWithWait();
ULONG ImplSalReleaseYieldMutex();
void ImplSalAcquireYieldMutex( ULONG nCount );
ULONG GetCurrentThreadId();
BOOL ImplSalYieldMutexTryToAcquire();
void ImplSalYieldMutexAcquire();
void ImplSalYieldMutexRelease();

// \\OS2\SOURCE\WINDOW\SALFRAME.CXX
MRESULT EXPENTRY SalFrameWndProc( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );
MRESULT EXPENTRY SalFrameFrameProc( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );
// \SV\WIN\SOURCE\APP\SALTIMER.CXX
#define SALTIMERPROC_RECURSIVE 0xffffffff
void SalTimerProc( HWND hWnd, UINT nMsg, UINT nId, ULONG nTime );

// \WIN\SOURCE\WINDOW\SALFRAME.CXX
void SalTestMouseLeave();

// \\OS2\SOURCE\WINDOW\SALFRAME.CXX
// return Frame for Message-Handling
Os2SalFrame* GetSalDefaultFrame();

// \\OS2\SOURCE\WINDOW\SALFRAME.CXX
// IME-Daten wieder freigeben
#ifdef ENABLE_IME
void ImplReleaseSALIMEData();
#endif

// -----------
// - Defines -
// -----------

#define SAL_PROFILE_APPNAME         ((PSZ)"StarOffice")
#define SAL_PROFILE_USEDJP          ((PSZ)"UseDJP")
#define SAL_PROFILE_PRINTDJP        ((PSZ)"PrintDJP")
#define SAL_PROFILE_PRINTRAW        ((PSZ)"PrintRAW")

#define SAL_FRAME_WNDEXTRA          sizeof(ULONG)
#define SAL_FRAME_THIS              0
#define SAL_FRAME_CLASSNAME         "SALFRAME"
#define SAL_SUBFRAME_CLASSNAME      "SALSUBFRAME"
#define SAL_OBJECT_WNDEXTRA         sizeof(ULONG)
#define SAL_OBJECT_THIS             0
#define SAL_OBJECT_CLASSNAME        "SALOBJECT"
#define SAL_OBJECT_CHILDCLASSNAME   "SALOBJECTCHILD"
#define SAL_OBJECT_CLIPCLASSNAME    "SALOBJECTCLIP"
#define SAL_COM_CLASSNAME           "SALCOMWND"

#define SAL_MOUSELEAVE_TIMEOUT      300

// MP1 == 0; MP2 == pData
#define SAL_MSG_USEREVENT           (WM_USER+111)
// MP1 == 0; MP2 == MousePosition relativ to upper left of screen
#define SAL_MSG_MOUSELEAVE          (WM_USER+112)
// MP1 == hDC; MP2 == 0
#define SAL_MSG_PRINTABORTJOB       (WM_USER+113)
// MP1 == 0; MP2 == 0
#define SAL_MSG_STARTTIMER          (WM_USER+114)
// MP1 == nFrameStyle; MP2 == pParent; lResult pFrame
#define SAL_MSG_CREATEFRAME         (WM_USER+115)
// MP1 == 0; MP2 == pParent; lResult pObject
#define SAL_MSG_CREATEOBJECT        (WM_USER+116)
// MP1 == bWait; MP2 == pMutex
#define SAL_MSG_THREADYIELD         (WM_USER+117)
// MP1 == 0; MP2 == 0
#define SAL_MSG_RELEASEWAITYIELD    (WM_USER+118)
// MP1 == 0; MP2 == pData
#define SAL_MSG_SYSPROCESSMENU      (WM_USER+119)
// POSTFOCUS-Message; MP1 == nMP1; MP2 == nMP2 (SHORT1( bFocus ), 0)
#define SAL_MSG_POSTFOCUS           (WM_USER+120)
// POSTSIZE-Message; MP1 == nMP1; MP2 == nMP2
#define SAL_MSG_POSTSIZE            (WM_USER+121)

// wParam == wParam; lParam == lParam
#define SAL_MSG_POSTMOVE            (WM_USER+136)
// wParam == pRECT; lParam == 0
#define SAL_MSG_POSTPAINT           (WM_USER+137)
// wParam == nFlags; lParam == 0
#define SAL_MSG_TOTOP               (WM_USER+142)
// wParam == bVisible; lParam == 0
#define SAL_MSG_SHOW                (WM_USER+143)

// SysChild-ToTop; nMP1 = 0; nMP2 = 0
#define SALOBJ_MSG_TOTOP            (WM_USER+150)
// POSTFOCUS-Message; MP1 == nMP1; MP2 == nMP2 (SHORT1( bFocus ), 0)
#define SALOBJ_MSG_POSTFOCUS        (WM_USER+151)

// wParam == 0; lParam == 0
#define SAL_MSG_DESTROYFRAME        (WM_USER+160)
// wParam == 0; lParam == pObject;
#define SAL_MSG_DESTROYOBJECT       (WM_USER+161)
// wParam == 0; lParam == this; lResult == bRet
#define SAL_MSG_CREATESOUND         (WM_USER+162)
// wParam == 0; lParam == this
#define SAL_MSG_DESTROYSOUND        (WM_USER+163)
// wParam == hWnd; lParam == 0; lResult == hDC
#define SAL_MSG_GETDC               (WM_USER+164)
// wParam == hWnd; lParam == 0
#define SAL_MSG_RELEASEDC           (WM_USER+165)
// wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
#define SAL_MSG_RECREATEHWND         (WM_USER+166)
// wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
#define SAL_MSG_RECREATECHILDHWND    (WM_USER+167)
// wParam == 0; lParam == HWND;
#define SAL_MSG_DESTROYHWND         (WM_USER+168)
// POSTTIMER-Message; wparam = 0, lParam == time
#define SAL_MSG_POSTTIMER           (WM_USER+169)

// -----------------
// - Helpfunctions -
// -----------------

inline void SetWindowPtr( HWND hWnd, SalFrame* pThis )
{
    WinSetWindowULong( hWnd, SAL_FRAME_THIS, (ULONG)pThis );
}

inline Os2SalFrame* GetWindowPtr( HWND hWnd )
{
    return (Os2SalFrame*)WinQueryWindowULong( hWnd, SAL_FRAME_THIS );
}

inline void SetSalObjWindowPtr( HWND hWnd, SalObject* pThis )
{
    WinSetWindowULong( hWnd, SAL_OBJECT_THIS, (ULONG)pThis );
}

inline Os2SalObject* GetSalObjWindowPtr( HWND hWnd )
{
    return (Os2SalObject*)WinQueryWindowULong( hWnd, SAL_OBJECT_THIS );
}

#endif  // _SV_SALDATA_HXX
<commit_msg>INTEGRATION: CWS os2port03 (1.5.116); FILE MERGED 2008/07/16 13:38:45 obr 1.5.116.2: RESYNC: (1.5-1.6); FILE MERGED 2008/01/29 15:21:51 ydario 1.5.116.1: os2 compile fixes. Issue number:i85203 Submitted by:ydario<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: saldata.hxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _SV_SALDATA_HXX
#define _SV_SALDATA_HXX

#include <vcl/sv.h>
#include <vcl/svdata.hxx>
#include <vcl/salwtype.hxx>

class Os2SalInstance;
class Os2SalFrame;
class Os2SalObject;

extern "C" int debug_printf(const char *f, ...);

// --------------
// - SalIMEData -
// --------------

// YD FIXME #define ENABLE_IME

#ifdef ENABLE_IME

struct SalIMEData;

#ifdef OS2IM_INCLUDED

typedef APIRET (APIENTRY ImAssociateInstanceFunc)( HWND hwnd, HIMI himi, PHIMI phimiPrev );
typedef APIRET (APIENTRY ImGetInstanceFunc)( HWND hwnd, PHIMI phimi );
typedef APIRET (APIENTRY ImReleaseInstanceFunc)( HWND hwnd, HIMI himi );
typedef APIRET (APIENTRY ImSetConversionFontFunc)( HIMI himi, PFATTRS pFontAttrs );
typedef APIRET (APIENTRY ImSetConversionFontSizeFunc)( HIMI himi, PSIZEF psizfxBox );
typedef APIRET (APIENTRY ImGetConversionStringFunc)( HIMI himi, ULONG ulIndex, PVOID pBuf, PULONG pulBufLen );
typedef APIRET (APIENTRY ImGetResultStringFunc)( HIMI himi, ULONG ulIndex, PVOID pBuf, PULONG pulBufLen );
typedef APIRET (APIENTRY ImSetCandidateWindowPosFunc)( HIMI himi, PCANDIDATEPOS pCandidatePos );
typedef APIRET (APIENTRY ImQueryIMEPropertyFunc)( HIMI himi, ULONG ulIndex, PULONG pulProp );
typedef APIRET (APIENTRY ImRequestIMEFunc)( HIMI himi, ULONG ulAction, ULONG ulIndex, ULONG ulValue );
typedef APIRET (APIENTRY ImSetIMModeFunc)( HIMI himi, ULONG ulInputMode, ULONG ulConversionMode );
typedef APIRET (APIENTRY ImQueryIMModeFunc)( HIMI himi, PULONG pulInputMode, PULONG pulConversionMode );

struct SalIMEData
{
    HMODULE                         mhModIME;
    ImAssociateInstanceFunc*        mpAssocIME;
    ImGetInstanceFunc*              mpGetIME;
    ImReleaseInstanceFunc*          mpReleaseIME;
    ImSetConversionFontFunc*        mpSetConversionFont;
    ImSetConversionFontSizeFunc*    mpSetConversionFontSize;
    ImGetConversionStringFunc*      mpGetConversionString;
    ImGetResultStringFunc*          mpGetResultString;
    ImSetCandidateWindowPosFunc*    mpSetCandidateWin;
    ImQueryIMEPropertyFunc*         mpQueryIMEProperty;
    ImRequestIMEFunc*               mpRequestIME;
    ImSetIMModeFunc*                mpSetIMEMode;
    ImQueryIMModeFunc*              mpQueryIMEMode;
};

#endif

#endif

// --------------------
// - Icon cache       -
// --------------------

struct SalIcon
{
    int     nId;
    HPOINTER hIcon;
    SalIcon *pNext;
};

// -----------
// - SalData -
// -----------

struct SalData
{
    HAB                     mhAB;                   // anchor block handle
    HMQ                     mhMQ;                   // handle of os2 message queue
    int                     mnArgc;                 // commandline param count
    char**                  mpArgv;                 // commandline
    ULONG                   mnNewTimerMS;           // Neue Zeit, mit dem der Timer gestartet werden soll
    ULONG                           mnTimerMS;                  // Current Time (in MS) of the Timer
    ULONG                           mnTimerOrgMS;               // Current Original Time (in MS)
    ULONG                   mnNextTimerTime;
    ULONG                   mnLastEventTime;
    ULONG                   mnTimerId;          // os2 timer id
    BOOL                    mbInTimerProc;          // timer event is currently being dispatched
    //SALTIMERPROC              mpTimerProc;            // timer callback proc
    HWND                    mhWantLeaveMsg;         // window handle, that want a MOUSELEAVE message
    AutoTimer*              mpMouseLeaveTimer;      // Timer for MouseLeave Test
    Os2SalInstance*             mpFirstInstance;        // pointer of first instance
    Os2SalFrame*                mpFirstFrame;           // pointer of first frame
    Os2SalFrame*                mpCreateFrame;          // Create-Frame for WM_CREATE
    Os2SalObject*               mpFirstObject;          // pointer of first object window
    ULONG                   mnAppThreadId;          // Id from Applikation-Thread
    ULONG                   mnFontMetricCount;      // number of entries in the font list
    PFONTMETRICS                mpFontMetrics;          // cached font list
    BOOL                    mbObjClassInit;         // Ist SALOBJECTCLASS initialised
#ifdef ENABLE_IME
    SalIMEData*                 mpIMEData;              // SalIME-Data
    BOOL                    mbIMEInit;              // SalIME-Data-Init
#endif

    SalIcon*                mpFirstIcon;            // icon cache, points to first icon, NULL if none

};

inline void SetSalData( SalData* pData ) { ImplGetSVData()->mpSalData = (void*)pData; }
inline SalData* GetSalData() { return (SalData*)ImplGetSVData()->mpSalData; }
inline SalData* GetAppSalData() { return (SalData*)ImplGetAppSVData()->mpSalData; }

// --------------
// - SalShlData -
// --------------

#define OS2_VER_211     211
#define OS2_VER_WARP3   230
#define OS2_VER_WARP4   240

struct SalShlData
{
    HMODULE mhMod;      // Module handle of SAL-DLL
    USHORT  mnVersion;  // 211 = OS2 2.11; 230 = OS2 3.0; 240 = OS2 4.0
    PFNWP   mpFrameProc;    // old frame proc
};

extern SalShlData aSalShlData;

BOOL SalImplHandleProcessMenu( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );

// --------------------------------------------
// - SALSHL.CXX - for accessing DLL resources -
// --------------------------------------------

HPOINTER ImplLoadSalCursor( int nId );
HBITMAP ImplLoadSalBitmap( int nId );
BOOL ImplLoadSalIcon( int nId, HPOINTER& rIcon);

// SALGDI.CXX
void ImplInitSalGDI();
void ImplFreeSalGDI();

// --------------
// - Prototypes -
// --------------

// \\OS2\SOURCE\APP\SALINST.CXX
void ImplSalYieldMutexAcquireWithWait();
ULONG ImplSalReleaseYieldMutex();
void ImplSalAcquireYieldMutex( ULONG nCount );
ULONG GetCurrentThreadId();
BOOL ImplSalYieldMutexTryToAcquire();
void ImplSalYieldMutexAcquire();
void ImplSalYieldMutexRelease();

// \\OS2\SOURCE\WINDOW\SALFRAME.CXX
MRESULT EXPENTRY SalFrameWndProc( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );
MRESULT EXPENTRY SalFrameFrameProc( HWND hWnd, ULONG nMsg, MPARAM nMP1, MPARAM nMP2 );
// \SV\WIN\SOURCE\APP\SALTIMER.CXX
#define SALTIMERPROC_RECURSIVE 0xffffffff
void SalTimerProc( HWND hWnd, UINT nMsg, UINT nId, ULONG nTime );

// \WIN\SOURCE\WINDOW\SALFRAME.CXX
void SalTestMouseLeave();

// \\OS2\SOURCE\WINDOW\SALFRAME.CXX
// return Frame for Message-Handling
Os2SalFrame* GetSalDefaultFrame();

// \\OS2\SOURCE\WINDOW\SALFRAME.CXX
// IME-Daten wieder freigeben
#ifdef ENABLE_IME
void ImplReleaseSALIMEData();
#endif

// -----------
// - Defines -
// -----------

#define SAL_PROFILE_APPNAME         ((PSZ)"StarOffice")
#define SAL_PROFILE_USEDJP          ((PSZ)"UseDJP")
#define SAL_PROFILE_PRINTDJP        ((PSZ)"PrintDJP")
#define SAL_PROFILE_PRINTRAW        ((PSZ)"PrintRAW")

#define SAL_FRAME_WNDEXTRA          sizeof(ULONG)
#define SAL_FRAME_THIS              0
#define SAL_FRAME_CLASSNAME         "SALFRAME"
#define SAL_SUBFRAME_CLASSNAME      "SALSUBFRAME"
#define SAL_OBJECT_WNDEXTRA         sizeof(ULONG)
#define SAL_OBJECT_THIS             0
#define SAL_OBJECT_CLASSNAME        "SALOBJECT"
#define SAL_OBJECT_CHILDCLASSNAME   "SALOBJECTCHILD"
#define SAL_OBJECT_CLIPCLASSNAME    "SALOBJECTCLIP"
#define SAL_COM_CLASSNAME           "SALCOMWND"

#define SAL_MOUSELEAVE_TIMEOUT      300

// MP1 == 0; MP2 == pData
#define SAL_MSG_USEREVENT           (WM_USER+111)
// MP1 == 0; MP2 == MousePosition relativ to upper left of screen
#define SAL_MSG_MOUSELEAVE          (WM_USER+112)
// MP1 == hDC; MP2 == 0
#define SAL_MSG_PRINTABORTJOB       (WM_USER+113)
// MP1 == 0; MP2 == 0
#define SAL_MSG_STARTTIMER          (WM_USER+114)
// MP1 == nFrameStyle; MP2 == pParent; lResult pFrame
#define SAL_MSG_CREATEFRAME         (WM_USER+115)
// MP1 == 0; MP2 == pParent; lResult pObject
#define SAL_MSG_CREATEOBJECT        (WM_USER+116)
// MP1 == bWait; MP2 == pMutex
#define SAL_MSG_THREADYIELD         (WM_USER+117)
// MP1 == 0; MP2 == 0
#define SAL_MSG_RELEASEWAITYIELD    (WM_USER+118)
// MP1 == 0; MP2 == pData
#define SAL_MSG_SYSPROCESSMENU      (WM_USER+119)
// POSTFOCUS-Message; MP1 == nMP1; MP2 == nMP2 (SHORT1( bFocus ), 0)
#define SAL_MSG_POSTFOCUS           (WM_USER+120)
// POSTSIZE-Message; MP1 == nMP1; MP2 == nMP2
#define SAL_MSG_POSTSIZE            (WM_USER+121)

// wParam == wParam; lParam == lParam
#define SAL_MSG_POSTMOVE            (WM_USER+136)
// wParam == pRECT; lParam == 0
#define SAL_MSG_POSTPAINT           (WM_USER+137)
// wParam == nFlags; lParam == 0
#define SAL_MSG_TOTOP               (WM_USER+142)
// wParam == bVisible; lParam == 0
#define SAL_MSG_SHOW                (WM_USER+143)

// SysChild-ToTop; nMP1 = 0; nMP2 = 0
#define SALOBJ_MSG_TOTOP            (WM_USER+150)
// POSTFOCUS-Message; MP1 == nMP1; MP2 == nMP2 (SHORT1( bFocus ), 0)
#define SALOBJ_MSG_POSTFOCUS        (WM_USER+151)

// wParam == 0; lParam == 0
#define SAL_MSG_DESTROYFRAME        (WM_USER+160)
// wParam == 0; lParam == pObject;
#define SAL_MSG_DESTROYOBJECT       (WM_USER+161)
// wParam == 0; lParam == this; lResult == bRet
#define SAL_MSG_CREATESOUND         (WM_USER+162)
// wParam == 0; lParam == this
#define SAL_MSG_DESTROYSOUND        (WM_USER+163)
// wParam == hWnd; lParam == 0; lResult == hDC
#define SAL_MSG_GETDC               (WM_USER+164)
// wParam == hWnd; lParam == 0
#define SAL_MSG_RELEASEDC           (WM_USER+165)
// wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
#define SAL_MSG_RECREATEHWND         (WM_USER+166)
// wParam == newParentHwnd; lParam == oldHwnd; lResult == newhWnd
#define SAL_MSG_RECREATECHILDHWND    (WM_USER+167)
// wParam == 0; lParam == HWND;
#define SAL_MSG_DESTROYHWND         (WM_USER+168)
// POSTTIMER-Message; wparam = 0, lParam == time
#define SAL_MSG_POSTTIMER           (WM_USER+169)

// -----------------
// - Helpfunctions -
// -----------------

inline void SetWindowPtr( HWND hWnd, SalFrame* pThis )
{
    WinSetWindowULong( hWnd, SAL_FRAME_THIS, (ULONG)pThis );
}

inline Os2SalFrame* GetWindowPtr( HWND hWnd )
{
    return (Os2SalFrame*)WinQueryWindowULong( hWnd, SAL_FRAME_THIS );
}

inline void SetSalObjWindowPtr( HWND hWnd, SalObject* pThis )
{
    WinSetWindowULong( hWnd, SAL_OBJECT_THIS, (ULONG)pThis );
}

inline Os2SalObject* GetSalObjWindowPtr( HWND hWnd )
{
    return (Os2SalObject*)WinQueryWindowULong( hWnd, SAL_OBJECT_THIS );
}

#endif  // _SV_SALDATA_HXX
<|endoftext|>