//------------------------------------------------------------------------------ TimeTag TimeTag::getCurrentTime() { uint32_t retSeconds; uint32_t retFraction; #ifdef WIN32 _timeb currentTime; _ftime_s(¤tTime); //2208988800 = Num. seconds from 1900 to 1970, where _ftime starts from. retSeconds = 2208988800 + static_cast<uint32_t>(currentTime.time); //Correct for timezone. retSeconds -= static_cast<uint32_t>(60 * currentTime.timezone); //Correct for daylight savings time. if(currentTime.dstflag) retSeconds += static_cast<uint32_t>(3600); retFraction = static_cast<uint32_t>(currentTime.millitm); //Fill up all 32 bits... retFraction *= static_cast<uint32_t>(static_cast<float>(1<<31)/1000000.0f); #else retSeconds = 0; retFraction = 0; #endif return TimeTag(retSeconds, retFraction); }
void NSFTraceLog::addTrace(const NSFString& type, const NSFString& tag1, const NSFString& data1, const NSFString& tag2, const NSFString& data2, const NSFString& tag3, const NSFString& data3) { // If logging is not enabled, then return without action if (!enabled) { return; } NSFXMLElement* trace = NULL; try { // Lock to prevent events from being added to the queue with timestamps out of order LOCK(traceLogMutex) { // Create the new trace element trace = new NSFXMLElement(TraceTag()); // Add the time trace->addChildElementBack(new NSFXMLElement(TimeTag(), toString(NSFTimerThread::getPrimaryTimerThread().getCurrentTime()))); // Add a trace for the type NSFXMLElement* typeTrace = new NSFXMLElement(type); trace->addChildElementBack(typeTrace); // Add the new data under the type element; typeTrace->addChildElementBack(new NSFXMLElement(tag1, data1)); if (!tag2.empty()) typeTrace->addChildElementBack(new NSFXMLElement(tag2, data2)); if (!tag3.empty()) typeTrace->addChildElementBack(new NSFXMLElement(tag3, data3)); eventHandler.queueEvent(traceAddEvent.copy(true, trace)); } ENDLOCK; } catch(...) { // If unable to add a trace, just do nothing, because calling the exception handler may result in an infinite loop delete trace; } }
void OpenFile() { //std::cout << "LogManager try to open file to " << sLogFileName << std::endl; if (logFile.is_open()) { logFile << "Change to log file: "<< sLogFileName<< std::endl; TimeTag(); EndFile(); logFile.close(); } //First attempt to create the log file. std::ostringstream filename; filename << "results/logs/" << theApp->getStartTimeString() << "-eventLog"; if (mSide == RED) { filename << "Red"; } else if (mSide == BLUE) { filename << "Blue"; } filename << ".txt"; logFile.open(filename.str().c_str()); //logFile.open(sLogFileName); if (!logFile.is_open()) { std::cout << "could not open file \""<<filename.str()<<"\"" << std::endl; return; } else { //std::cout << "Using file \"delta3d_log.html\" for logging" << std::endl; } //TimeTag(); //logFile << std::endl; logFile.flush(); //std::cout.flush(); }
void test3() { int bufferSize = 1000; char *buffer = AllocateAligned4( bufferSize ); // single message tests // empty message { std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/no_arguments" ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n";\ } TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool ); #ifndef _OBJC_OBJC_H_ TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil ); #endif TEST_PACK_UNPACK0( "/nil", OscNil, true, IsNil ); TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum ); TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 ); TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat ); TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar ); TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor ); TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage ); TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 ); TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag ); TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble ); // blob { char blobData[] = "abcd"; std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/a_blob" ) << Blob( blobData, 4 ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; const void *value; osc_bundle_element_size_t size; m.ArgumentsBegin()->AsBlob( value, size ); assertEqual( size, (osc_bundle_element_size_t)4 ); assertEqual( (memcmp( value, blobData, 4 ) == 0), true ); } // array { int32 arrayData[] = {1,2,3,4}; const std::size_t sourceArrayItemCount = 4; std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/an_array" ) << BeginArray; for( std::size_t j=0; j < sourceArrayItemCount; ++j ) ps << arrayData[j]; ps << EndArray << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; ReceivedMessageArgumentIterator i = m.ArgumentsBegin(); assertEqual( i->IsArrayBegin(), true ); assertEqual( i->ComputeArrayItemCount(), sourceArrayItemCount ); std::size_t arrayItemCount = i->ComputeArrayItemCount(); ++i; // move past array begin marker for( std::size_t j=0; j < arrayItemCount; ++j ){ assertEqual( true, i->IsInt32() ); int32 k = i->AsInt32(); assertEqual( k, arrayData[j] ); ++i; } assertEqual( i->IsArrayEnd(), true ); } TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString ); TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol ); // nested bundles, and multiple messages in bundles... { std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginBundle() << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage << EndBundle; assertEqual( ps.IsReady(), true ); ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << b << "\n"; } }
void test3() { int bufferSize = 1000; char *buffer = AllocateAligned4( bufferSize ); // single message tests // empty message { memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/no_arguments" ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n";\ } TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool ); TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil ); TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum ); TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 ); TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat ); TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar ); TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor ); TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage ); TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 ); TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag ); TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble ); // blob { char blobData[] = "abcd"; memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/a_blob" ) << Blob( blobData, 4 ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; const void *value; unsigned long size; m.ArgumentsBegin()->AsBlob( value, size ); assertEqual( size, (unsigned long)4 ); assertEqual( (memcmp( value, blobData, 4 ) == 0), true ); } TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString ); TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol ); // nested bundles, and multiple messages in bundles... { memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginBundle() << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage << EndBundle; assertEqual( ps.IsReady(), true ); ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << b << "\n"; } }