예제 #1
0
void StepManiaLanServer::UpdateClients()
{
	//Go through all the clients and check to see if it is being used.
	//If so then try to get a backet and parse the data.
	for (unsigned int x = 0; x < Client.size(); ++x)
		if (CheckConnection(x) && (Client[x]->GetData(Packet) >= 0))
			ParseData(Packet, x);
}
예제 #2
0
PVR_ERROR cHTSPData::GetEpg(PVR_HANDLE handle, const PVR_CHANNEL &channel, time_t iStart, time_t iEnd)
{
  if (!CheckConnection())
    return PVR_ERROR_SERVER_ERROR;

  SChannels channels = GetChannels();

  if (channels.find(channel.iUniqueId) != channels.end())
  {
    time_t stop;

    SEvent event;
    event.id = channels[channel.iUniqueId].event;
    if (event.id == 0)
      return PVR_ERROR_NO_ERROR;

    do
    {
      bool success = GetEvent(event, event.id);
      if (success)
      {
        EPG_TAG broadcast;
        memset(&broadcast, 0, sizeof(EPG_TAG));

        broadcast.iUniqueBroadcastId = event.id;
        broadcast.strTitle           = event.title.c_str();
        broadcast.iChannelNumber     = event.chan_id >= 0 ? event.chan_id : channel.iUniqueId;
        broadcast.startTime          = event.start;
        broadcast.endTime            = event.stop;
        broadcast.strPlotOutline     = ""; // unused
        broadcast.strPlot            = event.descs.c_str();
        broadcast.strIconPath        = ""; // unused
        broadcast.iGenreType         = (event.content & 0x0F) << 4;
        broadcast.iGenreSubType      = event.content & 0xF0;
        broadcast.firstAired         = 0;  // unused
        broadcast.iParentalRating    = 0;  // unused
        broadcast.iStarRating        = 0;  // unused
        broadcast.bNotify            = false;
        broadcast.iSeriesNumber      = 0;  // unused
        broadcast.iEpisodeNumber     = 0;  // unused
        broadcast.iEpisodePartNumber = 0;  // unused
        broadcast.strEpisodeName     = ""; // unused

        PVR->TransferEpgEntry(handle, &broadcast);

        event.id = event.next;
        stop = event.stop;
      }
      else
        break;

    } while(iEnd > stop);

    return PVR_ERROR_NO_ERROR;
  }

  return PVR_ERROR_NO_ERROR;
}
예제 #3
0
/*
 * Set values for sequence
 */
int
SetValGTM(char *seqname, GTM_Sequence nextval, bool iscalled)
{
	GTM_SequenceKeyData seqkey;
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

	return conn ? set_val(conn, &seqkey, nextval, iscalled) : -1;
}
예제 #4
0
/*
 * Alter a sequence on the GTM
 */
int
AlterSequenceGTM(char *seqname, GTM_Sequence increment, GTM_Sequence minval,
				 GTM_Sequence maxval, GTM_Sequence startval, GTM_Sequence lastval, bool cycle, bool is_restart)
{
	GTM_SequenceKeyData seqkey;
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

	return conn ? alter_sequence(conn, &seqkey, increment, minval, maxval, startval, lastval, cycle, is_restart) : 0;
}
예제 #5
0
void JohanCity::UpdateTime(float dt) {

	clock->Start();
	
	// Optimized version of power checking...
	CheckPower(); // crawls from power plant outward...
	
	// Optimized version of water checking...
	CheckWater(); // crawls from water source outward...
	
	// TODO: optimize?
	CheckConnection();

	checktilems = clock->Reset() * 1000.0f;
	
	// Then apply tile info to buildings
	CheckBuildingRequisites();
	
	checkbuildingms = clock->Reset() * 1000.0f;

	// Done checking for required items? Spend the RCI
	for(int i = 0;i < tiles.size();i++) {
		for(int j = 0;j < tiles[i].size();j++) {
			TileType type = tiles[i][j]->type;
			if(type == ttResidential || type == ttCommercial || type == ttIndustrial) {
				tiles[i][j]->UpdateTime(dt);
			}
			
			// Undo checks (so they won't get invalid)?
			tiles[i][j]->checkid = -1;
//			tiles[i][j]->powered = false;
//			tiles[i][j]->watered = false;
//			tiles[i][j]->connected = false;
		}
	}
	
	updatetilems = clock->Reset() * 1000.0f;
	
	for(std::list<Building*>::iterator i = buildings.begin();i != buildings.end();i++) {
		Building* building = *i;
		building->UpdateTime(dt);
	}
	
	updatebuildingms = clock->Reset() * 1000.0f;
	
	snprintf(timingreport,256,
		"Check tile time: %.2f ms\r\nCheck building time: %.2f ms\r\nUpdate tile time: %.2f ms\r\nUpdate building time: %.2f ms\r\n",
		checktilems,
		checkbuildingms,
		updatetilems,
		updatebuildingms);
	
	UpdateBuffers();
}
예제 #6
0
/*
 * Drop the sequence depending the key type
 *
 * Type of Sequence name use in key;
 *		GTM_SEQ_FULL_NAME, full name of sequence
 *		GTM_SEQ_DB_NAME, DB name part of sequence key
 */
int
DropSequenceGTM(char *name, GTM_SequenceKeyType type)
{
	GTM_SequenceKeyData seqkey;
	CheckConnection();
	seqkey.gsk_keylen = strlen(name) + 1;
	seqkey.gsk_key = name;
	seqkey.gsk_type = type;

	return conn ? close_sequence(conn, &seqkey) : -1;
}
예제 #7
0
/*
 * Create a sequence on the GTM.
 */
int
CreateSequenceGTM(char *seqname, GTM_Sequence increment, GTM_Sequence minval,
				  GTM_Sequence maxval, GTM_Sequence startval, bool cycle)
{
	GTM_SequenceKeyData seqkey;
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

	return conn ? open_sequence(conn, &seqkey, increment, minval, maxval, startval, cycle) : 0;
}
예제 #8
0
/*
 * Rename the sequence
 */
int
RenameSequenceGTM(char *seqname, const char *newseqname)
{
	GTM_SequenceKeyData seqkey, newseqkey;
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;
	newseqkey.gsk_keylen = strlen(newseqname) + 1;
	newseqkey.gsk_key = (char *) newseqname;

	return conn ? rename_sequence(conn, &seqkey, &newseqkey) : -1;
}
예제 #9
0
/*
 * Report BARRIER
 */
int
ReportBarrierGTM(char *barrier_id)
{
	if (!gtm_backup_barrier)
		return;

	CheckConnection();

	if (!conn)
		return EOF;

	return(report_barrier(conn, barrier_id));
}
예제 #10
0
GTM_Snapshot
GetSnapshotGTM(GlobalTransactionId gxid, bool canbe_grouped)
{
	GTM_Snapshot ret_snapshot = NULL;
	CheckConnection();
	if (conn)
		ret_snapshot = get_snapshot(conn, gxid, canbe_grouped);
	if (ret_snapshot == NULL)
	{
		CloseGTM();
		InitGTM();
	}
	return ret_snapshot;
}
예제 #11
0
void NetworkThread::Run()
{
	while(ReceiveMessages())
	{
		if(myPacket && !myPacket.endOfPacket())
		{
			ParseMessages();
			myPacket.clear();
		}
		
		CheckConnection();
		
		sf::sleep(sf::milliseconds(100));
	}
}
예제 #12
0
PVR_ERROR cHTSPData::RequestEPGForChannel(PVRHANDLE handle, const PVR_CHANNEL &channel, time_t start, time_t end)
{
  if (!CheckConnection())
    return PVR_ERROR_SERVER_ERROR;

  SChannels channels = GetChannels();

  if (channels.find(channel.uid) != channels.end())
  {
    time_t stop;

    SEvent event;
    event.id = channels[channel.uid].event;
    if (event.id == 0)
      return PVR_ERROR_NO_ERROR;

    do
    {
      bool success = GetEvent(event, event.id);
      if (success)
      {
        PVR_PROGINFO broadcast;
        memset(&broadcast, 0, sizeof(PVR_PROGINFO));

        broadcast.channum         = event.chan_id >= 0 ? event.chan_id : channel.number;
        broadcast.uid             = event.id;
        broadcast.title           = event.title.c_str();
        broadcast.subtitle        = event.title.c_str();
        broadcast.description     = event.descs.c_str();
        broadcast.starttime       = event.start;
        broadcast.endtime         = event.stop;
        broadcast.genre_type      = (event.content & 0x0F) << 4;
        broadcast.genre_sub_type  = event.content & 0xF0;
        PVR->TransferEpgEntry(handle, &broadcast);

        event.id = event.next;
        stop = event.stop;
      }
      else
        break;

    } while(end > stop);

    return PVR_ERROR_NO_ERROR;
  }

  return PVR_ERROR_NO_ERROR;
}
예제 #13
0
GetNextValGTM(char *seqname)
#endif
{
	GTM_Sequence ret = -1;
	GTM_SequenceKeyData seqkey;
#ifdef XCP
	char   *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : MyCoordName;
	int		coordPid = IS_PGXC_COORDINATOR ? MyProcPid : MyCoordPid;
	int		status;
#endif
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

#ifdef XCP
	if (conn)
		status = get_next(conn, &seqkey, coordName,
						  coordPid, range, &ret, rangemax);
	else
		status = GTM_RESULT_COMM_ERROR;

	/* retry once */
	if (status == GTM_RESULT_COMM_ERROR)
	{
		CloseGTM();
		InitGTM();
		if (conn)
			status = get_next(conn, &seqkey, coordName, coordPid,
							  range, &ret, rangemax);
	}
	if (status != GTM_RESULT_OK)
		ereport(ERROR,
				(errcode(ERRCODE_INTERNAL_ERROR),
				 errmsg("%s", GTMPQerrorMessage(conn))));
#else
	if (conn)
		ret = get_next(conn, &seqkey);
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
	}
#endif
	return ret;
}
예제 #14
0
파일: common.c 프로젝트: dankrusi/postgres
/*
 * AcceptResult
 *
 * Checks whether a result is valid, giving an error message if necessary;
 * and ensures that the connection to the backend is still up.
 *
 * Returns true for valid result, false for error state.
 */
static bool
AcceptResult(const PGresult *result)
{
	bool		OK;

	if (!result)
		OK = false;
	else
		switch (PQresultStatus(result))
		{
			case PGRES_COMMAND_OK:
			case PGRES_TUPLES_OK:
			case PGRES_EMPTY_QUERY:
			case PGRES_COPY_IN:
			case PGRES_COPY_OUT:
			case PGRES_COPY_BOTH:
				/* Fine, do nothing */
				OK = true;
				break;

			case PGRES_BAD_RESPONSE:
			case PGRES_NONFATAL_ERROR:
			case PGRES_FATAL_ERROR:
				OK = false;
				break;

			default:
				OK = false;
				psql_error("unexpected PQresultStatus (%d)",
						   PQresultStatus(result));
				break;
		}

	if (!OK)
	{
		const char *error = PQerrorMessage(pset.db);

		if (strlen(error))
			psql_error("%s", error);

		CheckConnection();
	}

	return OK;
}
예제 #15
0
/* Update is run regulary and we gather the state of the Wiiremote and see if the user have pressed on a button or moved the wiiremote
   This could have been done with callbacks instead but it doesn't look nice in C++*/
void CWiiRemote::Update()
{
  if (m_DisconnectWhenPossible)
  {//If the user have choosen to disconnect or lost comunication
    DisconnectNow(true);
    m_DisconnectWhenPossible = false;
  }
#ifdef CWIID_OLD
  if(m_connected)
  {//Here we check if the connection is suddenly broken
    if (!CheckConnection())
    {
      DisconnectNow(true);
      return;
    }
  }
#endif
}
예제 #16
0
/*
 * Get the next sequence value
 */
GTM_Sequence
GetNextValGTM(char *seqname)
{
	GTM_Sequence ret = -1;
	GTM_SequenceKeyData seqkey;
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

	if (conn)
		ret =  get_next(conn, &seqkey);
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
	}
	return ret;
}
예제 #17
0
/*
 * Set values for sequence
 */
int
SetValGTM(char *seqname, GTM_Sequence nextval, bool iscalled)
{
	GTM_SequenceKeyData seqkey;
#ifdef XCP
	char   *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : MyCoordName;
	int		coordPid = IS_PGXC_COORDINATOR ? MyProcPid : MyCoordPid;
#endif
	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

#ifdef XCP
	return conn ? set_val(conn, &seqkey, coordName, coordPid, nextval, iscalled) : -1;
#else
	return conn ? set_val(conn, &seqkey, nextval, iscalled) : -1;
#endif
}
예제 #18
0
파일: common.c 프로젝트: GisKook/Gis
/*
 * ProcessCopyResult: if command was a COPY FROM STDIN/TO STDOUT, handle it
 *
 * Note: Utility function for use by SendQuery() only.
 *
 * Returns true if the query executed successfully, false otherwise.
 */
static bool
ProcessCopyResult(PGresult *results)
{
	bool		success = false;

	if (!results)
		return false;

	switch (PQresultStatus(results))
	{
		case PGRES_TUPLES_OK:
		case PGRES_COMMAND_OK:
		case PGRES_EMPTY_QUERY:
			/* nothing to do here */
			success = true;
			break;

		case PGRES_COPY_OUT:
			SetCancelConn();
			success = handleCopyOut(pset.db, pset.queryFout);
			ResetCancelConn();
			break;

		case PGRES_COPY_IN:
			SetCancelConn();
			success = handleCopyIn(pset.db, pset.cur_cmd_source,
								   PQbinaryTuples(results));
			ResetCancelConn();
			break;

		default:
			break;
	}

	/* may need this to recover from conn loss during COPY */
	if (!CheckConnection())
		return false;

	return success;
}
예제 #19
0
파일: common.c 프로젝트: sunyangkobe/cscd43
/*
 * ProcessCopyResult: if command was a COPY FROM STDIN/TO STDOUT, handle it
 *
 * Note: Utility function for use by SendQuery() only.
 *
 * Returns true if the query executed successfully, false otherwise.
 */
static bool
ProcessCopyResult(PGresult *results)
{
	bool		success = false;

	if (!results)
		return false;

	switch (PQresultStatus(results))
	{
		case PGRES_TUPLES_OK:
		case PGRES_COMMAND_OK:
		case PGRES_EMPTY_QUERY:
			/* nothing to do here */
			success = true;
			break;

		case PGRES_COPY_OUT:
			success = handleCopyOut(pset.db, pset.queryFout);
			break;

		case PGRES_COPY_IN:
			if (pset.cur_cmd_interactive && !QUIET())
				puts(gettext("Enter data to be copied followed by a newline.\n"
							 "End with a backslash and a period on a line by itself."));

			success = handleCopyIn(pset.db, pset.cur_cmd_source,
			  pset.cur_cmd_interactive ? get_prompt(PROMPT_COPY) : NULL);
			break;

		default:
			break;
	}

	/* may need this to recover from conn loss during COPY */
	if (!CheckConnection())
		return false;

	return success;
}
예제 #20
0
int
PrepareTranGTM(GlobalTransactionId gxid)
{
	int ret;

	if (!GlobalTransactionIdIsValid(gxid))
		return 0;
	CheckConnection();
	ret = prepare_transaction(conn, gxid);

	/*
	 * If something went wrong (timeout), try and reset GTM connection. 
	 * We will close the transaction locally anyway, and closing GTM will force
	 * it to be closed on GTM.
	 */
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
	}
	return ret;
}
예제 #21
0
파일: SQL.cpp 프로젝트: firef0xff/SQL
bool cSQL::SendCommand(const String &request)
{
#ifdef NODB
   return true;
#endif
   if (!CheckConnection())
   {
      return false;
   }
   try
   {
      if (mEnableLog)
         log.push_back(Time().TimeString() + "---" + request);
      cmd->CommandText = request;
      cmd->Execute();
      return true;
   }
   catch (Exception &exception)
   {
      return false;
   }
}
예제 #22
0
GlobalTransactionId
BeginTranGTM(GTM_Timestamp *timestamp)
{
	GlobalTransactionId  xid = InvalidGlobalTransactionId;

	CheckConnection();
	// TODO Isolation level
	if (conn)
		xid =  begin_transaction(conn, GTM_ISOLATION_RC, timestamp);

	/* If something went wrong (timeout), try and reset GTM connection 
	 * and retry. This is safe at the beginning of a transaction.
	 */
	if (!TransactionIdIsValid(xid))
	{
		CloseGTM();
		InitGTM();
		if (conn)
			xid = begin_transaction(conn, GTM_ISOLATION_RC, timestamp);
	}
	return xid;
}
예제 #23
0
int main()
{
 DBusServer* server;
	DBusConnection* connection;
	DBusError error;
	char* address;
		
	dbus_error_init(&error);
	server = dbus_server_listen("tcp:host=localhost,port=8085", &error);
	
	if(!server)
	{
		std_log(LOG_FILENAME_LINE, "Error :: %s\n%s",error.name,error.message);
		std_log(LOG_FILENAME_LINE, "Fail");
		create_xml(1);
		return 1;
	}
	
	address = dbus_server_get_address(server);
	std_log(LOG_FILENAME_LINE, "Address :; %s",address);
	
	
	connection = dbus_connection_open_private("tcp:host=localhost,port=8085", &error);
	if(!CheckConnection(connection, &error))
		return 1;
	

	dbus_connection_close(connection);
	dbus_connection_unref(connection);
	dbus_shutdown();
	
	dbus_server_disconnect(server);	
	
	std_log(LOG_FILENAME_LINE, "SUCCESS");
	
	create_xml(0);
	return 0;
}
예제 #24
0
/*
 * Register Given Node
 * Connection for registering is just used once then closed
 */
int
RegisterGTM(GTM_PGXCNodeType type, GTM_PGXCNodePort port, char *datafolder)
{
	int ret;

	CheckConnection();

	if (!conn)
		return EOF;

	ret = node_register(conn, type, port, PGXCNodeName, datafolder);

	/* If something went wrong, retry once */
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
		if (conn)
			ret = node_register(conn, type, port, PGXCNodeName, datafolder);
	}

	return ret;
}
예제 #25
0
/*
 * Get the next sequence value
 */
GTM_Sequence
GetNextValGTM(char *seqname)
{
	GTM_Sequence ret = -1;
	GTM_SequenceKeyData seqkey;
	int	status;

	CheckConnection();
	seqkey.gsk_keylen = strlen(seqname) + 1;
	seqkey.gsk_key = seqname;

	if (conn)
		status =  get_next(conn, &seqkey, &ret);
	if (status != GTM_RESULT_OK)
	{
		CloseGTM();
		InitGTM();
		ereport(ERROR,
				(errcode(ERRCODE_INTERNAL_ERROR),
				 errmsg("%s", GTMPQerrorMessage(conn))));
	}
	return ret;
}
예제 #26
0
GlobalTransactionId
BeginTranAutovacuumGTM(void)
{
	GlobalTransactionId  xid = InvalidGlobalTransactionId;

	CheckConnection();
	// TODO Isolation level
	if (conn)
		xid =  begin_transaction_autovacuum(conn, GTM_ISOLATION_RC);

	/*
	 * If something went wrong (timeout), try and reset GTM connection and retry.
	 * This is safe at the beginning of a transaction.
	 */
	if (!TransactionIdIsValid(xid))
	{
		CloseGTM();
		InitGTM();
		if (conn)
			xid =  begin_transaction_autovacuum(conn, GTM_ISOLATION_RC);
	}
	return xid;
}
예제 #27
0
int
CommitTranGTM(GlobalTransactionId gxid, int waited_xid_count,
		GlobalTransactionId *waited_xids)
{
	int ret;

	if (!GlobalTransactionIdIsValid(gxid))
		return 0;
	CheckConnection();
#ifdef XCP
	ret = -1;
	if (conn)
#endif
	ret = commit_transaction(conn, gxid, waited_xid_count, waited_xids);

	/*
	 * If something went wrong (timeout), try and reset GTM connection.
	 * We will close the transaction locally anyway, and closing GTM will force
	 * it to be closed on GTM.
	 */
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
#ifdef XCP
		if (conn)
			ret = commit_transaction(conn, gxid, waited_xid_count, waited_xids);
#endif
	}

	/* Close connection in case commit is done by autovacuum worker or launcher */
	if (IsAutoVacuumWorkerProcess() || IsAutoVacuumLauncherProcess())
		CloseGTM();

	currentGxid = InvalidGlobalTransactionId;
	return ret;
}
예제 #28
0
파일: common.c 프로젝트: sunyangkobe/cscd43
/*
 * AcceptResult
 *
 * Checks whether a result is valid, giving an error message if necessary;
 * resets cancelConn as needed, and ensures that the connection to the backend
 * is still up.
 *
 * Returns true for valid result, false for error state.
 */
static bool
AcceptResult(const PGresult *result)
{
	bool		OK = true;

	ResetCancelConn();

	if (!result)
		OK = false;
	else
		switch (PQresultStatus(result))
		{
			case PGRES_COMMAND_OK:
			case PGRES_TUPLES_OK:
			case PGRES_EMPTY_QUERY:
			case PGRES_COPY_IN:
				/* Fine, do nothing */
				break;

			case PGRES_COPY_OUT:
				/* keep cancel connection for copy out state */
				SetCancelConn();
				break;

			default:
				OK = false;
				break;
		}

	if (!OK)
	{
		psql_error("%s", PQerrorMessage(pset.db));
		CheckConnection();
	}

	return OK;
}
예제 #29
0
/*
 * For a prepared transaction, commit the gxid used for PREPARE TRANSACTION
 * and for COMMIT PREPARED.
 */
int
CommitPreparedTranGTM(GlobalTransactionId gxid, GlobalTransactionId prepared_gxid)
{
	int ret = 0;

	if (!GlobalTransactionIdIsValid(gxid) || !GlobalTransactionIdIsValid(prepared_gxid))
		return ret;
	CheckConnection();
	ret = commit_prepared_transaction(conn, gxid, prepared_gxid);

	/*
	 * If something went wrong (timeout), try and reset GTM connection.
	 * We will close the transaction locally anyway, and closing GTM will force
	 * it to be closed on GTM.
	 */

	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
	}
	currentGxid = InvalidGlobalTransactionId;
	return ret;
}
예제 #30
0
int
RollbackTranGTM(GlobalTransactionId gxid)
{
	int ret = -1;

	if (!GlobalTransactionIdIsValid(gxid))
		return 0;
	CheckConnection();

	if (conn)
		ret = abort_transaction(conn, gxid);

	/*
	 * If something went wrong (timeout), try and reset GTM connection. 
	 * We will abort the transaction locally anyway, and closing GTM will force
	 * it to end on GTM.
	 */
	if (ret < 0)
	{
		CloseGTM();
		InitGTM();
	}
	return ret;
}