Exemple #1
0
void ServerDescription::serialize(BinaryOutput& b) const {
    b.writeString(serverName);
    applicationAddress.serialize(b);
    b.writeString(applicationName);
    b.writeInt32(maxClients);
    b.writeInt32(currentClients);
    b.writeString(data);
}
Exemple #2
0
void UniversalBSDF::speedSerialize(BinaryOutput& b) const {
    SpeedLoad::writeHeader(b, "UniversalBSDF");

    m_lambertian.speedSerialize(b);
    m_glossy.speedSerialize(b);
    m_transmissive.speedSerialize(b);
    b.writeFloat32(m_eta_t);
    m_extinction_t.serialize(b);
    b.writeFloat32(m_eta_r);
    m_extinction_r.serialize(b);
}
Exemple #3
0
void LightweightConduit::sendBuffer(const NetAddress& a, BinaryOutput& b) {
    NetworkDevice* nd = NetworkDevice::instance();
    if (sendto(sock, (const char*)b.getCArray(), (int)b.size(), 0,
       (struct sockaddr *) &(a.addr), sizeof(a.addr)) == SOCKET_ERROR) {
        Log::common()->printf("Error occured while sending packet "
                             "to %s\n", inet_ntoa(a.addr.sin_addr));
        Log::common()->println(socketErrorCode());
        nd->closesocket(sock);
    } else {
        ++mSent;
        bSent += b.size();
    }
}
Exemple #4
0
void LightweightConduit::sendBuffer(const NetAddress& a, BinaryOutput& b) {
    if (sendto(sock, (const char*)b.getCArray(), b.size(), 0,
       (struct sockaddr *) &(a.addr), sizeof(a.addr)) == SOCKET_ERROR) {
        if (nd->debugLog) {
            nd->debugLog->printf("Error occured while sending packet "
                                 "to %s\n", inet_ntoa(a.addr.sin_addr));
            nd->debugLog->println(socketErrorCode());
        }
        nd->closesocket(sock);
    } else {
        ++mSent;
        bSent += b.size();
    }
}
Exemple #5
0
    virtual bool onEvent(const GEvent& e) override {
        if (GApp::onEvent(e)) {
            return true;
        }

        switch (e.type) {
        case GEventType::GUI_ACTION:
            if (e.gui.control == m_connectToAddressBox) {
                connectToServer(m_connectToAddress);
                m_connectToAddress = "";
                return true;
            } else {
                // Send a text message to the other machine
                shared_ptr<Conversation> conversation = findConversation(e.gui.control);
                if (notNull(conversation)) {
                    BinaryOutput bo;
                    bo.writeString32(conversation->textToSend);
                    conversation->connection->send(TEXT, bo);
                    conversation->textToSend = "";
                    return true;
                }
            }
            break;

        case GEventType::GUI_CLOSE:
            {
                // Shut down the associated network connection by letting 
                // the Conversation's destructor execute
                for (int i = 0; i < m_conversationArray.size(); ++i) {
                    if (m_conversationArray[i]->window.get() == e.guiClose.window) {
                        m_conversationArray.fastRemove(i);
                        break; // Leave the FOR loop
                    }
                } // for
            }
            break;

        case GEventType::QUIT:
            m_conversationArray.clear();
            m_server->stop();
            m_server.reset();
            break;
        } //switch

        return false;
    } // onEvent
Exemple #6
0
void ReliableConduit::sendBuffer(const BinaryOutput& b) {
    NetworkDevice* nd = NetworkDevice::instance();
    int ret = ::send(sock, (const char*)b.getCArray(), (int)b.size(), 0);
    
    if (ret == SOCKET_ERROR) {
        Log::common()->println("Error occured while sending message.");
        Log::common()->println(socketErrorCode());
        nd->closesocket(sock);
        return;
    }

    ++mSent;
    bSent += b.size();

    // Verify the packet was actually sent
    // Conversion to unsigned is safe because -1 is caught earlier
    debugAssert(ret == b.size());
}
// same as for the setpoint
CommandStatus SlaveDemoApp::HandleControl(BinaryOutput& aControl, size_t aIndex)
{
	LOG_BLOCK(LEV_EVENT, "Received BINARY " << aControl.ToString() << " on index: " << aIndex);

	// set the binary to ON if the command  code was LATCH_ON, otherwise set it off (LATCH_OFF)
	apl::Binary b(aControl.GetCode() == CC_LATCH_ON, BQ_ONLINE);
	b.SetToNow();

	// count how many BinaryOutput commands we recieve
	apl::Counter c(++mCountBinaryOutput, CQ_ONLINE);
	c.SetToNow();

	Transaction t(mpObserver);
	mpObserver->Update(b, aIndex);
	mpObserver->Update(c, 1); 

	return CS_SUCCESS;
}
CommandStatus CommandResponder :: HandleControl(const BinaryOutput& aControl, size_t aIndex)
{
	CommandStatus cs = CS_TOO_MANY_OPS;
	if ( mLinkStatuses && (aControl.GetCode() == CC_LATCH_ON || aControl.GetCode() == CC_LATCH_OFF)) {
		try {
			Transaction t(mpObs);
			bool val = aControl.GetCode() == CC_LATCH_ON ? true : false;
			mpObs->Update(ControlStatus(val, ControlStatus::ONLINE), aIndex);
			cs = CS_SUCCESS;
			LOG_BLOCK(LEV_INFO, "Updated ControlStatus " << aIndex << " with " << val << "." );
		}
		catch (Exception& ex) {
			LOG_BLOCK(LEV_WARNING, "Failure trying to update point in response to control. " << ex.GetErrorString());
			cs = CS_FORMAT_ERROR;
		}
	}
	else {
		cs = GetResponseCode(true, aIndex);
	}
	LOG_BLOCK(LEV_INFO, "[" << aIndex << "] - " <<  aControl.ToString() << " returning " << ToString(cs));
	return cs;
}
Exemple #9
0
	template<class T> inline
	std::enable_if_t<std::is_arithmetic<T>::value, void>
    save(BinaryOutput & a, T const & t)
	{
		a.save_Data(std::addressof(t), sizeof(t));
	}
Exemple #10
0
void GImage::encodeJPEG(
    BinaryOutput&           out) const {

	if (channels != 3) {
		// Convert to three channel
		GImage tmp = *this;
		tmp.convertToRGB();
		tmp.encodeJPEG(out);
		return;
	}

    debugAssert(channels == 3);
    out.setEndian(G3D_LITTLE_ENDIAN);

    // Allocate and initialize a compression object
    jpeg_compress_struct    cinfo;
    jpeg_error_mgr          jerr;

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_compress(&cinfo);

    // Specify the destination for the compressed data.
    // (Overestimate the size)
    int buffer_size = width * height * 3 + 200;
    JOCTET* compressed_data = (JOCTET*)System::malloc(buffer_size);
	jpeg_memory_dest(&cinfo, compressed_data, buffer_size);


    cinfo.image_width       = width;
    cinfo.image_height      = height;

	// # of color components per pixel
    cinfo.input_components  = 3;

    // colorspace of input image
    cinfo.in_color_space    = JCS_RGB; 
    cinfo.input_gamma       = 1.0;
    
    // Set parameters for compression, including image size & colorspace
    jpeg_set_defaults(&cinfo);
    jpeg_set_quality(&cinfo, jpegQuality, false);
    cinfo.smoothing_factor = 0;
    cinfo.optimize_coding = TRUE;
//    cinfo.dct_method = JDCT_FLOAT;
    cinfo.dct_method = JDCT_ISLOW;
    cinfo.jpeg_color_space = JCS_YCbCr;

    // Initialize the compressor
    jpeg_start_compress(&cinfo, TRUE);

    // Iterate over all scanlines from top to bottom
	// pointer to a single row
    JSAMPROW row_pointer[1];
    
    // JSAMPLEs per row in image_buffer
    int row_stride = cinfo.image_width * 3;
    while (cinfo.next_scanline < cinfo.image_height) {
	    row_pointer[0] = &(_byte[cinfo.next_scanline * row_stride]);
	    jpeg_write_scanlines(&cinfo, row_pointer, 1);
    }

    // Shut down the compressor
    jpeg_finish_compress(&cinfo);
    
    // Figure out how big the result was.
    int outLength = ((mem_dest_ptr)cinfo.dest)->count;

    //	Release the JPEG compression object
    jpeg_destroy_compress(&cinfo);

    // Copy into an appropriately sized output buffer.
    out.writeBytes(compressed_data, outLength);

    // Free the conservative buffer.
    System::free(compressed_data);
    compressed_data = NULL;
}
Exemple #11
0
void Vector2::serialize(BinaryOutput& b) const {
    b.writeFloat32(x);
    b.writeFloat32(y);
}
Exemple #12
0
void writeHeader(BinaryOutput& b, const String& header) {
    debugAssertM(header.size() < HEADER_LENGTH, "This header string is too long");
    b.writeString(header, SpeedLoad::HEADER_LENGTH);
}
Exemple #13
0
void Color1::serialize(BinaryOutput& bo) const {
    bo.writeFloat32(value);
}
	void serialize(BinaryOutput& b) const {
		b.writeInt32(i32);
		b.writeInt64(i64);
		b.writeString(s);
		b.writeFloat32(f);
	}
Exemple #15
0
 void sendMyName(shared_ptr<NetSendConnection> connection) const {
     BinaryOutput bo;
     bo.writeString32(m_name);
     connection->send(CHANGE_NAME, bo);
 }
Exemple #16
0
void GImage::encodeTGA(
    BinaryOutput&       out) const {

    out.setEndian(G3D_LITTLE_ENDIAN);

    // ID length
    out.writeUInt8(0);

    // Color map Type
    out.writeUInt8(0);

    // Type
    out.writeUInt8(2);

    // Color map
    out.skip(5);

    // x, y offsets
    out.writeUInt16(0);
    out.writeUInt16(0);

    // Width & height
    out.writeUInt16(m_width);
    out.writeUInt16(m_height);

    // Color depth
    if (m_channels == 1) {
        // Force RGB mode
        out.writeUInt8(8 * 3);
    } else {
        out.writeUInt8(8 * m_channels);
    }

    // Image descriptor
    if (m_channels < 4) {
        // 0 alpha bits
        out.writeUInt8(0);
    } else {
        // 8 alpha bits
        out.writeUInt8(8);
    }

    // Image ID (zero length)

    if (m_channels == 1) {
        // Pixels are upside down in BGR format.
        for (int y = m_height - 1; y >= 0; --y) {
            for (int x = 0; x < m_width; ++x) {
                uint8 p = (m_byte[(y * m_width + x)]);
                out.writeUInt8(p);
                out.writeUInt8(p);
                out.writeUInt8(p);
            }
        }
    } else if (m_channels == 3) {
        // Pixels are upside down in BGR format.
        for (int y = m_height - 1; y >= 0; --y) {
            for (int x = 0; x < m_width; ++x) {
                uint8* p = &(m_byte[3 * (y * m_width + x)]);
                out.writeUInt8(p[2]);
                out.writeUInt8(p[1]);
                out.writeUInt8(p[0]);
            }
        }
    } else {
        // Pixels are upside down in BGRA format.
        for (int y = m_height - 1; y >= 0; --y) {
            for (int x = 0; x < m_width; ++x) {
                uint8* p = &(m_byte[4 * (y * m_width + x)]);
                out.writeUInt8(p[2]);
                out.writeUInt8(p[1]);
                out.writeUInt8(p[0]);
                out.writeUInt8(p[3]);
            }
        }
    }

    // Write "TRUEVISION-XFILE " 18 bytes from the end
    // (with null termination)
    out.writeString("TRUEVISION-XFILE ");
}