// Search for an existing Proxy that matches the pointer to // member and replace it's Call, or create a new Proxy for it. // void ListenersBase::updatep (void const* const member, const size_t bytes, Call::Ptr cp) { Call* c = cp; ReadWriteMutex::ScopedReadLockType lock (m_groups_mutex); if (!m_groups.empty ()) { Proxy* proxy; { ReadWriteMutex::ScopedReadLockType lock (m_proxies_mutex); // See if there's already a proxy proxy = find_proxy (member, bytes); } // Possibly create one if (!proxy) { ReadWriteMutex::ScopedWriteLockType lock (m_proxies_mutex); // Have to search for it again in case someone else added it proxy = find_proxy (member, bytes); if (!proxy) { // Create a new empty proxy proxy = new (m_allocator) Proxy (member, bytes); // Add all current groups to the Proxy. // We need the group read lock for this (caller provided). for (Groups::iterator iter = m_groups.begin(); iter != m_groups.end();) { Group* group = &(*iter++); proxy->add (group, *m_allocator); } // Add it to the list. m_proxies.push_front (*proxy); } } // Requires the group read lock proxy->update (c, m_timestamp); } }
static uint64_t proxy_timestamp (const char *path) { ProtobufCService *rpc_client; Apteryx__Get get = APTERYX__GET__INIT; uint64_t value = 0; cb_info_t *proxy = NULL; /* Find and connect to a proxied instance */ rpc_client = find_proxy (&path, &proxy); if (!rpc_client) return 0; /* Do remote timestamp */ get.path = (char *) path; apteryx__server__timestamp (rpc_client, &get, handle_timestamp_response, &value); if (!value) { INC_COUNTER (counters.proxied_timeout); ERROR ("No response from proxy for path \"%s\"\n", (char *)path); rpc_client_release (rpc, rpc_client, false); return value; } rpc_client_release (rpc, rpc_client, true); return value; }
static int proxy_prune (const char *path) { ProtobufCService *rpc_client; Apteryx__Prune prune = APTERYX__PRUNE__INIT; protobuf_c_boolean is_done = 0; cb_info_t *proxy = NULL; /* Find and connect to a proxied instance */ rpc_client = find_proxy (&path, &proxy); if (!rpc_client) return false; /* Do remote prune */ prune.path = (char *) path; apteryx__server__prune (rpc_client, &prune, handle_ok_response, &is_done); if (!is_done) { ERROR ("PROXY PRUNE: No response\n"); rpc_client_release (rpc, rpc_client, false); return false; } rpc_client_release (rpc, rpc_client, true); return true; }
static char * proxy_get (const char *path) { ProtobufCService *rpc_client; Apteryx__Get get = APTERYX__GET__INIT; get_data_t data = {0}; cb_info_t *proxy = NULL; char *value = NULL; /* Find and connect to a proxied instance */ rpc_client = find_proxy (&path, &proxy); if (!rpc_client) return NULL; /* Do remote get */ get.path = (char *) path; apteryx__server__get (rpc_client, &get, handle_get_response, &data); if (!data.done) { INC_COUNTER (counters.proxied_timeout); ERROR ("No response from proxy for path \"%s\"\n", (char *)path); rpc_client_release (rpc, rpc_client, false); } else { rpc_client_release (rpc, rpc_client, true); value = data.value; } return value; }
// find the proxy's data model and set up new proxy object // *** to be implemented *** void WebThings::register_proxy(const char *uri, ThingFunc setup) { Proxy *proxy = find_proxy(uri); if (!proxy) { proxy = new Proxy(); } }
struct proxy_l* add_proxy(str* name, unsigned short port, int proto) { struct proxy_l* p; if ((p=find_proxy(name, port, proto))!=0) return p; if ((p=mk_proxy(name, port, proto))==0) goto error; /* add p to the proxy list */ p->next=proxies; proxies=p; return p; error: return 0; }
bool Command::handle_reply_message(const Url &url, const Value &val) { if (url.path() == REPLY_PATH) { RootProxy *proxy = find_proxy(url.location()); if (proxy) { if (val.size() < 2 || !val[0].is_string()) { std::cerr << "Bad argument to " << REPLY_PATH << " :" << val << "\n"; return true; } proxy->handle_reply(val[0].str(), val[1]); } else { // std::cerr << "Could not handle reply from '" << url.location() << "' (no proxy for this location).\n"; } return true; } else { return false; } }
static GList * proxy_search (const char *path) { const char *in_path = path; ProtobufCService *rpc_client; Apteryx__Search search = APTERYX__SEARCH__INIT; search_data_t data = {0}; cb_info_t *proxy = NULL; /* Find and connect to a proxied instance */ rpc_client = find_proxy (&path, &proxy); if (!rpc_client) return NULL; /* Do remote search */ search.path = (char *) path; apteryx__server__search (rpc_client, &search, handle_search_response, &data); if (!data.done) { INC_COUNTER (counters.proxied_timeout); ERROR ("No response from proxy for path \"%s\"\n", (char *)path); rpc_client_release (rpc, rpc_client, false); } else { rpc_client_release (rpc, rpc_client, true); /* Prepend local path to start of all search results */ size_t path_len = path - in_path; char *local_path = g_malloc0 (path_len + 1); strncpy (local_path, in_path, path_len); GList *itr = data.paths; for (; itr; itr = itr->next) { char *tmp = g_strdup_printf ("%s%s", local_path, (char *)itr->data); g_free (itr->data); itr->data = tmp; } g_free (local_path); } return data.paths; }
static GList * proxy_traverse (const char *path) { const char *in_path = path; ProtobufCService *rpc_client; Apteryx__Traverse traverse = APTERYX__TRAVERSE__INIT; traverse_data_t data = {0}; cb_info_t *proxy = NULL; /* Find and connect to a proxied instance */ rpc_client = find_proxy (&path, &proxy); if (!rpc_client) return NULL; /* Do remote traverse */ traverse.path = (char *) path; data.path = path; apteryx__server__traverse (rpc_client, &traverse, handle_traverse_response, &data); if (!data.done) { INC_COUNTER (counters.proxied_timeout); ERROR ("No response from proxy for path \"%s\"\n", (char *)path); rpc_client_release (rpc, rpc_client, false); } else { DEBUG ("TRAVERSE: %s (proxies as %s)\n", in_path, path); rpc_client_release (rpc, rpc_client, true); /* Prepend full path to start of all search results */ GList *itr = data.paths; for (; itr; itr = itr->next) { Apteryx__PathValue *pv = (Apteryx__PathValue *) itr->data; char *tmp = g_strconcat (in_path, pv->path, NULL); g_free (pv->path); pv->path = tmp; } } return data.paths; }
static int proxy_set (const char *path, const char *value, uint64_t ts) { ProtobufCService *rpc_client; Apteryx__Set set = APTERYX__SET__INIT; Apteryx__PathValue _pv = APTERYX__PATH_VALUE__INIT; Apteryx__PathValue *pv[1] = {&_pv}; int result = 1; cb_info_t *proxy = NULL; /* Find and connect to a proxied instance */ rpc_client = find_proxy (&path, &proxy); if (!rpc_client) { /* A positive value is interpreted as proxy not found */ return 1; } /* Do remote set */ pv[0]->path = (char *) path; pv[0]->value = (char *) value; set.n_sets = 1; set.sets = pv; set.ts = ts; apteryx__server__set (rpc_client, &set, handle_set_response, &result); if (result == -ETIMEDOUT) { /* We got no response. Kill the socket. */ ERROR ("PROXY SET: No response\n"); rpc_client_release (rpc, rpc_client, false); } else { /* We got some response */ if (result != 0) DEBUG ("PROXY SET: Error response: %s\n", strerror (-result)); rpc_client_release (rpc, rpc_client, true); } return result; }
/* * Main entry point for MPI parallel debugger. * * @arg --debugger=type select backend debugger * @arg --debugger_path=path set backend debugger path * @arg --port=port port number to listen on/connect to * @arg --host=host host to connect to * @arg --proxy=proxy_type type of proxy connection to use * @arg --master master process * @arg --server=id server process with rank 'id' */ int main(int argc, char *argv[]) { int ch; int port = PTP_PROXY_TCP_PORT; char * host = NULL; char * debugger_str = DEFAULT_BACKEND; char * proxy_str = DEFAULT_PROXY; char * path = NULL; proxy * p; dbg_backend * d; #ifdef _AIX int n; char * cp; #endif #ifndef _AIX while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { if (ch == 0) { switch (opt_type) { case OPT_TYPE_DEBUGGER: debugger_str = optarg; break; case OPT_TYPE_DEBUGGER_PATH: path = optarg; break; case OPT_TYPE_PROXY: proxy_str = optarg; break; case OPT_TYPE_PORT: port = (int)strtol(optarg, NULL, 10); break; case OPT_TYPE_HOST: host = optarg; break; case OPT_TYPE_MASTER: case OPT_TYPE_SERVER: break; #ifdef DEBUG case OPT_TYPE_DEBUG: if (optarg == NULL) debug_level = DEBUG_LEVEL_ALL; else debug_level = (int)strtol(optarg, NULL, 10); break; #endif /* DEBUG */ } } else { fprintf(stderr, "sdm [--debugger=value] [--debugger_path=path]\n" " [--proxy=proxy]\n" " [--host=host_name] [--port=port]\n" " [--master]\n" " [--server=rank]\n" #ifdef DEBUG " [--debug[=level]]\n" #endif /* DEBUG */ ); return 1; } } #else /* * AIX does not support GNU style getopt with long options. * Parse options by string comparison instead. */ n = 1; while (n < argc) { cp = strchr(argv[n], '='); if (cp == NULL) { if (strcmp(argv[n], "--master") == 0 || strncmp(argv[n], "--server", 8) == 0) { /* No action required */ #ifdef DEBUG } else if (strcmp(argv[n], "--debug") == 0) { debug_level = DEBUG_LEVEL_ALL; #endif } else { fprintf(stderr, "sdm [--debugger=value] [--debugger_path=path]\n" " [--proxy=proxy]\n" " [--host=host_name] [--port=port]\n" " [--master]\n" " [--server=rank]\n" #ifdef DEBUG " [--debug[=level]]\n" #endif /* DEBUG */ ); return 1; } } else { *cp = '\0'; if (strncmp(argv[n], "--debugger", 10) == 0) { debugger_str = strdup(cp + 1); } else if (strncmp(argv[n], "--debugger_path", 15) == 0) { path = strdup(cp + 1); } else if (strncmp(argv[n], "--proxy", 7) == 0) { proxy_str = strdup(cp + 1); } else if (strncmp(argv[n], "--port", 6) == 0) { port = (int) strtol(cp + 1, NULL, 10); } else if (strncmp(argv[n], "--host", 6) == 0) { host = strdup(cp + 1); } #ifdef DEBUG else if (strncmp(argv[n], "--debug", 7) == 0) { debug_level = (int) strtol(cp + 1, NULL, 10); } #endif else { fprintf(stderr, "sdm [--debugger=value] [--debugger_path=path]\n" " [--proxy=proxy]\n" " [--host=host_name] [--port=port]\n" " [--master]\n" " [--server=rank]\n" #ifdef DEBUG " [--debug[=level]]\n" #endif /* DEBUG */ ); return 1; } } n = n + 1; } #endif if (find_dbg_backend(debugger_str, &d) < 0) { fprintf(stderr, "No such backend: \"%s\"\n", debugger_str); return 1; } if (path != NULL) { backend_set_path(d, path); } if (find_proxy(proxy_str, &p) < 0) { fprintf(stderr,"No such proxy: \"%s\"\n", proxy_str); return 1; } if (sdm_init(argc, argv) < 0) { DEBUG_PRINTS(DEBUG_LEVEL_STARTUP, "sdm_init failed\n"); return 1; } if (sdm_route_get_id() == SDM_MASTER) { DEBUG_PRINTS(DEBUG_LEVEL_STARTUP, "starting client\n"); master(proxy_str, host, port); } else { DEBUG_PRINTF(DEBUG_LEVEL_STARTUP, "starting task %d\n", sdm_route_get_id()); server(d); } DEBUG_PRINTS(DEBUG_LEVEL_STARTUP, "all finished\n"); sdm_finalize(); return 0; }