static int TryExec(int argc, char *argv[]) { string name(argv[1]); if (commands.find(name) == commands.end()) { std::cerr << "Invalid command " << name << "!" << std::endl; return EXIT_FAILURE; } ICmd *cmd = commands[name]; if (!cmd->ValidArgs(argc - 2, argv + 2)) { Usage(cmd->GetName().c_str()); return EXIT_FAILURE; } CurrentCmd = cmd; // in case client closes pipe we are writing to in the protobuf code (void)RegisterSignal(SIGPIPE, SIG_IGN); (void)RegisterSignal(SIGINT, SigInt); (void)RegisterSignal(SIGTERM, SigInt); int ret = cmd->Execute(argc - 2, argv + 2); if (cmd->GotSignal()) return -cmd->InterruptedSignal; else return ret; }
int TCommandHandler::TryExec(const std::string &commandName, const std::vector<std::string> &commandArgs) { const auto it = Commands.find(commandName); if (it == Commands.end()) { std::cerr << "Invalid command " << commandName << "!" << std::endl; return EXIT_FAILURE; } ICmd *cmd = it->second.get(); PORTO_ASSERT(cmd); if (!cmd->ValidArgs(commandArgs)) { Usage(cmd->GetName().c_str()); return EXIT_FAILURE; } CurrentCmd = cmd; // in case client closes pipe we are writing to in the protobuf code (void)RegisterSignal(SIGPIPE, SIG_IGN); (void)RegisterSignal(SIGINT, SigInt); (void)RegisterSignal(SIGTERM, SigInt); TCommandEnviroment commandEnv{*this, commandArgs}; int ret = cmd->Execute(&commandEnv); if (cmd->GotSignal()) return -cmd->InterruptedSignal; else return ret; }
void TCommandHandler::Usage(const char *command) { ICmd *cmd = Commands["help"].get(); PORTO_ASSERT(cmd); std::vector<std::string> args; if (command) args.push_back(command); TCommandEnviroment commandEnv{*this, args}; cmd->Execute(&commandEnv); }
void MgRecordShape::copy(const MgObject& src) { if (src.isKindOf(Type()) && this != &src) { const MgRecordShape& p = (const MgRecordShape&)src; _clear(); for (ITEMS::const_iterator it = p._items.begin(); it != p._items.end(); ++it) { ICmd* item = createItem((*it)->type()); item->copy(**it); _items.push_back(item); } _sid = p._sid; } MgBaseShape::copy(src); }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdDrawPath& p = (const CmdDrawPath&)src; stroke = p.stroke; fill = p.fill; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdQuadTo& p = (const CmdQuadTo&)src; cp = p.cp; pt = p.pt; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdDrawHandle& p = (const CmdDrawHandle&)src; pt = p.pt; t = p.t; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdSetBrush& p = (const CmdSetBrush&)src; argb = p.argb; style = p.style; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdClearRect& p = (const CmdClearRect&)src; pt = p.pt; vec = p.vec; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdDrawLine& p = (const CmdDrawLine&)src; pt1 = p.pt1; pt2 = p.pt2; } }
bool MgRecordShape::load(MgShapeFactory* factory, MgStorage* s) { _clear(); _sid = s->readInt("refid", _sid); for (int i = 0; s->readNode("p", i, false); i++) { ICmd* item = createItem(s->readInt("type", 0)); if (item && item->load(s)) { _items.push_back(item); } else { delete item; } s->readNode("p", i, true); } return _load(factory, s); }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdBezierTo& p = (const CmdBezierTo&)src; c1 = p.c1; c2 = p.c2; pt = p.pt; } }
BOOL CommandManager::Execute( LPCTSTR cmdline, tstring& replyText ) { //分割并整理命令行的各个部分 TStringVector parts; splitByChar(cmdline, parts, ' '); TStringVector::iterator iter = parts.begin(); while (iter != parts.end()) { tstring& part = *iter; trim(part); if (part.size() == 0) { iter = parts.erase(iter); } else { iter++; } } //检查是否有可用的部分 if (parts.size() == 0) { replyText = _T("invalid command."); return FALSE; } //查找可用的命令 tstring& cmdname = parts[0]; makeLower(cmdname); CommandMap::iterator cmdIter = m_cmdMap.find(cmdname); if (cmdIter == m_cmdMap.end()) { replyText = _T("no such command."); return FALSE; } //执行命令 ICmd* pCmd = cmdIter->second; BOOL bExecuteOK = pCmd->Execute(parts, replyText, m_env); return bExecuteOK; }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdDrawEllipse& p = (const CmdDrawEllipse&)src; pt = p.pt; vec = p.vec; stroke = p.stroke; fill = p.fill; } }
void test(int argc, char * argv[]){ auto pm = new PluginManager<ICmd>(); //load const char * cmdName = "print"; const char * dev = "a.img"; const int fatType = 1; auto params = new Parameters(cmdName, dev, fatType); ICmd * cmd = pm->getPlugin(params->getCmdName()); if(cmd != NULL){ cmd->config(params); cmd->execute(); } delete params; delete pm; //unload }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdDrawTextAt& p = (const CmdDrawTextAt&)src; text = p.text; pt = p.pt; vec = p.vec; align = p.align; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdDrawBitmap& p = (const CmdDrawBitmap&)src; name = p.name; pt = p.pt; vec = p.vec; angle = p.angle; } }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdSetPen& p = (const CmdSetPen&)src; argb = p.argb; width = p.width; style = p.style; phase = p.phase; orgw = p.orgw; } }
int TCommandHandler::TryExec(const std::string &commandName, const std::vector<std::string> &commandArgs) { const auto it = Commands.find(commandName); if (it == Commands.end()) { std::cerr << "Invalid command " << commandName << "!" << std::endl; return EXIT_FAILURE; } ICmd *cmd = it->second.get(); PORTO_ASSERT(cmd); if (!cmd->ValidArgs(commandArgs)) { Usage(cmd->GetName().c_str()); return EXIT_FAILURE; } // in case client closes pipe we are writing to in the protobuf code Signal(SIGPIPE, SIG_IGN); TCommandEnviroment commandEnv{*this, commandArgs}; commandEnv.NeedArgs = cmd->NeedArgs; return cmd->Execute(&commandEnv); }
virtual void copy(const ICmd& src) { if (src.type() == type()) { const CmdLineTo& p = (const CmdLineTo&)src; pt = p.pt; } }
static void Usage(const char *command) { ICmd *cmd = commands["help"]; char *argv[] = { (char *)command, NULL }; cmd->Execute(command ? 1 : 0, argv); }