diff --git a/application/ChatCommand.cpp b/application/ChatCommand.cpp index 117e346..088b992 100644 --- a/application/ChatCommand.cpp +++ b/application/ChatCommand.cpp @@ -23,6 +23,46 @@ ChatCommand::ChatCommand(const char* name, BMessage msg, bool toProtocol, } +ChatCommand::ChatCommand(BMessage* data) + : BArchivable(data) +{ + data->FindString("_name", &fName); + data->FindString("_desc", &fDescription); + data->FindBool("_proto", &fToProto); + data->FindMessage("_msg", &fMessage); + + int32 argType, i = 0; + while (data->FindInt32("_argtype", i, &argType) == B_OK) { + fArgTypes.AddItem(argType); + i++; + } +} + + +status_t +ChatCommand::Archive(BMessage* data, bool deep) +{ + status_t ret = BArchivable::Archive(data, deep); + data->AddString("_name", fName); + data->AddString("_desc", fDescription); + data->AddBool("_proto", fToProto); + data->AddMessage("_msg", new BMessage(fMessage)); + + for (int i = 0; i < fArgTypes.CountItems(); i++) + data->AddInt32("_argtype", fArgTypes.ItemAt(i)); + return ret; +} + + +ChatCommand* +ChatCommand::Instantiate(BMessage* data) +{ + if (!validate_instantiation(data, "ChatCommand")) + return NULL; + return new ChatCommand(data); +} + + void ChatCommand::SetDesc(const char* description) { diff --git a/application/ChatCommand.h b/application/ChatCommand.h index b1e9b58..fa7f206 100644 --- a/application/ChatCommand.h +++ b/application/ChatCommand.h @@ -5,6 +5,7 @@ #ifndef CHAT_COMMAND_H #define CHAT_COMMAND_H +#include #include #include @@ -23,10 +24,15 @@ enum cmd_arg_type }; -class ChatCommand { +class ChatCommand : public BArchivable { public: ChatCommand(const char* name, BMessage msg, bool toProtocol, List argTypes); + ChatCommand(BMessage* data); + + status_t Archive(BMessage* data, bool deep=true); + ChatCommand* Instantiate(BMessage* data); + const char* GetName() { return fName.String(); }