2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maksym Mamontov <stg@madf.info>
21 #ifndef __UR_FUNCTOR_H__
22 #define __UR_FUNCTOR_H__
26 #include "stg/os_int.h"
27 #include "stg/common.h"
36 class UpdateRouter : public std::unary_function<std::pair<const uint32_t, RS::USER>, void>
39 explicit UpdateRouter(REMOTE_SCRIPT & t)
42 void operator() (std::pair<const uint32_t, USER> & val)
44 std::vector<uint32_t> newRouters = obj.IP2Routers(val.second.ip);
45 std::vector<uint32_t>::const_iterator oldIt(val.second.routers.begin());
46 std::vector<uint32_t>::const_iterator newIt(newRouters.begin());
47 val.second.shortPacketsCount = 0;
48 while (oldIt != val.second.routers.end() ||
49 newIt != newRouters.end())
51 if (oldIt == val.second.routers.end())
53 if (newIt != newRouters.end())
55 obj.SendDirect(val.second, *newIt); // Connect on new router
59 else if (newIt == newRouters.end())
61 obj.SendDirect(val.second, *oldIt, true); // Disconnect on old router
64 else if (*oldIt < *newIt)
66 obj.SendDirect(val.second, *oldIt, true); // Disconnect on old router
69 else if (*oldIt > *newIt)
71 obj.SendDirect(val.second, *newIt); // Connect on new router
77 if (newIt != newRouters.end())
81 val.second.routers = newRouters;