|
-
January 16th, 2011, 07:49 PM
#1
Distributed enums
Hello, it's nice to be back 
I have a distributed system consisting of many processes, and I am designing a mechanism by which they can all send messages to a "monitor" process.
Each message consists of a code identifying the type of message, and a string containing the message contents. There are many types of messages (several for each type of process, and there are many types of processes). The purpose of encoding the message type in a code is so that the monitor can filter out certain types of messages and only show the rest.
My problem is where to declare the codes corresponding to the message types. Obviously I want them to be symbolic constants, not magic numbers, so an enumeration comes to mind. However, I don't want to have one central enumeration for all the message types, because I don't want to introduce gratuitous compile-time dependencies (since every component will include the header file that declares this enumeration, the build system will force all the components to be recompiled when I add a new message type for a new component).
So I'm trying to find a way to "distribute", i.e. spread out the enumeration so there's one piece for each component, and each component only needs its own piece. The obvious problem is how to come up with numerical starting values for the pieces, so that the numerical values of the symbols from different components do not overlap.
I can:
1) Assign the starting values manually. I don't want to do this because there are many components and it would be a maintenance headache.
2) Have a pre-build step that generates and assigns these starting values. I don't want to do this either because it would complicate the build process unnecessarily.
3) Automatically assign unique starting values at compile-time somehow. I'm trying to figure out a way to do this. Basically, I need to be able to generate a number that is unique to each file. I thought of trying to compute a compile-time hash of __FILE__, but that doesn't work (besides the fact that compile-time hashing is not even really possible without C++0x, there are multiple instances of each component that may be compiled on different machines, and __FILE__ may evaluate to a different string on different machines).
Any ideas about how I might be able to create such a "distributed enumeration"? I am open to new approaches to my original problem as well.
Old Unix programmers never die, they just mv to /dev/null
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|