mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 03:19:24 +01:00
Simplifly data registry and reserve 0...1000 as client range
This commit is contained in:
parent
6b4014dfca
commit
56c4742f75
@ -976,7 +976,6 @@ bool Network::AppendScreenshot(NetworkUpdatePeerInfo *pi)
|
||||
NetworkUpdateRegisterData *dsu;
|
||||
NetworkUpdate *ud;
|
||||
SDL_Surface *scr;
|
||||
struct ds_data *data;
|
||||
void *png;
|
||||
size_t sz;
|
||||
bool out = NULL;
|
||||
@ -989,20 +988,15 @@ bool Network::AppendScreenshot(NetworkUpdatePeerInfo *pi)
|
||||
if (!png)
|
||||
goto out_scr;
|
||||
|
||||
data = DataStore::ds->embedData(png, sz);
|
||||
if (!data)
|
||||
goto out_png;
|
||||
ud = InitNetworkUpdate(this->ud, REGISTER_DATA,
|
||||
sizeof(NetworkUpdate) + sizeof(NetworkUpdateRegisterData) + sz);
|
||||
dsu = (NetworkUpdateRegisterData *)ud->data;
|
||||
dsu->key = data->key;
|
||||
dsu->metadata = data->metadata;
|
||||
memcpy(dsu->data, data->data, sz);
|
||||
dsu->key = DataStore::ds->getNextKey();
|
||||
dsu->metadata = 0;
|
||||
memcpy(dsu->data, png, sz);
|
||||
this->AddNetworkUpdate(ud);
|
||||
|
||||
out = true;
|
||||
free(data);
|
||||
out_png:
|
||||
free(png);
|
||||
out_scr:
|
||||
SDL_FreeSurface(scr);
|
||||
|
@ -68,20 +68,14 @@ struct ds_data *DataStore::registerData(uint32_t key,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct ds_data *DataStore::embedData(void *data, size_t sz)
|
||||
uint32_t DataStore::getNextKey()
|
||||
{
|
||||
struct ds_data *out;
|
||||
uint32_t out = this->key_counter;
|
||||
|
||||
out = (struct ds_data *)xmalloc(sizeof(struct ds_data) + sz);
|
||||
this->key_counter += 2;
|
||||
|
||||
out->key = this->key_counter;
|
||||
out->metadata = 0; /* Setup by the embedder */
|
||||
memcpy(out->data, data, sz);
|
||||
|
||||
panic_if(this->registerData(out->key, out) != NULL,
|
||||
"Registering new data with key %u was non-NULL\n",
|
||||
out->key);
|
||||
out->key += 2;
|
||||
if (this->key_counter > DATA_KEY_RANGE)
|
||||
this->key_counter = 1;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define DATA_KEY_RANGE 1000
|
||||
|
||||
struct ds_data
|
||||
{
|
||||
uint32_t key;
|
||||
@ -20,28 +22,24 @@ public:
|
||||
~DataStore();
|
||||
|
||||
/**
|
||||
* Register a new datum.
|
||||
* Register a new datum from the network.
|
||||
*
|
||||
* @param key The key to register with
|
||||
* @param metadata The metadata
|
||||
* @param data The data to register
|
||||
* @param data_sz The size of the data
|
||||
*
|
||||
* @return the old datum with that key, or NULL
|
||||
*/
|
||||
struct ds_data *registerData(uint32_t key, struct ds_data *data);
|
||||
|
||||
struct ds_data *registerNetworkData(uint32_t key, uint32_t metadata,
|
||||
void *data, size_t data_sz);
|
||||
|
||||
/**
|
||||
* Embed existing data into a data store. The new data is reallocated,
|
||||
* but the old is not freed
|
||||
* Get the next key for registered data
|
||||
*
|
||||
* @param data The data to embed.
|
||||
* @param sz the size of the data
|
||||
*
|
||||
* @return the new data store data.
|
||||
* @return a valid key
|
||||
*/
|
||||
struct ds_data *embedData(void *data, size_t sz);
|
||||
uint32_t getNextKey();
|
||||
|
||||
/**
|
||||
* Unregister a datum.
|
||||
@ -57,6 +55,8 @@ public:
|
||||
static DataStore *ds;
|
||||
|
||||
private:
|
||||
struct ds_data *registerData(uint32_t key, struct ds_data *data);
|
||||
|
||||
struct ds_data **registeredData;
|
||||
int n_registeredData;
|
||||
|
||||
|
@ -467,7 +467,7 @@ class Broker(SocketServer.UDPServer):
|
||||
self.stat_data = stat_data
|
||||
self.image_dir = image_dir
|
||||
|
||||
self.data_key = 0
|
||||
self.data_key = DATA_KEY_RANGE
|
||||
|
||||
stats.load(self.stat_data)
|
||||
try:
|
||||
@ -479,6 +479,9 @@ class Broker(SocketServer.UDPServer):
|
||||
def get_data_key(self):
|
||||
out = self.data_key
|
||||
self.data_key = (self.data_key + DATA_KEY_RANGE) & 0xffffffff
|
||||
# Start at DATA_KEY_RANGE
|
||||
if self.data_key < DATA_KEY_RANGE:
|
||||
self.data_key = self.data_key + DATA_KEY_RANGE
|
||||
|
||||
return out
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user