Esempio n. 1
0
void CShareManager::makePath(const QSharedPointer<SShare> &p)
{
	try	{
		CShareSet::iterator it = prepared_.find(p);
		if(it != prepared_.end())	{
#ifndef QT_TEST
			ERROR_("Share: name: " << p->name << " ip: " << p->ip << " already prepeared.");
#endif
			return;
		}
		it = mounted_.find(p);
		if( it != mounted_.end() )	{
#ifndef QT_TEST
			ERROR_("Share: name: " << p->name << " ip: " << p->ip << " already mounted.");
#endif
			return;
		}
		mounter_->mkdir(*p);
		prepared_.insert(p);
	}
	catch(CShareMounterInterface::CMountError &e)	{
		errors_.push_back( qMakePair(p, qMakePair(e.err(), QString(e.what()) ) ) );
		emit hasErrors();
	}
}
Esempio n. 2
0
void CShareManager::destroyPath(const QSharedPointer<SShare> &p)
{
	CShareSet::iterator it = prepared_.find(p);
	if(it == prepared_.end())	{
#ifndef QT_TEST
		ERROR_("No such share to remove: name: " << p->name << " ip:" << p->ip);
#endif
		return;
	}
	QSharedPointer<SShare> share = *it;
	prepared_.erase(it);
	try	{
		mounter_->rmdir(*share);
	}
	catch(CShareMounterInterface::CMountError &e)	{
		errors_.push_back( qMakePair(share, qMakePair(e.err(), QString(e.what()) ) ) );
		emit hasErrors();
	}
}
	bool TcpDataTransport::connect()
	{
		if (!d_socket)
		{
			boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(getIpAddress()), getPort());
			d_socket.reset(new boost::asio::ip::tcp::socket(ios));

			try
			{
				d_socket->connect(endpoint);
				INFO_("Connected to %s on port %d.", getIpAddress().c_str(), getPort());
			}
			catch(boost::system::system_error& ex)
			{
				ERROR_("Cannot establish connection: %s", ex.what());
				d_socket.reset();
			}
		}

		return bool(d_socket);
	}
Esempio n. 4
0
Errors Device_openDeviceList(DeviceListHandle *deviceListHandle)
{
  assert(deviceListHandle != NULL);

  // open partition list file
  deviceListHandle->file = fopen("/proc/partitions","r");
  if (deviceListHandle->file == NULL)
  {
    return ERROR_(OPEN_FILE,errno);
  }

  // skip first line (header line)
  if (fgets(deviceListHandle->line,sizeof(deviceListHandle->line),deviceListHandle->file) == NULL)
  {
    // ignore error
  }

  // no line read yet
  deviceListHandle->readFlag = FALSE;

  return ERROR_NONE;
}
	void SerialPortDataTransport::startAutoDetect()
	{
		if (d_port && d_port->getSerialPort()->deviceName() == "")
		{
			if (!Settings::getInstance()->IsAutoDetectEnabled)
			{
				INFO_SIMPLE_("Auto detection is disabled through settings !");
				return;
			}

			INFO_SIMPLE_("Serial port is empty ! Starting Auto COM Port Detection...");
			std::vector<boost::shared_ptr<SerialPortXml> > ports;
			if (SerialPortXml::EnumerateUsingCreateFile(ports) && !ports.empty() && getReaderUnit())
			{
				std::vector<unsigned char> cmd = getReaderUnit()->getPingCommand();
				if (cmd.size() > 0)
				{
					boost::shared_ptr<ReaderCardAdapter> rca = getReaderUnit()->getDefaultReaderCardAdapter();
					std::vector<unsigned char> wrappedcmd = rca->adaptCommand(cmd);
					bool found = false;
					for (std::vector<boost::shared_ptr<SerialPortXml> >::iterator i  = ports.begin(); i != ports.end() && !found; ++i)
					{
						try
						{
							INFO_("Processing port {%s}...", (*i)->getSerialPort()->deviceName().c_str());
							(*i)->getSerialPort()->open();
							configure((*i), false);
						
							
							
							d_port = (*i);
							std::vector<unsigned char> r = sendCommand(wrappedcmd, Settings::getInstance()->AutoDetectionTimeout);
							if (r.size() > 0)
							{
								INFO_SIMPLE_("Reader found ! Using this COM port !");
								found = true;
							}
						}
						catch (std::exception& e)
						{
							ERROR_("Exception {%s}", e.what());
						}
						catch (...)
						{
							ERROR_SIMPLE_("Exception received !");
						}

						if ((*i)->getSerialPort()->isOpen())
						{
							(*i)->getSerialPort()->close();
						}
					}

					if (!found)
					{
						INFO_SIMPLE_("No reader found on COM port...");
					}
					else
					{
						d_isAutoDetected = true;
					}
				}
			}
			else
			{
				WARNING_SIMPLE_("No COM Port detected !");
			}
		}
	}