Beispiel #1
0
LoadedDeviceAdapter::LoadedDeviceAdapter(const std::string& name, const std::string& filename) :
   name_(name),
   InitializeModuleData_(0),
   CreateDevice_(0),
   DeleteDevice_(0),
   GetModuleVersion_(0),
   GetDeviceInterfaceVersion_(0),
   GetNumberOfDevices_(0),
   GetDeviceName_(0),
   GetDeviceType_(0),
   GetDeviceDescription_(0)
{
   try
   {
      module_ = boost::make_shared<LoadedModule>(filename);
   }
   catch (const CMMError& e)
   {
      module_.reset();
      throw CMMError("Failed to load device adapter " + ToQuotedString(name_), e);
   }

   try
   {
      CheckInterfaceVersion();
   }
   catch (const CMMError& e)
   {
      module_.reset();
      throw CMMError("Failed to load device adapter " + ToQuotedString(name_) +
            " from " + ToQuotedString(filename), e);
   }

   InitializeModuleData();
}
Beispiel #2
0
short
IsolatedScalarUDF::generateShape(CollHeap * c, char * buf,
                           NAString * shapeStr)
{
  Space *space = (Space *)c;
  char mybuf[100];

  sprintf (mybuf, "isolated_scalar_udf");
  outputBuffer (space, buf, mybuf, shapeStr);

  if (getRoutineDesc() &&
      getRoutineDesc()->getNARoutine() &&
      getRoutineDesc()->getNARoutine()->getRoutineName())
  {
    NAString fmtdStr;
    ToQuotedString(fmtdStr, getRoutineDesc()->getNARoutine()->
                             getRoutineName()->getQualifiedNameObj().
                             getQualifiedNameAsAnsiString().data());
    snprintf (mybuf, 100, "(scalar_udf %s", fmtdStr.data());
    outputBuffer (space, buf, mybuf, shapeStr);
    if (getRoutineDesc()->isUUDFRoutine() &&
        getRoutineDesc()->getActionNARoutine() &&
        getRoutineDesc()->getActionNARoutine()->getActionName())
    {
      ToQuotedString(fmtdStr, getRoutineDesc()->getActionNARoutine()->
                               getActionName()->data());
      snprintf (mybuf, 100, ", udf_action %s", fmtdStr.data());
      outputBuffer (space, buf, mybuf, shapeStr);
    }
    strcpy(mybuf, ")");
    outputBuffer (space, buf, mybuf, shapeStr);
  }
  return 0;
}
Beispiel #3
0
MM::DeviceType
LoadedDeviceAdapter::GetAdvertisedDeviceType(const std::string& deviceName) const
{
   int typeInt = MM::UnknownType;
   bool ok = GetDeviceType(deviceName.c_str(), &typeInt);
   if (!ok || typeInt == MM::UnknownType)
   {
      throw CMMError("Cannot get type of device " +
            ToQuotedString(deviceName) + " of device adapter module " +
            ToQuotedString(name_));
   }
   return static_cast<MM::DeviceType>(typeInt);
}
Beispiel #4
0
std::string
LoadedDeviceAdapter::GetDeviceDescription(const std::string& deviceName) const
{
   ModuleStringBuffer descBuf(this, "GetDeviceDescription");
   bool ok = GetDeviceDescription(deviceName.c_str(), descBuf.GetBuffer(),
         descBuf.GetMaxStrLen());
   if (!ok)
   {
      throw CMMError("Cannot get description for device " +
            ToQuotedString(deviceName) + " of device adapter module " +
            ToQuotedString(name_));
   }
   return descBuf.Get();
}
std::string
DeviceInstance::GetPropertyValueAt(const std::string& propertyName, unsigned index) const
{
   DeviceStringBuffer valueBuf(this, "GetPropertyValueAt");
   bool ok = pImpl_->GetPropertyValueAt(propertyName.c_str(), index,
         valueBuf.GetBuffer());
   if (!ok)
   {
      throw CMMError("Device " + ToQuotedString(GetLabel()) +
            ": cannot get allowed value at index " +
            boost::lexical_cast<std::string>(index) + " of property " +
            ToQuotedString(propertyName));
   }
   return valueBuf.Get();
}
void
DeviceInstance::SetProperty(const std::string& name,
      const std::string& value) const
{
   LOG_DEBUG(Logger()) << "Will set property \"" << name << "\" to \"" <<
      value << "\"";

   int err = pImpl_->SetProperty(name.c_str(), value.c_str());

   ThrowIfError(err, "Cannot set property " + ToQuotedString(name) +
         " to " + ToQuotedString(value));

   LOG_DEBUG(Logger()) << "Did set property \"" << name << "\" to \"" <<
      value << "\"";
}
Beispiel #7
0
void
LoadedDeviceAdapter::ModuleStringBuffer::ThrowBufferOverflowError() const
{
   std::string name(module_ ? module_->GetName() : "<unknown>");
   throw CMMError("Buffer overflow in device adapter module " +
         ToQuotedString(name) + " while calling " + funcName_ + "(); "
         "this is most likely a bug in the device adapter");
}
void
DeviceInstance::DeviceStringBuffer::ThrowBufferOverflowError() const
{
   std::string label(instance_ ? instance_->GetLabel() : "<unknown>");
   throw CMMError("Buffer overflow in device " + ToQuotedString(label) +
         " while calling " + funcName_ + "(); "
         "this is most likely a bug in the device adapter");
}
Beispiel #9
0
MM::Device* HubInstance::GetInstalledDevice(int devIdx)
{
   MM::Device* peripheral = GetImpl()->GetInstalledDevice(devIdx);
   if (!peripheral)
      throw CMMError("Hub " + ToQuotedString(GetLabel()) +
            " returned a null peripheral at index " + ToString(devIdx));
   return peripheral;
}
std::string
DeviceInstance::GetProperty(const std::string& name) const
{
   DeviceStringBuffer valueBuf(this, "GetProperty");
   int err = pImpl_->GetProperty(name.c_str(), valueBuf.GetBuffer());
   ThrowIfError(err, "Cannot get value of property " +
         ToQuotedString(name));
   return valueBuf.Get();
}
Beispiel #11
0
std::string
HubInstance::GetInstalledPeripheralDescription(const std::string& peripheralName)
{
   std::vector<MM::Device*> peripherals = GetInstalledPeripherals();
   for (std::vector<MM::Device*>::iterator it = peripherals.begin(), end = peripherals.end();
         it != end; ++it)
   {
      DeviceStringBuffer nameBuf(0, "GetName");
      (*it)->GetName(nameBuf.GetBuffer());
      if (nameBuf.Get() == peripheralName)
      {
         DeviceStringBuffer descBuf(0, "GetDescription");
         (*it)->GetDescription(descBuf.GetBuffer());
         return descBuf.Get();
      }
   }

   throw CMMError("No peripheral with name " + ToQuotedString(peripheralName) +
         " installed in hub " + ToQuotedString(GetLabel()));
}
Beispiel #12
0
boost::shared_ptr<DeviceInstance>
DeviceManager::GetDevice(const std::string& label) const
{
   DeviceConstIterator found =
      std::find_if(devices_.begin(), devices_.end(),
            DevicePairMatcheslabel(label));
   if (found == devices_.end())
   {
      throw CMMError("No device with label " + ToQuotedString(label));
   }
   return found->second;
}
Beispiel #13
0
std::vector<std::string>
LoadedDeviceAdapter::GetAvailableDeviceNames() const
{
   unsigned deviceCount = GetNumberOfDevices();
   std::vector<std::string> deviceNames;
   deviceNames.reserve(deviceCount);
   for (unsigned i = 0; i < deviceCount; ++i)
   {
      ModuleStringBuffer nameBuf(this, "GetDeviceName");
      bool ok = GetDeviceName(i, nameBuf.GetBuffer(), nameBuf.GetMaxStrLen());
      if (!ok)
      {
         throw CMMError("Cannot get device name at index " + ToString(i) +
               " from device adapter module " + ToQuotedString(name_));
      }
      deviceNames.push_back(nameBuf.Get());
   }
   return deviceNames;
}
Beispiel #14
0
boost::shared_ptr<DeviceInstance>
DeviceManager::LoadDevice(boost::shared_ptr<LoadedDeviceAdapter> module,
      const std::string& deviceName, const std::string& label, CMMCore* core,
      mm::logging::Logger deviceLogger,
      mm::logging::Logger coreLogger)
{
   for (DeviceConstIterator it = devices_.begin(), end = devices_.end(); it != end; ++it)
   {
      if (it->first == label)
      {
         throw CMMError("The specified device label " + ToQuotedString(label) +
               " is already in use", MMERR_DuplicateLabel);
      }
   }

   boost::shared_ptr<DeviceInstance> device = module->LoadDevice(core,
         deviceName, label, deviceLogger, coreLogger);

   std::string description;
   bool moduleHasDescription = false;
   try
   {
      description = module->GetDeviceDescription(deviceName);
      moduleHasDescription = true;
   }
   catch (const CMMError&)
   {
      // Module did not have a description for this device.
   }
   if (moduleHasDescription && !description.empty())
   {
      // If a description could be obtained from the module, set the device's
      // description (which will be used so long as the device does not
      // override GetDescription().
      device->SetDescription(description);
   }

   devices_.push_back(std::make_pair(label, device));
   deviceRawPtrIndex_.insert(std::make_pair(device->GetRawPtr(), device));
   return device;
}
Beispiel #15
0
void FastLogger::VLogF(bool isDebug, const char* format, va_list ap)
{
   // Keep a copy of the argument list
   va_list apCopy;
#ifdef _MSC_VER
   apCopy = ap;
#else
   va_copy(apCopy, ap);
#endif

   // We avoid dynamic allocation in the vast majority of cases.
   const size_t smallBufSize = 1024;
   char smallBuf[smallBufSize];
   int n = vsnprintf(smallBuf, smallBufSize, format, ap);
   if (n >= 0 && n < smallBufSize)
   {
      Log(isDebug, smallBuf);
      return;
   }

   // Okay, now we deal with some nastiness due to the non-standard
   // implementation of Microsoft's vsnprintf() (vsnprintf_s() is no better).

#ifdef _MSC_VER
   // With Microsoft's C Runtime, n is always -1 (whether error or overflow).
   // Try a fixed-size buffer and give up if it is not large enough.
   const size_t bigBufSize = 65536;
#else
   // With C99/C++11 compliant vsnprintf(), n is -1 if error but on overflow it
   // is the required string length.
   if (n < 0)
   {
      Log(isDebug, ("Error in vsnprintf() while formatting log entry with "
               "format string " + ToQuotedString(format)).c_str());
      return;
   }
   size_t bigBufSize = n + 1;
#endif

   boost::scoped_array<char> bigBuf(new char[bigBufSize]);
   if (!bigBuf)
   {
      Log(isDebug, ("Error: could not allocate " + ToString(bigBufSize/1024) +
               " kilobytes to format log entry with format string " +
               ToQuotedString(format)).c_str());
      return;
   }

   n = vsnprintf(bigBuf.get(), bigBufSize, format, apCopy);
   if (n >= 0 && n < bigBufSize)
   {
      Log(isDebug, bigBuf.get());
      return;
   }

#ifdef _MSC_VER
   Log(isDebug, ("Error or overflow in vsnprintf() (buffer size " +
            ToString(bigBufSize / 1024) + " kilobytes) while formatting "
            "log entry with format string " + ToQuotedString(format)).c_str());
#else
   Log(isDebug, ("Error in vsnprintf() while formatting log entry with "
            "format string " + ToQuotedString(format)).c_str());
#endif
}
Beispiel #16
0
short FileScan::generateShape(CollHeap * c, char * buf, NAString * shapeStr)
{
  Space * space = (Space *)c;
  char mybuf[1000];
  NAString fmtdStr1, fmtdStr2;

  if (getIndexDesc()->getNAFileSet()->getKeytag() == 0)
  {
     if (getTableName().getCorrNameAsString() == "")
     {
        ToQuotedString(fmtdStr1, 
                       getIndexDesc()->getNAFileSet()->
                        getExtFileSetName().data());
        snprintf(mybuf, 1000, "scan(path %s, ", fmtdStr1.data());
     }
     else
     {
        ToQuotedString(fmtdStr1,getTableName().getCorrNameAsString().data());
        ToQuotedString(fmtdStr2,getIndexDesc()->getNAFileSet()->
                                 getExtFileSetName().data());
        snprintf(mybuf, 1000, "scan(TABLE %s, path %s, ",
                  fmtdStr1.data(), fmtdStr2.data());
     }
  }
  else
  {
    if (getTableName().getCorrNameAsString() != "")
    {
      ToQuotedString(fmtdStr1,getTableName().getCorrNameAsString().data());
      ToQuotedString(fmtdStr2,getIndexDesc()->getNAFileSet()->
                               getExtFileSetName().data());
      snprintf(mybuf, 1000, "scan(TABLE %s, path %s, ",
                  fmtdStr1.data(), fmtdStr2.data());
    }
    else
    {
      ToQuotedString(fmtdStr1,getIndexDesc()->getNAFileSet()->
                               getExtFileSetName().data());
      snprintf(mybuf, 1000, "scan(path %s, ", fmtdStr1.data());
    }

  }

  outputBuffer(space, buf, mybuf, shapeStr);

  if (getReverseScan())
    strcpy(mybuf, "reverse");
  else
    strcpy(mybuf, "forward");

  outputBuffer(space, buf, mybuf, shapeStr);

  if (getNumberOfBlocksToReadPerAccess() > -1)
    {
      sprintf(mybuf, ", blocks_per_access %d ",
	      getNumberOfBlocksToReadPerAccess());
      outputBuffer(space, buf, mybuf, shapeStr);
    }

  if (getMdamKeyPtr() == NULL)
    strcpy(mybuf, ", mdam off)");
  else
    {
      // compute MAX stop column
      CollIndex maxStopColumn=0;
      CollIndex j = 0;
      for (j=0; j < getMdamKeyPtr()->getKeyDisjunctEntries(); j++)
        {
          if (getMdamKeyPtr()->getStopColumn(j) > maxStopColumn)
            {
              maxStopColumn = getMdamKeyPtr()->getStopColumn(j);
            }
        }

      if (maxStopColumn == getIndexDesc()->getIndexKey().entries()-1)
        {
          strcpy(mybuf, ", mdam forced, mdam_columns all(");
        }
        else
        {
          strcpy(mybuf, ", mdam forced, mdam_columns (");
        }

      outputBuffer(space, buf, mybuf, shapeStr);

      UInt32 maxCol = MINOF((maxStopColumn+1), getIndexDesc()->getIndexKey().entries());
      for (UInt32 i = 0; i < maxCol; i++)
	{
	  if (i > 0)
	    strcpy(mybuf, ", ");
	  else
	    mybuf[0] = 0;

	  if (getMdamKeyPtr()->isColumnSparse(i))
	    strcat(mybuf, "sparse");
	  else
	    strcat(mybuf, "dense");
	  outputBuffer(space, buf, mybuf, shapeStr);
	}
      strcpy(mybuf, "))");
    }

  outputBuffer(space, buf, mybuf, shapeStr);

  return 0;
}
// *****************************************************************************
// *                                                                           *
// * Function: CmpSeabaseDDL::addSchemaObject                                  *
// *                                                                           *
// *    Inserts a schema object row into the OBJECTS table.                    *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <cliInterface>                  ExeCliInterface &               In       *
// *    is a reference to an Executor CLI interface handle.                    *
// *                                                                           *
// *  <schemaName>                    const ComSchemaName &           In       *
// *    is a reference to a ComSchemaName instance.  The catalog name must be  *
// *  set.                                                                     *
// *                                                                           *
// *  <schemaClass>                   ComSchemaClass                  In       *
// *    is the class (private or shared) of the schema to be added.            *
// *                                                                           *
// *  <ownerID>                       Int32                           In       *
// *    is the authorization ID that will own the schema.                      *
// *                                                                           *
// *  <ignoreIfExists>                NABoolean                       In       *
// *    do not return an error is schema already exists                        *
// *****************************************************************************
// *                                                                           *
// * Returns: PrivStatus                                                       *
// *                                                                           *
// *   0: Schema as added                                                      *
// *  -1: Schema was not added.  A CLI error is put into the diags area.       *
// *                                                                           *
// *****************************************************************************
int CmpSeabaseDDL::addSchemaObject(
   ExeCliInterface & cliInterface,
   const ComSchemaName & schemaName,
   ComSchemaClass schemaClass,
   Int32 ownerID,
   NABoolean ignoreIfExists)
   
{

NAString catalogName = schemaName.getCatalogNamePartAsAnsiString();
ComAnsiNamePart schemaNameAsComAnsi = schemaName.getSchemaNamePart();
NAString schemaNamePart = schemaNameAsComAnsi.getInternalName();

ComObjectName objName(catalogName,schemaNamePart,NAString(SEABASE_SCHEMA_OBJECTNAME), 
                      COM_TABLE_NAME,TRUE);
                      
   if (isSeabaseReservedSchema(objName) &&
       !Get_SqlParser_Flags(INTERNAL_QUERY_FROM_EXEUTIL))
   {
      *CmpCommon::diags() << DgSqlCode(-CAT_RESERVED_METADATA_SCHEMA_NAME)
                          << DgSchemaName(schemaName.getExternalName().data());
      return -1;
   }
                      
NAString objectNamePart = objName.getObjectNamePartAsAnsiString(TRUE);

Lng32 retcode = existsInSeabaseMDTable(&cliInterface,catalogName,schemaNamePart, 
                                       objectNamePart, COM_UNKNOWN_OBJECT, FALSE);
   if (retcode < 0)
      return -1;
  
   if (retcode == 1 ) // already exists
   {
      if (ignoreIfExists)
        return 0;
      else
        *CmpCommon::diags() << DgSqlCode(-CAT_SCHEMA_ALREADY_EXISTS)
                            << DgSchemaName(schemaName.getExternalName().data());
      return -1;
   }

char buf[4000];

ComUID schemaUID;

   schemaUID.make_UID();
   
Int64 schemaObjectUID = schemaUID.get_value();
  
Int64 createTime = NA_JulianTimestamp();

NAString quotedSchName;
NAString quotedObjName;

   ToQuotedString(quotedSchName,schemaNamePart,FALSE);
   ToQuotedString(quotedObjName,NAString(SEABASE_SCHEMA_OBJECTNAME),FALSE);

char schemaObjectLit[3] = {0};
   
   switch (schemaClass)
   {
      case COM_SCHEMA_CLASS_PRIVATE:
      {
         strncpy(schemaObjectLit,COM_PRIVATE_SCHEMA_OBJECT_LIT,2);
         break;
      }
      case COM_SCHEMA_CLASS_SHARED:
      {
         strncpy(schemaObjectLit,COM_SHARED_SCHEMA_OBJECT_LIT,2);
         break;
      }
      case COM_SCHEMA_CLASS_DEFAULT:
      default:
      {
         // Schemas are private by default, but could choose a different
         // default class here based on CQD or other attribute.
         strncpy(schemaObjectLit,COM_PRIVATE_SCHEMA_OBJECT_LIT,2);
         break;
      } 
   }
   
   str_sprintf(buf, "insert into %s.\"%s\".%s values ('%s', '%s', '%s', '%s', %Ld, %Ld, %Ld, '%s', '%s', %d, %d, 0)",
               getSystemCatalog(),SEABASE_MD_SCHEMA,SEABASE_OBJECTS,
               catalogName.data(), quotedSchName.data(), quotedObjName.data(),
               schemaObjectLit,
               schemaObjectUID,
               createTime, 
               createTime,
               COM_YES_LIT, // valid_def
               COM_NO_LIT,  // droppable
               ownerID,ownerID);
               
Int32 cliRC = cliInterface.executeImmediate(buf);
   
   if (cliRC < 0)
   {
      cliInterface.retrieveSQLDiagnostics(CmpCommon::diags());
      return -1;
   }

   return 0;

}
CMMError
DeviceInstance::MakeException() const
{
   return CMMError("Error in device " + ToQuotedString(GetLabel()));
}
CMMError
DeviceInstance::MakeExceptionForCode(int code) const
{
   return CMMError("Error in device " + ToQuotedString(GetLabel()) + ": " +
         GetErrorText(code) + " (" + ToString(code) + ")");
}
Beispiel #20
0
boost::shared_ptr<DeviceInstance>
LoadedDeviceAdapter::LoadDevice(CMMCore* core, const std::string& name,
      const std::string& label,
      mm::logging::Logger deviceLogger,
      mm::logging::Logger coreLogger)
{
   MM::Device* pDevice = CreateDevice(name.c_str());
   if (!pDevice)
      throw CMMError("Device adapter " + ToQuotedString(GetName()) +
            " failed to instantiate device " + ToQuotedString(name));

   MM::DeviceType expectedType;
   try
   {
      expectedType = GetAdvertisedDeviceType(name);
   }
   catch (const CMMError&)
   {
      // The type of a device that was not explictily registered (e.g. a
      // peripheral device or a device provided only for backward
      // compatibility) will not be available.
      expectedType = MM::UnknownType;
   }
   MM::DeviceType actualType = pDevice->GetType();
   if (expectedType == MM::UnknownType)
      expectedType = actualType;

   boost::shared_ptr<LoadedDeviceAdapter> shared_this(shared_from_this());
   DeleteDeviceFunction deleter = boost::bind<void>(&LoadedDeviceAdapter::DeleteDevice, this, _1);

   switch (expectedType)
   {
      case MM::CameraDevice:
         return boost::make_shared<CameraInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::ShutterDevice:
         return boost::make_shared<ShutterInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::StageDevice:
         return boost::make_shared<StageInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::XYStageDevice:
         return boost::make_shared<XYStageInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::StateDevice:
         return boost::make_shared<StateInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::SerialDevice:
         return boost::make_shared<SerialInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::GenericDevice:
         return boost::make_shared<GenericInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::AutoFocusDevice:
         return boost::make_shared<AutoFocusInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::ImageProcessorDevice:
         return boost::make_shared<ImageProcessorInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::SignalIODevice:
         return boost::make_shared<SignalIOInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::MagnifierDevice:
         return boost::make_shared<MagnifierInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::SLMDevice:
         return boost::make_shared<SLMInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::GalvoDevice:
         return boost::make_shared<GalvoInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      case MM::HubDevice:
         return boost::make_shared<HubInstance>(core, shared_this, name, pDevice, deleter, label, deviceLogger, coreLogger);
      default:
         deleter(pDevice);
         throw CMMError("Device " + ToQuotedString(name) +
               " of device adapter " + ToQuotedString(GetName()) +
               " has invalid or unknown type (" + ToQuotedString(actualType) + ")");
   }
}