示例#1
0
void BETABRITE::WriteStringFile ( const char Name, const char *Contents )
{
	BeginCommand ( );
	BeginNestedCommand ( );
	WriteStringFileNested ( Name, Contents );
	EndCommand ( );
}
示例#2
0
void BETABRITE::WriteTextFile ( const char Name, const char *Contents, const char initColor, const char Position, const char Mode, const char Special )
{
	BeginCommand ( );
	BeginNestedCommand ( );
	WriteTextFileNested ( Name, Contents, initColor, Position, Mode, Special );
	EndCommand ( );
}
示例#3
0
void BETABRITE::CancelPriorityTextFile ( void )
{
	BeginCommand ( );
	BeginNestedCommand ( );
	print ( BB_CC_WTEXT );
	print ( BB_PRIORITY_FILE_LABEL );
	EndCommand ( );
}
示例#4
0
void DisplayCopyRect(uint8_t x,
                     uint8_t y,
                     uint8_t w,
                     uint8_t h,
                     Rgb565 const * data) {
  BeginWriteWindow(x, y, x+w-1, y+h-1);
  SpiWriteBuffer(data, w * h);
  EndCommand();
}
示例#5
0
void DisplayFillRect(uint8_t x,
                     uint8_t y,
                     uint8_t w,
                     uint8_t h,
                     Rgb565 color) {
  BeginWriteWindow(x, y, x+w-1, y+h-1);
  SpiWriteRepeatedValue(color, w * h);
  EndCommand();
}
示例#6
0
文件: walsender.c 项目: xiul/postgres
/*
 * IDENTIFY_SYSTEM
 */
static void
IdentifySystem(void)
{
	StringInfoData buf;
	char		sysid[32];
	char		tli[11];

	/*
	 * Reply with a result set with one row, two columns. First col is system
	 * ID, and second is timeline ID
	 */

	snprintf(sysid, sizeof(sysid), UINT64_FORMAT,
			 GetSystemIdentifier());
	snprintf(tli, sizeof(tli), "%u", ThisTimeLineID);

	/* Send a RowDescription message */
	pq_beginmessage(&buf, 'T');
	pq_sendint(&buf, 2, 2);		/* 2 fields */

	/* first field */
	pq_sendstring(&buf, "systemid");	/* col name */
	pq_sendint(&buf, 0, 4);		/* table oid */
	pq_sendint(&buf, 0, 2);		/* attnum */
	pq_sendint(&buf, TEXTOID, 4);		/* type oid */
	pq_sendint(&buf, -1, 2);	/* typlen */
	pq_sendint(&buf, 0, 4);		/* typmod */
	pq_sendint(&buf, 0, 2);		/* format code */

	/* second field */
	pq_sendstring(&buf, "timeline");	/* col name */
	pq_sendint(&buf, 0, 4);		/* table oid */
	pq_sendint(&buf, 0, 2);		/* attnum */
	pq_sendint(&buf, INT4OID, 4);		/* type oid */
	pq_sendint(&buf, 4, 2);		/* typlen */
	pq_sendint(&buf, 0, 4);		/* typmod */
	pq_sendint(&buf, 0, 2);		/* format code */
	pq_endmessage(&buf);

	/* Send a DataRow message */
	pq_beginmessage(&buf, 'D');
	pq_sendint(&buf, 2, 2);		/* # of columns */
	pq_sendint(&buf, strlen(sysid), 4); /* col1 len */
	pq_sendbytes(&buf, (char *) &sysid, strlen(sysid));
	pq_sendint(&buf, strlen(tli), 4);	/* col2 len */
	pq_sendbytes(&buf, (char *) tli, strlen(tli));
	pq_endmessage(&buf);

	/* Send CommandComplete and ReadyForQuery messages */
	EndCommand("SELECT", DestRemote);
	ReadyForQuery(DestRemote);
	/* ReadyForQuery did pq_flush for us */
}
示例#7
0
void DisplayCopyRectFrag(uint8_t x,
                         uint8_t y,
                         uint8_t w,
                         uint8_t h,
                         uint8_t stride,
                         Rgb565 const * data) {
  BeginWriteWindow(x, y, x+w-1, y+h-1);
  for (uint8_t i = 0; i < h; ++i) {
    SpiWriteBuffer(data, w);
    data += stride;
  }
  EndCommand();
}
示例#8
0
static void WriteCommand(uint8_t cmd, unsigned argc, ...) {
  va_list args;
  va_start(args, argc);

  BeginCommand(cmd);
  ExpectReceive(argc);
  while (argc--) {
    SpiWriteByteAsync(va_arg(args, uint8_t));
  }
  SpinTransferComplete();
  EndCommand(cmd);

  va_end(args);
}
//-----------------------------------------------------------------
void tStreamReceiveFile::ProcessError(QDataStream &)
{

    enabled=false;
    int num_error=1;
    QString error="Error in command 1";
    QString detail="File name: "+file_name+"\nFile size: "+QString::number(file_size);

    QString client_detail="Ошибка на стороне клиента \n"+error_reason;

    QByteArray block;
    QDataStream in(&block, QIODevice::WriteOnly);

    in << tr("Error");
    in << num_error;
    in << error;
    in << detail;
    in << client_detail;

    emit Result(block);
    emit EndCommand();

}
示例#10
0
void BETABRITE::SetMemoryConfiguration ( const char startingFile, unsigned int numFiles, unsigned int size )
{
  BeginCommand ( );  
  BeginNestedCommand ( );
  print ( BB_CC_WSPFUNC );
  print ( BB_SFL_CLEARMEM );

  char sizeBuf[5] = "0100";
  if (size <= 0xffff)
  {
    sprintf(sizeBuf, "%04x", size);
  }

  for (char c = startingFile; c <  startingFile + numFiles; c++)
  {
    print ( c );
    print ( BB_SFFT_TEXT );
    print ( BB_SFKPS_LOCKED );
    print ( sizeBuf );
    print ( "FF00" );    // AlwaysOn for text file
  }
  
  EndCommand ( );
}
//-----------------------------------------------------------------
bool tStreamReceiveFile::ExeCommand(QDataStream& _in)
{
    bool ret=false;



    qint64 n=_in.device()->bytesAvailable();
    char* buff= new char[n];
    qint64 num=_in.device()->read(buff, n);
    read_size=read_size+n;

    if(enabled)
    {
        if(!error_detected)
        {
            file.write(buff, num);
        }

        QByteArray data(buff, n);
        calc_hash->AddToHash(data);

        delete[] buff;
        if(read_size==file_size)
        {

            ret=true;
            qDebug() << "File transfer complete";

            QByteArray block;
            QDataStream out(&block, QIODevice::WriteOnly);
            out.setVersion(QDataStream::Qt_4_8);

            QString file_name=file.fileName();
            qint64 file_size=file.size();
            QString command="ReceiveReport";

            file.close();

            bool error_detected1=!SetAttributeFile(file_name, hidden, create_date_time, last_modified, permission, hash);

            if(!error_detected1 && !error_detected)
            {
                out << command;
                out << file_name;
                out << file_size;

                emit Result(block);
                emit EndCommand();
            }
            else
            {
                ProcessError(out);
            }
        }
    }
    else
    {
        delete[] buff;
        ret=true;
        if(read_size==file_size)
        {
            emit EndCommand();
        }
    }
    return ret;
}
void IpcServerProxy::end()
{
    writeCommandBlock.write(QVariant::fromValue(EndCommand()));
}
示例#13
0
void BETABRITE::SetDateTime ( DateTime now, bool UseMilitaryTime )
{
	char		dow, strbuff[3];
	uint8_t		hour, minute, month, day;
	uint16_t	year;

	dow = now.dayOfWeek ( );
	dow += '1';
	hour = now.hour ( );
	minute = now.minute ( );
	month = now.month ( );
	day = now.day ( );
	year = now.year ( );

	BeginCommand ( );
	BeginNestedCommand ( );
	DelayBetweenCommands ( );
	print ( BB_CC_WSPFUNC );
	print ( ' ' );
	if ( hour <= 9 )
	{
		print ( '0' );
	}
	itoa ( hour, strbuff, 10 );
	print ( strbuff );
	if ( minute <= 9 )
	{
		print ( '0' );
	}
	itoa ( minute, strbuff, 10 );
	print ( strbuff );
	EndNestedCommand ( );
	BeginNestedCommand ( );
	DelayBetweenCommands ( );
	print ( BB_CC_WSPFUNC );
	print ( '\047' );
	print ( UseMilitaryTime ? 'M' : 'S' );
	EndNestedCommand ( );
	BeginNestedCommand ( );
	DelayBetweenCommands ( );
	print ( BB_CC_WSPFUNC );
	print ( '&' );
	print ( dow );
	EndNestedCommand ( );
	BeginNestedCommand ( );
	DelayBetweenCommands ( );
	print ( BB_CC_WSPFUNC );
	print ( ';' );
	if ( month <= 9 )
	{
		print ( '0' );
	}
	itoa ( month, strbuff, 10 );
	print ( strbuff );
	if ( day <= 9 )
	{
		print ( '0' );
	}
	itoa ( day, strbuff, 10 );
	print ( strbuff );
	if ( year < 2000 ) print ( "00" );
	else
	{
		year -= 2000;
		if ( year <= 9 )
		{
			print ( '0' );
		}
		itoa ( year, strbuff, 10 ); // 2 digits for the foreseeable future, and positive
		print ( strbuff );
	}
	EndNestedCommand ( );
	EndCommand ( );
}
示例#14
0
void idev_AbortIO(IDBase *IDBase, struct IORequest *ioreq)
{
	EndCommand(IOERR_ABORTED, (struct IOStdReq*)ioreq, SysBase);
}
示例#15
0
/*
 * IDENTIFY_SYSTEM
 */
static void
IdentifySystem(void)
{
	StringInfoData buf;
	char		sysid[32];
	char		tli[11];
	char		xpos[MAXFNAMELEN];
	XLogRecPtr	logptr;

	/*
	 * Reply with a result set with one row, three columns. First col is
	 * system ID, second is timeline ID, and third is current xlog location.
	 */

	snprintf(sysid, sizeof(sysid), UINT64_FORMAT,
			 GetSystemIdentifier());
	snprintf(tli, sizeof(tli), "%u", ThisTimeLineID);

	logptr = am_cascading_walsender ? GetStandbyFlushRecPtr() : GetInsertRecPtr();

	snprintf(xpos, sizeof(xpos), "%X/%X",
			 logptr.xlogid, logptr.xrecoff);

	/* Send a RowDescription message */
	pq_beginmessage(&buf, 'T');
	pq_sendint(&buf, 3, 2);		/* 3 fields */

	/* first field */
	pq_sendstring(&buf, "systemid");	/* col name */
	pq_sendint(&buf, 0, 4);		/* table oid */
	pq_sendint(&buf, 0, 2);		/* attnum */
	pq_sendint(&buf, TEXTOID, 4);		/* type oid */
	pq_sendint(&buf, -1, 2);	/* typlen */
	pq_sendint(&buf, 0, 4);		/* typmod */
	pq_sendint(&buf, 0, 2);		/* format code */

	/* second field */
	pq_sendstring(&buf, "timeline");	/* col name */
	pq_sendint(&buf, 0, 4);		/* table oid */
	pq_sendint(&buf, 0, 2);		/* attnum */
	pq_sendint(&buf, INT4OID, 4);		/* type oid */
	pq_sendint(&buf, 4, 2);		/* typlen */
	pq_sendint(&buf, 0, 4);		/* typmod */
	pq_sendint(&buf, 0, 2);		/* format code */

	/* third field */
	pq_sendstring(&buf, "xlogpos");
	pq_sendint(&buf, 0, 4);
	pq_sendint(&buf, 0, 2);
	pq_sendint(&buf, TEXTOID, 4);
	pq_sendint(&buf, -1, 2);
	pq_sendint(&buf, 0, 4);
	pq_sendint(&buf, 0, 2);
	pq_endmessage(&buf);

	/* Send a DataRow message */
	pq_beginmessage(&buf, 'D');
	pq_sendint(&buf, 3, 2);		/* # of columns */
	pq_sendint(&buf, strlen(sysid), 4); /* col1 len */
	pq_sendbytes(&buf, (char *) &sysid, strlen(sysid));
	pq_sendint(&buf, strlen(tli), 4);	/* col2 len */
	pq_sendbytes(&buf, (char *) tli, strlen(tli));
	pq_sendint(&buf, strlen(xpos), 4);	/* col3 len */
	pq_sendbytes(&buf, (char *) xpos, strlen(xpos));

	pq_endmessage(&buf);

	/* Send CommandComplete and ReadyForQuery messages */
	EndCommand("SELECT", DestRemote);
	ReadyForQuery(DestRemote);
	/* ReadyForQuery did pq_flush for us */
}
示例#16
0
/*
 * Execute an incoming replication command.
 */
static bool
HandleReplicationCommand(const char *cmd_string)
{
	bool		replication_started = false;
	int			parse_rc;
	Node	   *cmd_node;
	MemoryContext cmd_context;
	MemoryContext old_context;

	elog(DEBUG1, "received replication command: %s", cmd_string);

	cmd_context = AllocSetContextCreate(CurrentMemoryContext,
										"Replication command context",
										ALLOCSET_DEFAULT_MINSIZE,
										ALLOCSET_DEFAULT_INITSIZE,
										ALLOCSET_DEFAULT_MAXSIZE);
	old_context = MemoryContextSwitchTo(cmd_context);

	replication_scanner_init(cmd_string);
	parse_rc = replication_yyparse();
	if (parse_rc != 0)
		ereport(ERROR,
				(errcode(ERRCODE_SYNTAX_ERROR),
				 (errmsg_internal("replication command parser returned %d",
								  parse_rc))));

	cmd_node = replication_parse_result;

	switch (cmd_node->type)
	{
		case T_IdentifySystemCmd:
			IdentifySystem();
			break;

		case T_StartReplicationCmd:
			StartReplication((StartReplicationCmd *) cmd_node);

			/* break out of the loop */
			replication_started = true;
			break;

		case T_BaseBackupCmd:
			SendBaseBackup((BaseBackupCmd *) cmd_node);

			/* Send CommandComplete and ReadyForQuery messages */
			EndCommand("SELECT", DestRemote);
			ReadyForQuery(DestRemote);
			/* ReadyForQuery did pq_flush for us */
			break;

		default:
			ereport(FATAL,
					(errcode(ERRCODE_PROTOCOL_VIOLATION),
					 errmsg("invalid standby query string: %s", cmd_string)));
	}

	/* done */
	MemoryContextSwitchTo(old_context);
	MemoryContextDelete(cmd_context);

	return replication_started;
}
示例#17
0
/*
 * Execute commands from walreceiver, until we enter streaming mode.
 */
static void
WalSndHandshake(void)
{
	StringInfoData input_message;
	bool		replication_started = false;

	initStringInfo(&input_message);

	while (!replication_started)
	{
		int			firstchar;

		/* Wait for a command to arrive */
		firstchar = pq_getbyte();

		/*
		 * Emergency bailout if postmaster has died.  This is to avoid the
		 * necessity for manual cleanup of all postmaster children.
		 */
		if (!PostmasterIsAlive(true))
			exit(1);

		/*
		 * Check for any other interesting events that happened while we
		 * slept.
		 */
		if (got_SIGHUP)
		{
			got_SIGHUP = false;
			ProcessConfigFile(PGC_SIGHUP);
		}

		if (firstchar != EOF)
		{
			/*
			 * Read the message contents. This is expected to be done without
			 * blocking because we've been able to get message type code.
			 */
			if (pq_getmessage(&input_message, 0))
				firstchar = EOF;	/* suitable message already logged */
		}

		/* Handle the very limited subset of commands expected in this phase */
		switch (firstchar)
		{
			case 'Q':			/* Query message */
				{
					const char *query_string;
					XLogRecPtr	recptr;

					query_string = pq_getmsgstring(&input_message);
					pq_getmsgend(&input_message);

					if (strcmp(query_string, "IDENTIFY_SYSTEM") == 0)
					{
						StringInfoData buf;
						char		sysid[32];
						char		tli[11];

						/*
						 * Reply with a result set with one row, two columns.
						 * First col is system ID, and second is timeline ID
						 */

						snprintf(sysid, sizeof(sysid), UINT64_FORMAT,
								 GetSystemIdentifier());
						snprintf(tli, sizeof(tli), "%u", ThisTimeLineID);

						/* Send a RowDescription message */
						pq_beginmessage(&buf, 'T');
						pq_sendint(&buf, 2, 2); /* 2 fields */

						/* first field */
						pq_sendstring(&buf, "systemid");		/* col name */
						pq_sendint(&buf, 0, 4); /* table oid */
						pq_sendint(&buf, 0, 2); /* attnum */
						pq_sendint(&buf, TEXTOID, 4);	/* type oid */
						pq_sendint(&buf, -1, 2);		/* typlen */
						pq_sendint(&buf, 0, 4); /* typmod */
						pq_sendint(&buf, 0, 2); /* format code */

						/* second field */
						pq_sendstring(&buf, "timeline");		/* col name */
						pq_sendint(&buf, 0, 4); /* table oid */
						pq_sendint(&buf, 0, 2); /* attnum */
						pq_sendint(&buf, INT4OID, 4);	/* type oid */
						pq_sendint(&buf, 4, 2); /* typlen */
						pq_sendint(&buf, 0, 4); /* typmod */
						pq_sendint(&buf, 0, 2); /* format code */
						pq_endmessage(&buf);

						/* Send a DataRow message */
						pq_beginmessage(&buf, 'D');
						pq_sendint(&buf, 2, 2); /* # of columns */
						pq_sendint(&buf, strlen(sysid), 4);		/* col1 len */
						pq_sendbytes(&buf, (char *) &sysid, strlen(sysid));
						pq_sendint(&buf, strlen(tli), 4);		/* col2 len */
						pq_sendbytes(&buf, (char *) tli, strlen(tli));
						pq_endmessage(&buf);

						/* Send CommandComplete and ReadyForQuery messages */
						EndCommand("SELECT", DestRemote);
						ReadyForQuery(DestRemote);
						/* ReadyForQuery did pq_flush for us */
					}
					else if (sscanf(query_string, "START_REPLICATION %X/%X",
									&recptr.xlogid, &recptr.xrecoff) == 2)
					{
						StringInfoData buf;

						/*
						 * Check that we're logging enough information in the
						 * WAL for log-shipping.
						 *
						 * NOTE: This only checks the current value of
						 * wal_level. Even if the current setting is not
						 * 'minimal', there can be old WAL in the pg_xlog
						 * directory that was created with 'minimal'. So this
						 * is not bulletproof, the purpose is just to give a
						 * user-friendly error message that hints how to
						 * configure the system correctly.
						 */
						if (wal_level == WAL_LEVEL_MINIMAL)
							ereport(FATAL,
									(errcode(ERRCODE_CANNOT_CONNECT_NOW),
									 errmsg("standby connections not allowed because wal_level=minimal")));

						/* Send a CopyOutResponse message, and start streaming */
						pq_beginmessage(&buf, 'H');
						pq_sendbyte(&buf, 0);
						pq_sendint(&buf, 0, 2);
						pq_endmessage(&buf);
						pq_flush();

						/*
						 * Initialize position to the received one, then the
						 * xlog records begin to be shipped from that position
						 */
						sentPtr = recptr;

						/* break out of the loop */
						replication_started = true;
					}
					else
					{
						ereport(FATAL,
								(errcode(ERRCODE_PROTOCOL_VIOLATION),
								 errmsg("invalid standby query string: %s", query_string)));
					}
					break;
				}

			case 'X':
				/* standby is closing the connection */
				proc_exit(0);

			case EOF:
				/* standby disconnected unexpectedly */
				ereport(COMMERROR,
						(errcode(ERRCODE_PROTOCOL_VIOLATION),
						 errmsg("unexpected EOF on standby connection")));
				proc_exit(0);

			default:
				ereport(FATAL,
						(errcode(ERRCODE_PROTOCOL_VIOLATION),
						 errmsg("invalid standby handshake message type %d", firstchar)));
		}
	}
}