NameService - a key (null-terminated string)/value (pointer/int) store

Started by Maqs, April 07, 2014, 01:21:08 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Maqs

Hello,

the "NameService" is used by different parts of the firmware. One well-known place for this would be register_function/call.

register_function calls NameService_Lookup to check whether a function is already registered or not. If it's registered, it frees the memory used by the old entry and allocates new memory. At the end, NameService_Register is called to register the new function.
unregister_function calls NameService_Lookup and NameService_Unregister in that order. Besides the calls to the callback function, call(..) only calls NameService_Lookup.

None of the NameService functions deal with allocating or freeing memory for the stored data.

Below, you will find a quick overview over the structures and a few functions I found, some of them untested.

struct NameServiceEntry
{
    struct NameServiceEntry *next;
    void *data;
    char Name[];
};

struct NameService
{
    char *aNameService;
    int number_of_entries;
    int semaphore;
    int hash_table_size;
    void *ptr1;   // ptr to ptr1
    void *ptr2;   // ptr to ptr2
    struct NameServiceEntry *hash_table[hash_table_size];
};

// name will be used for the named semaphore created, can be zero if create_semaphore is 0
// if create_semaphore, creates (and uses) a semaphore
struct NameService *NameService_Create(char *name, int hash_table_size, int create_semaphore);

// Free NameService structures (not the data!).
// 0 on success
int NameService_Destroy(struct NameService *n);

// (Over)Write named entry.
// Will overwrite existing entries silently without free()ing it! Use NameService_Lookup first and free data.
// 0 on success
int NameService_Register(struct NameService *n, char *name, void *data);

// Remove named entry.
// 0 on success
int NameService_Unregister(struct NameService *n, char *name);

// Lookup named entry.
// 0 on success
int NameService_Lookup(struct NameService *n, char *name, void **data);     // 0 on success, data points to entry

// Calls callback for each NameService entry. This is useful for freeing all the data.
// 0 on success
int NameService_ForEach(struct NameService *n, void (*callback)(char *name, void *data, void *priv), void *priv);

// 0 if n is a NameService
int NameService_IsInstance(struct NameService *n);

// Internal hash function used by NameService.
int NameService_HashFunction(char *name);


Stubs for 6D.113:
FF32CD20 NameService_Create
FF32D304 NameService_Destroy
FF32D114 NameService_Register
FF32D124 NameService_Unregister
FF32D2EC NameService_Lookup
FF32D480 NameService_IsInstance
FF32D554 NameService_ForEach
FF32D5F4 NameService_HashFunction

g3gg0

Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

nanomad

Most of Canon high level code has a C++ feeling, with this being the first parameter. I don't think it's actual C++ though
EOS 1100D | EOS 650 (No, I didn't forget the D) | Ye Olde Canon EF Lenses ('87): 50 f/1.8 - 28 f/2.8 - 70-210 f/4 | EF-S 18-55 f/3.5-5.6 | Metz 36 AF-5