Beispiel #1
0
void CDSegment::DefPoints(const POINT* lpaPoints, const BYTE* lpaTypes, int nCount)
{
	FreeSegment();

	m_paPoints = new CPoint[nCount];
	m_paTypes = new BYTE[nCount];
	m_nCount = nCount;
	if (m_paPoints != NULL && m_paTypes != NULL)
	{
		memcpy(m_paPoints, lpaPoints, m_nCount * sizeof(CPoint));
		memcpy(m_paTypes, lpaTypes, m_nCount * sizeof(BYTE));
	}
}
Beispiel #2
0
CDSegment CDSegment::operator=(const CDSegment &Segment)
{
	CPoint *pNewPoints;
	BYTE * pNewTypes;

	m_nCount = Segment.m_nCount;

	pNewPoints = new CPoint[m_nCount];
	pNewTypes = new BYTE[m_nCount];
	memcpy(pNewPoints, Segment.m_paPoints, m_nCount * sizeof(CPoint));
	memcpy(pNewTypes, Segment.m_paTypes, m_nCount * sizeof(BYTE));
	FreeSegment();			// Get rid of old stuff
	m_paPoints = pNewPoints;
	m_paTypes = pNewTypes;

	return *this;
}
Beispiel #3
0
void TrashAudio(void)
{
  /* If SoundBlaster was initialized... */
  if(SndRate)
  {
    /* Reset DSP */
    WriteDSP(0xD3);
    WriteDSP(0xD0);
    /* Disable DMA */
    outp(0x0A,SBDMA|0x04);
    /* Disable IRQ */
    outp(0x21,inp(0x21)|(1<<SBIRQ));
  }

  /* If SB interrupt vector changed, restore it */
  if(IRQ5Old) { _dos_setvect(SBIRQ+8,IRQ5Old);IRQ5Old=0; }
  /* If low memory was allocated for DMA, free it */
  if(SBSegment) { FreeSegment(SBSegment);SBSegment=0; }
  /* Sound trashed */
  SndRate=0;
}
Beispiel #4
0
CDSegment::~CDSegment()
{
	FreeSegment();
}
Beispiel #5
0
static void
QDMirroringUpdate(
	QDMIRRORUpdateMask 		updateMask,
	bool					validFlag,
	QDMIRRORState 			state,
	QDMIRRORDisabledReason	disabledReason,
	struct timeval          *lastLogTimeVal,
	char                    *errorMessage)
{
#define UPDATE_VALIDFLAG_CMD "update gp_configuration set valid='%c' where dbid = CAST(%d AS SMALLINT)"
#define UPDATE_MASTER_MIRRORING_CMD "update gp_master_mirroring set (summary_state, detail_state, log_time, error_message) = ('%s', %s, '%s'::timestamptz, %s);"
	int count = 0;
	char cmd[200 + QDMIRRORErrorMessageSize * 2 + 3];
	char detailValue[100];
	char logTimeStr[128];
	char *summaryStateString;
	char *detailStateString;
	char errorMessageQuoted[QDMIRRORErrorMessageSize * 2 + 3];
	char *user;
	MemoryContext mcxt = CurrentMemoryContext;
	Segment *master = NULL;

	volatile PQExpBuffer entryBuffer = NULL;
	volatile PGconn		*entryConn = NULL;
	volatile PGresult	*rs = NULL;

	PG_TRY();
	{
		StartTransactionCommand();
		user = getDBSuperuserName("QDMirroringUpdate");
		Assert(user != NULL);

		master = GetMasterSegment();
		entryBuffer = createPQExpBuffer();
		if (PQExpBufferBroken(entryBuffer))
		{
			destroyPQExpBuffer(entryBuffer);
			ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY),
							errmsg("QDMirroringUpdate: out of memory")));
			/* not reached. */
		}

		/*
		 * initialize libpq connection buffer, we only need to initialize it
		 * once.
		 */
		initPQConnectionBuffer(master, user, NULL, entryBuffer, true);
		FreeSegment(master);

		free(user);

		/*
		 * Call libpq to connect
		 */
		entryConn = PQconnectdb(entryBuffer->data);

		if (PQstatus((PGconn *)entryConn) == CONNECTION_BAD)
		{
			/*
			 * When we get an error, we strdup it here.  When the main thread
			 * checks for errors, it makes a palloc copy of this, and frees
			 * this.
			 */
			char	   *error_message = strdup(PQerrorMessage((PGconn *)entryConn));
			if (!error_message)
			{
				ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY),
								errmsg("QDMirroringUpdate: out of memory")));
			}

			destroyPQExpBuffer(entryBuffer);
			PQfinish((PGconn *)entryConn);
			entryConn = NULL;
			elog(FATAL, "QDMirroringUpdate: setting segDB state failed, error connecting to entry db, error: %s", error_message);
		}

		/* finally, we're ready to actually get some stuff done. */

		do
		{
			rs = PQexec((PGconn *)entryConn, "BEGIN");
			if (PQresultStatus((PGresult *)rs) != PGRES_COMMAND_OK)
				break;

			if ((updateMask & QDMIRROR_UPDATEMASK_VALIDFLAG) != 0)
			{
				count = snprintf(cmd, sizeof(cmd), UPDATE_VALIDFLAG_CMD, (validFlag ? 't' : 'f'), ftsQDMirrorInfo->dbid);
				if (count >= sizeof(cmd))
				{
					ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
									errmsg("QDMirroringUpdate: format command string failure")));
				}

				rs = PQexec((PGconn *)entryConn, cmd);
				if (PQresultStatus((PGresult *)rs) != PGRES_COMMAND_OK)
				{
					ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
									errmsg("QDMirroringUpdate: could not execute command '%s'", cmd)));
					break;
				}
			}

			if ((updateMask & QDMIRROR_UPDATEMASK_MASTERMIRRORING)!= 0)
			{
				switch (state)
				{
					case QDMIRROR_STATE_NONE:
						summaryStateString = "None";
						break;

					case QDMIRROR_STATE_NOTCONFIGURED:
						summaryStateString = "Not Configured";
						break;

					case QDMIRROR_STATE_CONNECTINGWALSENDSERVER:
					case QDMIRROR_STATE_POSITIONINGTOEND:
					case QDMIRROR_STATE_CATCHUPPENDING:
					case QDMIRROR_STATE_CATCHINGUP:
						summaryStateString = "Synchronizing";
						break;

					case QDMIRROR_STATE_SYNCHRONIZED:
						summaryStateString = "Synchronized";
						break;

					case QDMIRROR_STATE_DISABLED:
						summaryStateString = "Not Synchronized";
						break;

					default:
						summaryStateString = "Unknown";
						break;
				}

				if (state == QDMIRROR_STATE_DISABLED)
				{
					detailStateString =
						QDMirroringDisabledReasonToString(disabledReason);
				}
				else
				{
					detailStateString = NULL;
				}

				if (detailStateString == NULL)
				{
					strcpy(detailValue, "null");
				}
				else
				{
					count = snprintf(detailValue, sizeof(detailValue), "'%s'", detailStateString);
					if (count >= sizeof(detailValue))
					{
						ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
										errmsg("QDMirroringUpdate: format command string failure")));
					}
				}

				QDMirroringFormatTime(logTimeStr, sizeof(logTimeStr), lastLogTimeVal);

				/*
				 * Escape quote the error string before putting in DML statement...
				 */
				if (errorMessage != NULL)
				{
					int errorMessageLen = strlen(errorMessage);

					if (errorMessageLen == 0)
					{
						strcpy(errorMessageQuoted, "null");
					}
					else
					{
						size_t escapedLen;

						errorMessageQuoted[0] = '\'';
						escapedLen = PQescapeString(&errorMessageQuoted[1], errorMessage, errorMessageLen);
						errorMessageQuoted[escapedLen + 1] = '\'';
						errorMessageQuoted[escapedLen + 2] = '\0';

						elog((Debug_print_qd_mirroring ? LOG : DEBUG5), "Error message quoted: \"%s\"", errorMessageQuoted);
					}
				}
				else
				{
					strcpy(errorMessageQuoted, "null");
				}
				count = snprintf(cmd, sizeof(cmd), UPDATE_MASTER_MIRRORING_CMD,
								 summaryStateString, detailValue, logTimeStr, errorMessageQuoted);

				if (count >= sizeof(cmd))
				{
					ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
									errmsg("QDMirroringUpdate: format command string failure")));
				}

				rs = PQexec((PGconn *)entryConn, cmd);
				if (PQresultStatus((PGresult *)rs) != PGRES_COMMAND_OK)
				{
					ereport(ERROR,
							(errcode(ERRCODE_INTERNAL_ERROR),
							 errmsg("QDMirroringUpdate: could not execute command '%s'", cmd)));
					break;
				}

				elog((Debug_print_qd_mirroring ? LOG : DEBUG5),
					 "Successfully executed command \"%s\"", cmd);

				rs = PQexec((PGconn *)entryConn, "COMMIT");
				if (PQresultStatus((PGresult *)rs) != PGRES_COMMAND_OK)
					break;
			}
		}
		while (0);

		PQclear((PGresult *)rs);
		PQfinish((PGconn *)entryConn);
		destroyPQExpBuffer(entryBuffer);

		CommitTransactionCommand();
	}
	PG_CATCH();
	{
		PQclear((PGresult *)rs);
		PQfinish((PGconn *)entryConn);
		destroyPQExpBuffer(entryBuffer);

		AbortCurrentTransaction();
	}
	PG_END_TRY();

	MemoryContextSwitchTo(mcxt); /* Just incase we hit an error */
	return;
}