Exemplo n.º 1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void App::addObject(const std::string& parentID, DataModel::Object* o) {
	DataModel::PublicObject *po = DataModel::PublicObject::Cast(o);
	if ( po != NULL )
		SEISCOMP_DEBUG("adding  %-12s %s",o->className(),po->publicID().c_str());
	else
		return;

	DataModel::Pick *pick = DataModel::Pick::Cast(o);
	if ( pick ) {
		logObject(_inputPicks, Core::Time::GMT());
		feed(pick);
		return;
	}

	DataModel::Amplitude *amplitude = DataModel::Amplitude::Cast(o);
	if ( amplitude ) {
		logObject(_inputAmps, Core::Time::GMT());
		feed(amplitude);
		return;
	}

	DataModel::Origin *origin = DataModel::Origin::Cast(o);
	if ( origin ) {
		logObject(_inputOrgs, Core::Time::GMT());
		feed(origin);
		return;
	}
}
Exemplo n.º 2
0
		bool write(DataModel::Object *object) {
			if ( SCCoreApp->isExitRequested() ) return false;

			RoutingTable::iterator targetIt = _routingTable.find(object->className());
			if ( targetIt == _routingTable.end() )
				return false;

			DataModel::PublicObject *parent = object->parent();

			if ( !parent ) {
				cerr << "No parent found for object " << object->className() << endl;
				return false;
			}

			cout << char(toupper(_operation.toString()[0])) << "  "
			     << indent(object)
			     << object->className() << "(";

			DataModel::PublicObject *po = DataModel::PublicObject::Cast(object);
			if ( po != NULL )
				cout << "'" << po->publicID() << "'";
			else {
				const Core::MetaObject *meta = object->meta();
				bool first = true;
				for ( size_t i= 0; i < meta->propertyCount(); ++i ) {
					const Core::MetaProperty *prop = meta->property(i);
					if ( prop->isIndex() ) {
						if ( !first ) cout << ",";
						if ( prop->type() == "string" )
							cout << "'" << prop->readString(object) << "'";
						else
							cout << prop->readString(object);
						first = false;
					}
				}
			}

			cout << ")" << endl;

			_parentID = parent->publicID();

			++_count;

			if ( _test ) return true;

			DataModel::NotifierMessage notifierMessage;
			notifierMessage.attach(new DataModel::Notifier(_parentID, _operation, object));

			unsigned int counter = 0;
			while ( counter <= 4 ) {
				if ( _connection->send(targetIt->second, &notifierMessage) ) {
					if ( _count % 100 == 0 ) SCCoreApp->sync();
					return true;
				}

				cerr << "Could not send object " << object->className()
				<< " to " << targetIt->second << "@" << _connection->masterAddress()
				<< endl;
				if ( _connection->isConnected() ) break;
				++counter;
				sleep(1);
			}

			++_errors;
			return false;
		}