Beispiel #1
0
Boolean ImageItem::targetDrop(IDMTargetDropEvent& event)
{
  movieFrame->imageCenter = targetOperation()->position();
  movieFrame->newFileName = containerName() + sourceName();
  movieFrame->postEvent(WM_CUSTOM_SETMOVIE);
  return true;
}
Beispiel #2
0
Boolean DMDatei::sourceDiscard (IDMSourceDiscardEvent &e)
{
        e.setWhoDiscards (IDM::sourceDiscards);
        DosDelete (containerName () + "\\" + sourceName ());
        delete (Datei *)object ();
        return true;
}
Beispiel #3
0
BOOL
CNdasDeviceRegistrar::Unregister(DWORD SlotNo)
{
	InstanceAutoLock autolock(this);

	DeviceSlotMap::iterator slot_itr = m_deviceSlotMap.find(SlotNo);

	if (m_deviceSlotMap.end() == slot_itr) 
	{
		// TODO: Make more specific error code
		::SetLastError(NDASSVC_ERROR_DEVICE_ENTRY_NOT_FOUND);
		return FALSE;
	}

	CNdasDevicePtr pDevice = slot_itr->second;

	if (NDAS_DEVICE_STATUS_DISABLED != pDevice->GetStatus()) 
	{
		// TODO: ::SetLastError(NDAS_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		// TODO: Make more specific error code
		::SetLastError(NDASSVC_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		return FALSE;
	}

	DeviceIdMap::iterator id_itr = m_deviceIdMap.find(pDevice->GetDeviceId());

	XTLASSERT(m_deviceIdMap.end() != id_itr);

	m_deviceIdMap.erase(id_itr);
	m_deviceSlotMap.erase(slot_itr);
	m_slotbit[SlotNo] = FALSE;

	XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);
	BOOL fSuccess = _NdasSystemCfg.DeleteContainer(containerName, FALSE);
	
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
			"Deleting registration entry from the registry failed at %ls, error=0x%X\n", 
			containerName, GetLastError());
	}

	(void) m_service.GetEventPublisher().DeviceEntryChanged();

	return TRUE;

}
Beispiel #4
0
BOOL 
CNdasDeviceRegistrar::Unregister(const NDAS_DEVICE_ID& DeviceId)
{
	InstanceAutoLock autolock(this);

	XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
		"Unregister device %s\n", CNdasDeviceId(DeviceId).ToStringA());

	DeviceIdMap::iterator itrId = m_deviceIdMap.find(DeviceId);
	if (m_deviceIdMap.end() == itrId) 
	{
		::SetLastError(NDASSVC_ERROR_DEVICE_ENTRY_NOT_FOUND);
	}

	CNdasDevicePtr pDevice = itrId->second;
	
	if (pDevice->GetStatus() != NDAS_DEVICE_STATUS_DISABLED) 
	{
		::SetLastError(NDASSVC_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE);
		return FALSE;
	}

	DWORD SlotNo = pDevice->GetSlotNo();
	XTLASSERT(0 != SlotNo);

	DeviceSlotMap::iterator itrSlot = m_deviceSlotMap.find(SlotNo);

	m_deviceIdMap.erase(itrId);
	m_deviceSlotMap.erase(itrSlot);
	m_slotbit[SlotNo] = false;

	XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);
	BOOL fSuccess = _NdasSystemCfg.DeleteContainer(containerName, TRUE);
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
			"Deleting registration entry from the registry failed at %ls, error=0x%X\n", 
			containerName, GetLastError());
	}

	(void) m_service.GetEventPublisher().DeviceEntryChanged();

	return TRUE;
}
Beispiel #5
0
STDMETHODIMP
CNdasDeviceRegistrar::Register(
    __in_opt DWORD SlotNo,
    __in const NDAS_DEVICE_ID& DeviceId,
    __in DWORD RegFlags,
    __in_opt const NDASID_EXT_DATA* NdasIdExtension,
    __in BSTR Name,
    __in ACCESS_MASK GrantedAccess,
    __in_opt const NDAS_OEM_CODE* NdasOemCode,
    __deref_out INdasDevice** ppNdasDevice)
{
    HRESULT hr;

    *ppNdasDevice = 0;

    NDAS_DEVICE_ID ndasDeviceId = DeviceId;

    //
    // this will lock this class from here
    // and releases the lock when the function returns;
    //
    CAutoLock<CLock> autolock(&m_DataLock);

    XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
              "Registering device %s at slot %d\n",
              CNdasDeviceId(DeviceId).ToStringA(), SlotNo);

    if (NULL == NdasIdExtension)
    {
        NdasIdExtension = &NDAS_ID_EXTENSION_DEFAULT;
    }

    //
    // Only DEFAULT and SEAGATE are currently implemented
    //
    if (NDAS_VID_SEAGATE != NdasIdExtension->VID	&&
            NDAS_VID_WINDWOS_RO != NdasIdExtension->VID		&&
            NDAS_VID_DEFAULT != NdasIdExtension->VID)
    {
        XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_ERROR,
                  "Unknown Vendor ID=0x%02X\n",
                  NdasIdExtension->VID);

        hr = NDASSVC_ERROR_UNKNOWN_VENDOR_ID;
        return hr;
    }

    ndasDeviceId.VID = NdasIdExtension->VID;

    // If SlotNo is zero, automatically assign it.
    // check slot number
    if (0 == SlotNo)
    {
        SlotNo = pLookupEmptySlot();
        if (0 == SlotNo)
        {
            return NDASSVC_ERROR_DEVICE_ENTRY_SLOT_FULL;
        }
    }
    else if (SlotNo > MAX_SLOT_NUMBER)
    {
        return NDASSVC_ERROR_INVALID_SLOT_NUMBER;
    }

    // check and see if the slot is occupied
    if (m_slotbit[SlotNo])
    {
        return NDASSVC_ERROR_SLOT_ALREADY_OCCUPIED;
    }

    // find an duplicate address
    {
        CComPtr<INdasDevice> pExistingDevice;
        if (SUCCEEDED(get_NdasDevice(&ndasDeviceId, &pExistingDevice)))
        {
            return NDASSVC_ERROR_DUPLICATE_DEVICE_ENTRY;
        }
    }

    // register
    CComObject<CNdasDevice>* pNdasDeviceInstance;
    hr = CComObject<CNdasDevice>::CreateInstance(&pNdasDeviceInstance);
    if (FAILED(hr))
    {
        return hr;
    }

    hr = pNdasDeviceInstance->Initialize(
             SlotNo, ndasDeviceId, RegFlags, NdasIdExtension);
    if (FAILED(hr))
    {
        XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_ERROR,
                  "Device initialization failed, error=0x%X\n", GetLastError());
        return hr;
    }

    CComPtr<INdasDevice> pNdasDevice(pNdasDeviceInstance);

    COMVERIFY(pNdasDevice->put_Name(Name));
    COMVERIFY(pNdasDevice->put_GrantedAccess(GrantedAccess));
    if (NdasOemCode)
    {
        COMVERIFY(pNdasDevice->put_OemCode(NdasOemCode));
    }

    m_slotbit[SlotNo] = true;

    bool insertResult;

    m_NdasDevices.Add(pNdasDevice);

    XTLVERIFY( m_deviceSlotMap.insert(std::make_pair(SlotNo, pNdasDevice)).second );
    //DeviceSlotMap::value_type(SlotNo, pNdasDevice)).second;

    XTLVERIFY( m_deviceIdMap.insert(std::make_pair(ndasDeviceId, pNdasDevice)).second );
    //DeviceIdMap::value_type(ndasDeviceId, pNdasDevice)).second;

    XTLASSERT(m_deviceSlotMap.size() == m_deviceIdMap.size());

    //
    // When NdasIdExtension is NULL, NDAS_ID_EXTENSION_DEFAULT is assigned already
    //

    if (RegFlags & NDAS_DEVICE_REG_FLAG_VOLATILE)
    {
    }
    else
    {
        BOOL success;
        XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);

        if (0 != memcmp(&NDAS_ID_EXTENSION_DEFAULT, NdasIdExtension, sizeof(NDASID_EXT_DATA)))
        {
            NDAS_DEVICE_ID_REG_DATA regData = {0};
            regData.DeviceId = ndasDeviceId;
            regData.NdasIdExtension = *NdasIdExtension;

            success = _NdasSystemCfg.SetSecureValueEx(
                          containerName,
                          _T("DeviceID2"),
                          &regData,
                          sizeof(regData));
        }
        else
        {
            success = _NdasSystemCfg.SetSecureValueEx(
                          containerName,
                          _T("DeviceID"),
                          &ndasDeviceId,
                          sizeof(ndasDeviceId));
        }

        if (!success)
        {
            XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
                      "Writing registration entry to the registry failed at %ls, error=0x%X\n",
                      containerName.ToString(), GetLastError());
        }

        success = _NdasSystemCfg.SetSecureValueEx(
                      containerName,
                      _T("RegFlags"),
                      &RegFlags,
                      sizeof(RegFlags));

        if (!success)
        {
            XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
                      "Writing registration entry to the registry failed at %ls, error=0x%X\n",
                      containerName.ToString(), GetLastError());
        }
    }

    BOOL publishEvent = !m_fBootstrapping;

    autolock.Release();

    //
    // During bootstrapping, we do not publish this event
    // Bootstrap process will publish an event later
    //

    if (publishEvent)
    {
        (void) pGetNdasEventPublisher().DeviceEntryChanged();
    }

    *ppNdasDevice = pNdasDevice.Detach();

    return S_OK;
}
Beispiel #6
0
STDMETHODIMP
CNdasDeviceRegistrar::Deregister(INdasDevice* pNdasDevice)
{
    NDAS_DEVICE_ID ndasDeviceId;
    HRESULT hr;

    COMVERIFY(hr = pNdasDevice->get_NdasDeviceId(&ndasDeviceId));
    if (FAILED(hr))
    {
        return hr;
    }

    DWORD slotNo;
    COMVERIFY(hr = pNdasDevice->get_SlotNo(&slotNo));
    XTLASSERT(0 != slotNo);

    NDAS_DEVICE_STATUS status;
    COMVERIFY(pNdasDevice->get_Status(&status));
    if (NDAS_DEVICE_STATUS_DISABLED != status)
    {
        return NDASSVC_ERROR_CANNOT_UNREGISTER_ENABLED_DEVICE;
    }

    CAutoLock<CLock> autolock(&m_DataLock);

    XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
              "Unregister device %s\n", CNdasDeviceId(ndasDeviceId).ToStringA());

    bool found = false;
    size_t count = m_NdasDevices.GetCount();
    for (size_t i = 0; i < count; ++i)
    {
        CComPtr<INdasDevice> p = m_NdasDevices.GetAt(i);
        if (p == pNdasDevice)
        {
            m_NdasDevices.RemoveAt(i);
            found = true;
            break;
        }
    }

    if (!found)
    {
        return NDASSVC_ERROR_DEVICE_ENTRY_NOT_FOUND;
    }

    DeviceIdMap::iterator itrId = m_deviceIdMap.find(ndasDeviceId);
    ATLASSERT(m_deviceIdMap.end() != itrId);

    DeviceSlotMap::iterator itrSlot = m_deviceSlotMap.find(slotNo);
    ATLASSERT(m_deviceSlotMap.end() != itrSlot);

    m_deviceIdMap.erase(itrId);
    m_deviceSlotMap.erase(itrSlot);

    m_slotbit[slotNo] = false;

    XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), slotNo);
    BOOL success = _NdasSystemCfg.DeleteContainer(containerName, TRUE);
    if (!success)
    {
        XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
                  "Deleting registration entry from the registry failed at %ls, error=0x%X\n",
                  containerName, GetLastError());
    }

    autolock.Release();

    (void) pGetNdasEventPublisher().DeviceEntryChanged();

    return S_OK;
}
int main (int argc, char** argv)
{
  std::vector<coral::Option> secondaryOptions;
  //
  coral::Option csPar("conn_string");
  csPar.flag = "-c";
  csPar.helpEntry = "the database connection string";
  csPar.type = coral::Option::STRING;
  secondaryOptions.push_back(csPar);
  //
  coral::Option contPar("container");
  contPar.flag = "-cn";
  contPar.helpEntry = "the selected container name";
  contPar.type = coral::Option::STRING;
  secondaryOptions.push_back(contPar);
  //
  coral::Option mvPar("mapping_version");
  mvPar.flag = "-mv";
  mvPar.helpEntry ="the mapping version";
  mvPar.type = coral::Option::STRING;
  secondaryOptions.push_back(mvPar);
  //
  coral::Option cvPar("class_versions");
  cvPar.flag = "-cv";
  cvPar.helpEntry ="specify the class versions";
  cvPar.type = coral::Option::BOOLEAN;
  secondaryOptions.push_back(cvPar);
  //
  coral::Option outPar("output_file");
  outPar.flag = "-f";
  outPar.helpEntry = "the database host name";
  outPar.type = coral::Option::STRING;
  secondaryOptions.push_back(outPar);
  //
  coral::Option authPar("authentication_path");
  authPar.flag = "-a";
  authPar.helpEntry = "the authentication path";
  authPar.type = coral::Option::STRING;
  secondaryOptions.push_back(authPar);
  //
  coral::Option classPar("type_name");
  classPar.flag = "-t";
  classPar.helpEntry = "the container type name";
  classPar.type = coral::Option::STRING;
  secondaryOptions.push_back(classPar);
  //
  coral::Option dictPar("dictionary");
  dictPar.flag = "-D";
  dictPar.helpEntry = "the list of dictionary libraries";
  dictPar.type = coral::Option::STRING;
  secondaryOptions.push_back(dictPar);
  //
  coral::Option debugPar("debug");
  debugPar.flag = "-debug";
  debugPar.helpEntry ="print the debug messages";
  debugPar.type = coral::Option::BOOLEAN;
  secondaryOptions.push_back(debugPar);
  //
  std::vector<coral::Command> mainSet;
  //
  coral::Command listCont("list_containers");
  listCont.flag = "-list";
  listCont.helpEntry = "listing the available containers";
  listCont.type = coral::Option::BOOLEAN;
  listCont.exclusive = true;
  listCont.addOption(csPar.name);
  listCont.addOption(authPar.name);
  listCont.addOption(debugPar.name);
  mainSet.push_back(listCont);
  //
  coral::Command createCont("create");
  createCont.flag = "-create";
  createCont.helpEntry = "create a database or a container";
  createCont.type = coral::Option::BOOLEAN;
  createCont.exclusive = true;
  createCont.addOption(csPar.name);
  createCont.addOption(contPar.name);
  createCont.addOption(classPar.name);
  createCont.addOption(dictPar.name);
  createCont.addOption(authPar.name);
  createCont.addOption(debugPar.name);
  mainSet.push_back(createCont);
  //
  coral::Command eraseCont("erase");
  eraseCont.flag = "-erase";
  eraseCont.helpEntry = "erase a database or a container";
  eraseCont.type = coral::Option::BOOLEAN;
  eraseCont.exclusive = true;
  eraseCont.addOption(csPar.name);
  eraseCont.addOption(contPar.name);
  eraseCont.addOption(authPar.name);
  eraseCont.addOption(debugPar.name);
  mainSet.push_back(eraseCont);
  //
  coral::Command listMapp("list_mappings");
  listMapp.flag = "-lm";
  listMapp.helpEntry = "listing the available mapping versions";
  listMapp.type = coral::Option::BOOLEAN;
  listMapp.exclusive = true;
  listMapp.addOption(csPar.name);
  listMapp.addOption(contPar.name);
  listMapp.addOption(cvPar.name);
  listMapp.addOption(authPar.name);
  listMapp.addOption(debugPar.name);
  mainSet.push_back(listMapp);
  //
  coral::Command dumpMapp("dump_mapping");
  dumpMapp.flag = "-dm";
  dumpMapp.helpEntry = "dump the specified mapping in xml format";
  dumpMapp.type = coral::Option::BOOLEAN;
  dumpMapp.exclusive = true;
  dumpMapp.addOption(csPar.name);
  dumpMapp.addOption(mvPar.name);
  dumpMapp.addOption(outPar.name);
  dumpMapp.addOption(authPar.name);
  dumpMapp.addOption(debugPar.name);
  mainSet.push_back(dumpMapp);
  //
  try{
    edmplugin::PluginManager::Config config;
    edmplugin::PluginManager::configure(edmplugin::standard::config());
  
    std::vector<edm::ParameterSet> psets;
    edm::ParameterSet pSet;
    pSet.addParameter("@service_type",std::string("SiteLocalConfigService"));
    psets.push_back(pSet);
    static const edm::ServiceToken services(edm::ServiceRegistry::createSet(psets));
    static const edm::ServiceRegistry::Operate operate(services);

    std::string connectionString("");
    std::string authenticationPath("CORAL_AUTH_PATH=");
    std::string containerName("");
    std::string mappingVersion("");
    std::string fileName("");
    std::string className("");
    std::string dictionary("");
    bool withClassVersion = false;
    bool debug = false;
    coral::CommandLine cmd(secondaryOptions,mainSet);
    cmd.parse(argc,argv);
    const std::map<std::string,std::string>& ops = cmd.userOptions();
    if(cmd.userCommand()==coral::CommandLine::helpOption().name || ops.size()==0){
      cmd.help(std::cout);
      return 0;
    } else {
      std::map<std::string,std::string>::const_iterator iO=ops.find(coral::CommandLine::helpOption().name);
      if(iO!=ops.end()){
        cmd.help(cmd.userCommand(),std::cout);
        return 0;
      } else {
        iO = ops.find(csPar.name);
        if(iO!=ops.end()) {
          connectionString = iO->second;
        } else {
          throw coral::MissingRequiredOptionException(csPar.name);
        }
        iO = ops.find(contPar.name);
        if(iO!=ops.end()) containerName = iO->second;
        iO = ops.find(mvPar.name);
        if(iO!=ops.end()) mappingVersion = iO->second;
        iO = ops.find(authPar.name);
        if(iO!=ops.end()) {
          authenticationPath.append(iO->second);
          ::putenv( (char*)authenticationPath.c_str() );
        }
        iO = ops.find(outPar.name);
        if(iO!=ops.end()) fileName = iO->second;
        iO = ops.find(classPar.name);
        if(iO!=ops.end()) className = iO->second;
        iO = ops.find(dictPar.name);
        if(iO!=ops.end()) dictionary = iO->second;
        iO = ops.find(cvPar.name);
        if(iO!=ops.end()) withClassVersion = true;
        iO = ops.find(debugPar.name);
        if(iO!=ops.end()) debug = true;

        boost::shared_ptr<ora::ConnectionPool> connection( new ora::ConnectionPool );
        connection->configuration().disablePoolAutomaticCleanUp();
        ora::Database db( connection );
        if( debug ) db.configuration().setMessageVerbosity( coral::Debug );

        std::string contTag("container.name");
        std::string classTag("type");
        std::string nobjTag("n.objects");
        std::string mapVerTag("mapping.id");
        std::string classVerTag("class.version");
        std::string space("  ");
        size_t contMax = contTag.length();
        size_t classMax = classTag.length();
        size_t nobjMax = nobjTag.length();
        size_t mapVerMax = mapVerTag.length();
        size_t classVerMax = classVerTag.length();

        if(cmd.userCommand()==listCont.name){
	  db.connect( connectionString, true );
	  ora::ScopedTransaction transaction( db.transaction() );
          transaction.start();
          if( ! db.exists() ){
	    std::cout << "ORA database does not exists in \""<<connectionString<<"\"."<<std::endl;
	    return 0;
	  }
          std::set<std::string> conts = db.containers();

          std::cout << "ORA database in \""<<connectionString<<"\" has "<<conts.size()<<" container(s)."<<std::endl;
          std::cout <<std::endl;
          if( conts.size() ){
            // first find the max lenghts
            for(std::set<std::string>::const_iterator iC = conts.begin(); iC != conts.end(); ++iC ){
              ora::Container cont = db.containerHandle( *iC );
              if(cont.name().length()>contMax ) contMax = cont.name().length();
              if(cont.className().length()>classMax ) classMax = cont.className().length();
            }
            std::cout << std::setiosflags(std::ios_base::left);
            std::cout <<space<<std::setw(contMax)<<contTag;
            std::cout <<space<<std::setw(classMax)<<classTag;
            std::cout <<space<<std::setw(nobjMax)<<nobjTag;
            std::cout <<std::endl;
            
            std::cout <<space<<std::setfill('-');
            std::cout<<std::setw(contMax)<<"";
            std::cout <<space<<std::setw(classMax)<<"";
            std::cout <<space<<std::setw(nobjMax)<<"";
            std::cout <<std::endl;

            std::cout << std::setfill(' ');
            for(std::set<std::string>::const_iterator iC = conts.begin(); iC != conts.end(); ++iC ){
              ora::Container cont = db.containerHandle( *iC );
              std::cout <<space<<std::setw(contMax)<<cont.name();
              std::cout <<space<<std::setw(classMax)<<cont.className();
              std::stringstream ss;
              ss << std::setiosflags(std::ios_base::right);
              ss <<space<<std::setw(nobjMax)<<cont.size();
              std::cout << ss.str();
              std::cout <<std::endl;
            }
          }
          
          transaction.commit();
          return 0;
        }
        if(cmd.userCommand()==createCont.name){
	  db.connect( connectionString );
	  ora::ScopedTransaction transaction( db.transaction() );
          transaction.start(false);
          if( className.empty() ){
            throw coral::MissingRequiredOptionException(classPar.name);
          }
          if( !dictionary.empty() ){
	    ora::SharedLibraryName libName;
            edmplugin::SharedLibrary shared( libName(dictionary)  );
          }
          if( !db.exists() ){
            db.create();
          } else {
            std::set<std::string> conts = db.containers();
            if( conts.find( containerName )!=conts.end() ){
              std::cout << "ERROR: container \"" << containerName << "\" already exists in the database."<<std::endl;
              return -1;
            }
          }
          db.createContainer( className, containerName );
          transaction.commit();
          return 0;
        }
        if(cmd.userCommand()==eraseCont.name){
	  db.connect( connectionString );
	  ora::ScopedTransaction transaction( db.transaction() );
          transaction.start(false);
          if( containerName.empty() ){
            throw coral::MissingRequiredOptionException(contPar.name);
          }
          if( !db.exists() ){
            std::cout << "ERROR: ORA database does not exist."<<std::endl;
            return -1;
          } else {
            std::set<std::string> conts = db.containers();
            if( conts.find( containerName )==conts.end() ){
              std::cout << "ERROR: container \"" << containerName << "\" does not exists in the database."<<std::endl;
              return -1;
            }
            db.dropContainer( containerName );
            transaction.commit();
            return 0;
          }
        }
        if(cmd.userCommand()==listMapp.name){
	  db.connect( connectionString, true );
	  ora::ScopedTransaction transaction( db.transaction() );
          transaction.start();
          if( containerName.empty() ){
            throw coral::MissingRequiredOptionException(contPar.name);
          }
          if( !db.exists() ){
            std::cout << "ERROR: ORA database does not exist."<<std::endl;
            return -1;
          } else {
            ora::DatabaseUtility util = db.utility();
            if(withClassVersion){
              std::map<std::string,std::string> vers = util.listMappings( containerName );

              std::cout << "ORA database in \""<<connectionString<<"\" has "<<vers.size()<<" class version(s) for container \""<<containerName<<"\"."<<std::endl;
              std::cout <<std::endl;
              if( vers.size() ){
                // first find the max lenghts
                for( std::map<std::string,std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){
                  if( iM->first.length() > classVerMax ) classVerMax = iM->first.length();
                  if( iM->second.length() > mapVerMax ) mapVerMax = iM->second.length();
                }

                std::cout << std::setiosflags(std::ios_base::left);
                std::cout <<space<<std::setw(classVerMax)<<classVerTag;
                std::cout <<space<<std::setw(mapVerMax)<<mapVerTag;
                std::cout <<std::endl;

                std::cout <<space<<std::setfill('-');
                std::cout<<std::setw(classVerMax)<<"";
                std::cout <<space<<std::setw(mapVerMax)<<"";
                std::cout <<std::endl;

                std::cout << std::setfill(' ');
                for( std::map<std::string,std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){
                  std::cout <<space<<std::setw(classVerMax)<<iM->first;
                  std::cout <<space<<std::setw(mapVerMax)<<iM->second;
                  std::cout <<std::endl;
                }
              }              
            } else {
              std::set<std::string> vers = util.listMappingVersions( containerName );

              std::cout << "ORA database in \""<<connectionString<<"\" has "<<vers.size()<<" mapping version(s) for container \""<<containerName<<"\"."<<std::endl;
              std::cout <<std::endl;
              if( vers.size() ){
                // first find the max lenghts
                for( std::set<std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){
                  if( iM->length() > mapVerMax ) mapVerMax = iM->length();
                }

                std::cout << std::setiosflags(std::ios_base::left);
                std::cout <<space<<std::setw(mapVerMax)<<mapVerTag;
                std::cout <<std::endl;

                std::cout <<space<<std::setfill('-');
                std::cout <<std::setw(mapVerMax)<<"";
                std::cout <<std::endl;

                std::cout << std::setfill(' ');
                for( std::set<std::string>::const_iterator iM = vers.begin(); iM != vers.end(); ++iM ){
                  std::cout <<space<<std::setw(mapVerMax)<<*iM;
                  std::cout <<std::endl;
                }
              }
            }
            transaction.commit();
            return 0;
          }
        }
        if(cmd.userCommand()==dumpMapp.name){
	  db.connect( connectionString, true );
	  ora::ScopedTransaction transaction( db.transaction() );
          transaction.start();
          if( mappingVersion.empty() ){
            throw coral::MissingRequiredOptionException(mvPar.name);
          }
          if( !db.exists() ){
            std::cout << "ERROR: ORA database does not exist."<<std::endl;
            return -1;
          } else {
            ora::DatabaseUtility util = db.utility();
            std::auto_ptr<std::fstream> file;
            std::ostream* outputStream = &std::cout;
            if( !fileName.empty() ){
              file.reset(new std::fstream);
              file->open( fileName.c_str(),std::fstream::out );
              outputStream = file.get();
            }
            bool dump = util.dumpMapping( mappingVersion, *outputStream );
            if(!dump){
              std::cout << "Mapping with id=\""<<mappingVersion<<"\" has not been found in the database."<<std::endl;
            }
            if( !fileName.empty() ){
              if( dump ) std::cout << "Mapping with id=\""<<mappingVersion<<"\" dumped in file =\""<<fileName<<"\""<<std::endl;
              file->close();
            }
            transaction.commit();
            return 0;
          }
        }
      }
    }

  } catch (const std::exception& e){
    std::cout << "ERROR: " << e.what() << std::endl;
    return -1;
  } catch (...){
    std::cout << "UNEXPECTED FAILURE." << std::endl;
    return -1;
  }
}
Beispiel #8
0
CNdasDevicePtr
CNdasDeviceRegistrar::Register(
	__in_opt DWORD SlotNo,
	__in const NDAS_DEVICE_ID& DeviceId,
	__in DWORD RegFlags,
	__in_opt const NDASID_EXT_DATA* NdasIdExtension)
{
	//
	// this will lock this class from here
	// and releases the lock when the function returns;
	//
	InstanceAutoLock autolock(this);
	
	XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION,
		"Registering device %s at slot %d\n",
		CNdasDeviceId(DeviceId).ToStringA(), SlotNo);

	if (NULL == NdasIdExtension)
	{
		NdasIdExtension = &NDAS_ID_EXTENSION_DEFAULT;
	}

	//
	// Only DEFAULT and SEAGATE are currently implemented
	//
	if (NDAS_VID_SEAGATE != NdasIdExtension->VID &&
		NDAS_VID_DEFAULT != NdasIdExtension->VID)
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_ERROR,
			"Unknown Vendor ID=0x%02X\n",
			NdasIdExtension->VID);

		::SetLastError(NDASSVC_ERROR_UNKNOWN_VENDOR_ID);
		return CNdasDevicePtr();
	}

	// If SlotNo is zero, automatically assign it.
	// check slot number
	if (0 == SlotNo)
	{
		SlotNo = LookupEmptySlot();
		if (0 == SlotNo)
		{
			return CNdasDevicePtr();
		}
	}
	else if (SlotNo > m_dwMaxSlotNo)
	{
		::SetLastError(NDASSVC_ERROR_INVALID_SLOT_NUMBER);
		return CNdasDevicePtr();
	}

	// check and see if the slot is occupied
	if (m_slotbit[SlotNo])
	{
		::SetLastError(NDASSVC_ERROR_SLOT_ALREADY_OCCUPIED);
		return CNdasDevicePtr();
	}

	// find an duplicate address
	{
		CNdasDevicePtr pExistingDevice = Find(DeviceId);
		if (0 != pExistingDevice.get()) 
		{
			::SetLastError(NDASSVC_ERROR_DUPLICATE_DEVICE_ENTRY);
			return CNdasDevicePtr();
		}
	}

	// register 
	CNdasDevicePtr pDevice(new CNdasDevice(SlotNo, DeviceId, RegFlags, NdasIdExtension));
	if (0 == pDevice.get()) 
	{
		// memory allocation failed
		// No need to set error here!
		return CNdasDevicePtr();
	}

	BOOL fSuccess = pDevice->Initialize();
	if (!fSuccess) 
	{
		XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_ERROR,
			"Device initialization failed, error=0x%X\n", GetLastError());
		return CNdasDevicePtr();
	}

	m_slotbit[SlotNo] = true;

	bool insertResult;

	XTLVERIFY( m_deviceSlotMap.insert(std::make_pair(SlotNo, pDevice)).second );
	//DeviceSlotMap::value_type(SlotNo, pDevice)).second;

	XTLVERIFY( m_deviceIdMap.insert(std::make_pair(DeviceId, pDevice)).second );
	//DeviceIdMap::value_type(DeviceId, pDevice)).second;

	XTLASSERT(m_deviceSlotMap.size() == m_deviceIdMap.size());

	//
	// When NdasIdExtension is NULL, NDAS_ID_EXTENSION_DEFAULT is assigned already
	//

	if (RegFlags & NDAS_DEVICE_REG_FLAG_VOLATILE)
	{
	}
	else
	{
		XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo);

		if (0 != memcmp(&NDAS_ID_EXTENSION_DEFAULT, NdasIdExtension, sizeof(NDASID_EXT_DATA)))
		{
			NDAS_DEVICE_ID_REG_DATA regData = {0};
			regData.DeviceId = DeviceId;
			regData.NdasIdExtension = *NdasIdExtension;

			fSuccess = _NdasSystemCfg.SetSecureValueEx(
				containerName, 
				_T("DeviceID2"), 
				&regData, 
				sizeof(regData));
		}
		else
		{
			fSuccess = _NdasSystemCfg.SetSecureValueEx(
				containerName, 
				_T("DeviceID"), 
				&DeviceId, 
				sizeof(DeviceId));
		}

		if (!fSuccess) 
		{
			XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
				"Writing registration entry to the registry failed at %ls, error=0x%X\n", 
				containerName.ToString(), GetLastError());
		}

		fSuccess = _NdasSystemCfg.SetSecureValueEx(
			containerName,
			_T("RegFlags"),
			&RegFlags,
			sizeof(RegFlags));

		if (!fSuccess) 
		{
			XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING,
				"Writing registration entry to the registry failed at %ls, error=0x%X\n", 
				containerName.ToString(), GetLastError());
		}
	}

	//
	// During bootstrapping, we do not publish this event
	// Bootstrap process will publish an event later
	//
	if (!m_fBootstrapping) 
	{
		(void) m_service.GetEventPublisher().DeviceEntryChanged();
	}

	return pDevice;
}