// Setup a root node to use in all succeeding
examples. Pass in an invalid BMessenger, since for
// this example we don't care about getting
any reply BMessages back from the root node...
BLooper * root = SHCreateRootNode(BMessenger());
root->Run();
[...]
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
msg.AddString(SH_NAME_TO, "/");
msg.AddFlat(SH_NAME_CHILDREN, &SHNodeSpec("Joe",
"somecomputer.beos.com", 2958));
root->PostMessage(&msg);
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
root->PostMessage(&msg);
TestWorker test; // TestWorker
is a hypothetical user-defined subclass of SHWorker
BMessage testArchive;
test.Archive(&testArchive);
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
msg.AddString(SH_NAME_TO, "/Joe");
msg.AddMessage(SH_NAME_COMPONENTS, &testArchive);
root->PostMessage(&msg);
CustomSorter sort; // CustomSorter
is a hypothetical user-defined subclass of SHSorter
BMessage sortArchive;
sort.Archive(&sortAchive);
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
msg.AddString(SH_NAME_TO, "/Joe");
msg.AddMessage(SH_NAME_COMPONENTS, &sortArchive);
root->PostMessage(&msg);
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
msg.AddString(SH_NAME_TO, "/Joe");
SHFileSpec spec;
if (spec.addFlavor(SHFlavor("mydata.bin")) ==
B_NO_ERROR)
{
msg.AddFlat(SH_NAME_FILES,
&spec);
root->PostMessage(&msg);
}
else printf("Error adding flavor--file missing?\n");
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
msg.AddString(SH_NAME_TO, "/Joe");
msg.AddString(SH_NAME_SYMLINKS, "/Bob");
root->PostMessage(&msg);
Fancy Examples of how to use SH_COMMAND_ADDCOMPONENTS
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
msg.AddString(SH_NAME_TO, "/Joe");
// Give Joe three children, on three other computers...
msg.AddFlat(SH_NAME_CHILDREN, &SHNodeSpec("JoesChild1",
"anothercomputer1.beos.com"));
msg.AddFlat(SH_NAME_CHILDREN, &SHNodeSpec("JoesChild2",
"anothercomputer2.beos.com"));
msg.AddFlat(SH_NAME_CHILDREN, &SHNodeSpec("JoesChild3",
"anothercomputer3.beos.com"));
// And give him a few more TestWorkers...
TestWorker testWorker;
BMessage testMsg;
testWorker.Archive(&testMsg);
msg.AddMessage(SH_NAME_COMPONENTS, &testMsg);
// Joe gets
msg.AddMessage(SH_NAME_COMPONENTS, &testMsg);
// three instances of
msg.AddMessage(SH_NAME_COMPONENTS, &testMsg);
// the TestWorker!
// And give Joe some additional files, as well.
SHFileSpec spec;
spec.AddFlavor(SHFlavor("moredata1.bin"));
spec.AddFlavor(SHFlavor("moredata2.bin"));
spec.AddFlavor(SHFlavor("moredata3.bin"));
msg.AddFlat(SH_NAME_FILES, &spec);
// Send it all off
root->PostMessage(&msg);
BMessage msg(SH_COMMAND_ADDCOMPONENTS);
// Note that I DON'T specify SH_NAME_TO for
this one. Not specifying SH_NAME_TO creates
// a "broadcast" message that will be received
by EVERY node in the tree!
// Specify files based on system type, via SHFileSpec::AddFlavor().
SHFileSpec spec;
if (spec.AddFlavor(SHFlavor("ImportantFile.powerpc",
SH_ARCH_BEOS_PPC)) != B_NO_ERROR)
printf("Warning:
ImportantFile.powerpc doesn't exist on the root node! It won't be
cached...\n");
if (spec.AddFlavor(SHFlavor("ImportantFile.intel",
SH_ARCH_BEOS_X86)) != B_NO_ERROR)
printf("Warning:
ImportantFile.intel doesn't exist on the root node! It won't be cached...\n");
msg.AddFlat(SH_NAME_FILES, &spec);
// Send it off
root->PostMessage(&msg);