//------------------------------------------------------------------------------ void PortQueue::GetMessagesFromPort(bool wait_for_messages) { if(_init) { PortMessage *msg; ssize_t size; port_info pi; get_port_info(_port, &pi); status_t stat; if(pi.queue_count==0 && wait_for_messages) { size=port_buffer_size(_port); // now that there is a message, we'll just fall through to the // port-emptying loop get_port_info(_port, &pi); } for(int32 i = 0; i < pi.queue_count; i++) { msg = new PortMessage(); stat = msg->ReadFromPort(_port, 0); if(stat != B_OK) { delete msg; break; } _q.push(msg); } } }
// to be used only from a BView or BWindow bool nsToolkit::CallMethodAsync(MethodInfo *info) { #ifdef DEBUG printf("CMA\n"); #endif ThreadInterfaceData id; GetInterface(); id.data = info; id.waitingThread = 0; // Check message count to not exceed the port's capacity. // There seems to be a BeOS bug that allows more // messages on a port than its capacity. port_info portinfo; if (get_port_info(eventport, &portinfo) != B_OK) { return false; } if (port_count(eventport) < portinfo.capacity - 20) { if(write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 0) == B_OK) { return true; } } return false; }
// Synchronous version, not in use at the moment bool nsToolkit::CallMethod(MethodInfo *info) { #ifdef DEBUG printf("TK-CM\n"); #endif ThreadInterfaceData id; GetInterface(); id.data = info; id.waitingThread = find_thread(NULL); // Check message count to not exceed the port's capacity. // There seems to be a BeOS bug that allows more // messages on a port than its capacity. port_info portinfo; if (get_port_info(eventport, &portinfo) != B_OK) { return false; } if (port_count(eventport) < portinfo.capacity - 20) { // If we cannot write inside 5 seconds, something is really wrong. if(write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 5000000) == B_OK) { // semantics for CallMethod are that it should be synchronous suspend_thread(id.waitingThread); return true; } } return false; }
/* * parse_packet6(packet, mp) * * parses the message block into a ipgpc_packet_t structure for IPv6 traffic */ void parse_packet6(ipgpc_packet_t *packet, mblk_t *mp) { ip6_t *ip6h = (ip6_t *)mp->b_rptr; /* parse message block for IP header and ports */ bcopy(ip6h->ip6_src.s6_addr32, packet->saddr.s6_addr32, sizeof (ip6h->ip6_src.s6_addr32)); bcopy(ip6h->ip6_dst.s6_addr32, packet->daddr.s6_addr32, sizeof (ip6h->ip6_dst.s6_addr32)); /* Will be (re-)assigned in get_port_info */ packet->proto = ip6h->ip6_nxt; packet->dsfield = __IPV6_TCLASS_FROM_FLOW(ip6h->ip6_vcf); find_ids(packet, mp); packet->len = msgdsize(mp); packet->sport = 0; packet->dport = 0; /* Need to pullup everything. */ if (mp->b_cont != NULL) { if (!pullupmsg(mp, -1)) { ipgpc0dbg(("parse_packet6(): pullup error, can't " \ "find ports")); return; } ip6h = (ip6_t *)mp->b_rptr; } get_port_info(packet, ip6h, AF_INET6, mp); }
//------------------------------------------------------------------------------ bool PortQueue::SetPort(port_id port) { port_info pi; _init=(get_port_info(port,&pi)==B_OK)?true:false; _port=port; return _init; }
port_id BPrivate::get_launch_daemon_port() { if (sLaunchDaemonPort < 0) { sLaunchDaemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME); port_info info; if (get_port_info(sLaunchDaemonPort, &info) == B_OK && info.team == find_thread(NULL)) { // Make sure that the launch_daemon doesn't wait on itself sLaunchDaemonPort = -1; return -1; } } return sLaunchDaemonPort; }
status_t _user_get_port_info(port_id id, struct port_info *userInfo) { struct port_info info; status_t status; if (userInfo == NULL) return B_BAD_VALUE; if (!IS_USER_ADDRESS(userInfo)) return B_BAD_ADDRESS; status = get_port_info(id, &info); // copy back to user space if (status == B_OK && user_memcpy(userInfo, &info, sizeof(struct port_info)) < B_OK) return B_BAD_ADDRESS; return status; }
/* * parse_packet(packet, mp) * * parses the given message block into a ipgpc_packet_t structure */ void parse_packet(ipgpc_packet_t *packet, mblk_t *mp) { ipha_t *ipha; /* parse message block for IP header and ports */ ipha = (ipha_t *)mp->b_rptr; /* get ip header */ V4_PART_OF_V6(packet->saddr) = (int32_t)ipha->ipha_src; V4_PART_OF_V6(packet->daddr) = (int32_t)ipha->ipha_dst; packet->dsfield = ipha->ipha_type_of_service; packet->proto = ipha->ipha_protocol; packet->sport = 0; packet->dport = 0; find_ids(packet, mp); packet->len = msgdsize(mp); /* parse out TCP/UDP ports, if appropriate */ if ((packet->proto == IPPROTO_TCP) || (packet->proto == IPPROTO_UDP) || (packet->proto == IPPROTO_SCTP)) { get_port_info(packet, ipha, AF_INET, mp); } }
void MediaIcon::_findIconFor( const live_node_info &nodeInfo) { D_INTERNAL(("MediaIcon::_findIconFor(live_node_info)\n")); BMediaRoster *roster = BMediaRoster::CurrentRoster(); if (m_nodeKind & B_FILE_INTERFACE) { entry_ref ref; if ((roster && (roster->GetRefFor(nodeInfo.node, &ref) == B_OK)) && (BNodeInfo::GetTrackerIcon(&ref, this, m_size) == B_OK)) { return; } } dormant_node_info dormantNodeInfo; if (roster && (roster->GetDormantNodeFor(nodeInfo.node, &dormantNodeInfo) == B_OK)) { D_INTERNAL((" -> instantiated from dormant node\n")); _findIconFor(dormantNodeInfo); } else { D_INTERNAL((" -> application internal node\n")); port_info portInfo; app_info appInfo; if ((get_port_info(nodeInfo.node.port, &portInfo) == B_OK) && (be_roster->GetRunningAppInfo(portInfo.team, &appInfo) == B_OK)) { D_INTERNAL((" -> application info found: %s\n", appInfo.signature)); app_info thisAppInfo; if ((be_app->GetAppInfo(&thisAppInfo) != B_OK) || ((strcmp(appInfo.signature, thisAppInfo.signature) != 0) && (strcmp(appInfo.signature, addon_host::g_appSignature) != 0))) { // only use app icon if the node doesn't belong to our team // or the addon-host BNodeInfo::GetTrackerIcon(&appInfo.ref, this, m_size); return; } } bool audioIn = false, audioOut = false, videoIn = false, videoOut = false; _getMediaTypesFor(nodeInfo, &audioIn, &audioOut, &videoIn, &videoOut); _findDefaultIconFor(audioIn, audioOut, videoIn, videoOut); } }
/** * @brief Retrieve state data from device and return them as XML document * * @param model Device data model. libxml2 xmlDocPtr. * @param running Running datastore content. libxml2 xmlDocPtr. * @param[out] err Double pointer to error structure. Fill error when some occurs. * @return State data as libxml2 xmlDocPtr or NULL in case of error. */ xmlDocPtr get_state_data (xmlDocPtr model, xmlDocPtr running, struct nc_err **err) { nc_verb_verbose("get_state_data\n"); nc_verb_verbose("erropt=%u\n", erropt); xmlDocPtr state; xmlNodePtr root; xmlNsPtr ns; state = xmlNewDoc(BAD_CAST "1.0"); root = xmlNewDocNode(state, NULL, BAD_CAST "capable-switch", NULL); xmlDocSetRootElement(state, root); ns = xmlNewNs(root, BAD_CAST "urn:onf:of111:config:yang", NULL); xmlSetNs(root, ns); // state that should be queried here // ### base // #/ofc:capable-switch/ofc:config-version xmlNewChild(root, ns, BAD_CAST "config-version", BAD_CAST "1.1.1"); // // ### configuration points // // ### Resources // xmlNodePtr resources = xmlNewChild(root, NULL, BAD_CAST "resources", NULL); // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:number // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:current-rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:max-rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state/ofc:oper-state // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state/ofc:blocked // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:state/ofc:live // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:auto-negotiate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:medium // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:current/ofc:pause // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:auto-negotiate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:medium // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:supported/ofc:pause // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:rate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:auto-negotiate // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:medium // #/ofc:capable-switch/ofc:resources/ofc:port/ofc:features/ofc:advertised-peer/ofc:pause get_port_info(ofc_state.xmp_client_handle, resources, running); xmlNodePtr lsis = xmlNewChild(root, NULL, BAD_CAST "logical-switches", NULL); // ### LSIs // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:max-buffered-packets // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:max-tables // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:max-ports // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:flow-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:table-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:port-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:queue-statistics // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:reassemble-ip-fragments // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:block-looping-ports // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:reserved-port-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:reserved-port-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-capabilities // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:group-capabilities/ofc:capability // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:action-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:action-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:instruction-types // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:capabilities/ofc:instruction-types/ofc:type // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:connection-state // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:current-version // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:supported-versions // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:local-ip-address-in-use // #/ofc:capable-switch/ofc:logical-switches/ofc:switch/ofc:controllers/ofc:controller/ofc:state/ofc:local-port-in-use get_lsi_info(ofc_state.xmp_client_handle, lsis, running); return state; }
int main(int argc, char **argv) { int mgmt_classes[3] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS }; ib_portid_t portid = { 0 }; int port_op = -1; int is_switch, is_peer_switch, espeed_cap, peer_espeed_cap; int state, physstate, lwe, lws, lwa, lse, lss, lsa, lsee, lses, lsea, fdr10s, fdr10e, fdr10a; int peerlocalportnum, peerlwe, peerlws, peerlwa, peerlse, peerlss, peerlsa, peerlsee, peerlses, peerlsea, peerfdr10s, peerfdr10e, peerfdr10a; int peerwidth, peerspeed, peerespeed; uint8_t data[IB_SMP_DATA_SIZE] = { 0 }; uint8_t data2[IB_SMP_DATA_SIZE] = { 0 }; ib_portid_t peerportid = { 0 }; int portnum = 0; ib_portid_t selfportid = { 0 }; int selfport = 0; int changed = 0; int i; uint32_t vendorid, rem_vendorid; uint16_t devid, rem_devid; uint64_t val; char *endp; char usage_args[] = "<dest dr_path|lid|guid> <portnum> [<op>]\n" "\nSupported ops: enable, disable, on, off, reset, speed, espeed, fdr10,\n" "\twidth, query, down, arm, active, vls, mtu, lid, smlid, lmc,\n" "\tmkey, mkeylease, mkeyprot\n"; const char *usage_examples[] = { "3 1 disable\t\t\t# by lid", "-G 0x2C9000100D051 1 enable\t# by guid", "-D 0 1\t\t\t# (query) by direct route", "3 1 reset\t\t\t# by lid", "3 1 speed 1\t\t\t# by lid", "3 1 width 1\t\t\t# by lid", "-D 0 1 lid 0x1234 arm\t\t# by direct route", NULL }; ibdiag_process_opts(argc, argv, NULL, NULL, NULL, NULL, usage_args, usage_examples); argc -= optind; argv += optind; if (argc < 2) ibdiag_show_usage(); srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 3); if (!srcport) IBEXIT("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port); smp_mkey_set(srcport, ibd_mkey); if (resolve_portid_str(ibd_ca, ibd_ca_port, &portid, argv[0], ibd_dest_type, ibd_sm_id, srcport) < 0) IBEXIT("can't resolve destination port %s", argv[0]); if (argc > 1) portnum = strtol(argv[1], 0, 0); for (i = 2; i < argc; i++) { int j; for (j = 0; j < NPORT_ARGS; j++) { if (strcmp(argv[i], port_args[j].name)) continue; port_args[j].set = 1; if (!port_args[j].val) { if (port_op >= 0) IBEXIT("%s only one of: ", "query, enable, disable, " "reset, down, arm, active, " "can be specified", port_args[j].name); port_op = j; break; } if (++i >= argc) IBEXIT("%s requires an additional parameter", port_args[j].name); val = strtoull(argv[i], 0, 0); switch (j) { case SPEED: if (val > 15) IBEXIT("invalid speed value %ld", val); break; case ESPEED: if (val > 31) IBEXIT("invalid extended speed value %ld", val); break; case FDR10SPEED: if (val > 1) IBEXIT("invalid fdr10 speed value %ld", val); break; case WIDTH: if ((val > 31 && val != 255)) IBEXIT("invalid width value %ld", val); break; case VLS: if (val == 0 || val > 5) IBEXIT("invalid vls value %ld", val); break; case MTU: if (val == 0 || val > 5) IBEXIT("invalid mtu value %ld", val); break; case LID: if (val == 0 || val >= 0xC000) IBEXIT("invalid lid value 0x%lx", val); break; case SMLID: if (val == 0 || val >= 0xC000) IBEXIT("invalid smlid value 0x%lx", val); break; case LMC: if (val > 7) IBEXIT("invalid lmc value %ld", val); break; case MKEY: errno = 0; val = strtoull(argv[i], &endp, 0); if (errno || *endp != '\0') { errno = 0; val = strtoull(getpass("New M_Key: "), &endp, 0); if (errno || *endp != '\0') { IBEXIT("Bad new M_Key\n"); } } /* All 64-bit values are legal */ break; case MKEYLEASE: if (val > 0xFFFF) IBEXIT("invalid mkey lease time %ld", val); break; case MKEYPROT: if (val > 3) IBEXIT("invalid mkey protection bit setting %ld", val); } *port_args[j].val = val; changed = 1; break; } if (j == NPORT_ARGS) IBEXIT("invalid operation: %s", argv[i]); } if (port_op < 0) port_op = QUERY; is_switch = get_node_info(&portid, data); vendorid = (uint32_t) mad_get_field(data, 0, IB_NODE_VENDORID_F); devid = (uint16_t) mad_get_field(data, 0, IB_NODE_DEVID_F); if ((port_args[MKEY].set || port_args[MKEYLEASE].set || port_args[MKEYPROT].set) && is_switch && portnum != 0) IBEXIT("Can't set M_Key fields on switch port != 0"); if (port_op != QUERY || changed) printf("Initial %s PortInfo:\n", is_switch ? "Switch" : "CA/RT"); else printf("%s PortInfo:\n", is_switch ? "Switch" : "CA/RT"); espeed_cap = get_port_info(&portid, data, portnum, is_switch); show_port_info(&portid, data, portnum, espeed_cap, is_switch); if (is_mlnx_ext_port_info_supported(vendorid, devid)) { get_mlnx_ext_port_info(&portid, data2, portnum); show_mlnx_ext_port_info(&portid, data2, portnum); } if (port_op != QUERY || changed) { /* * If we aren't setting the LID and the LID is the default, * the SMA command will fail due to an invalid LID. * Set it to something unlikely but valid. */ physstate = mad_get_field(data, 0, IB_PORT_PHYS_STATE_F); val = mad_get_field(data, 0, IB_PORT_LID_F); if (!port_args[LID].set && (!val || val == 0xFFFF)) mad_set_field(data, 0, IB_PORT_LID_F, 0x1234); val = mad_get_field(data, 0, IB_PORT_SMLID_F); if (!port_args[SMLID].set && (!val || val == 0xFFFF)) mad_set_field(data, 0, IB_PORT_SMLID_F, 0x1234); mad_set_field(data, 0, IB_PORT_STATE_F, 0); /* NOP */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 0); /* NOP */ switch (port_op) { case ON: /* Enable only if state is Disable */ if(physstate != 3) { printf("Port is already in enable state\n"); goto close_port; } case ENABLE: case RESET: /* Polling */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2); break; case OFF: case DISABLE: printf("Disable may be irreversible\n"); mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 3); break; case DOWN: mad_set_field(data, 0, IB_PORT_STATE_F, 1); break; case ARM: mad_set_field(data, 0, IB_PORT_STATE_F, 3); break; case ACTIVE: mad_set_field(data, 0, IB_PORT_STATE_F, 4); break; } /* always set enabled speeds/width - defaults to NOP */ mad_set_field(data, 0, IB_PORT_LINK_SPEED_ENABLED_F, speed); mad_set_field(data, 0, IB_PORT_LINK_SPEED_EXT_ENABLED_F, espeed); mad_set_field(data, 0, IB_PORT_LINK_WIDTH_ENABLED_F, width); if (port_args[VLS].set) mad_set_field(data, 0, IB_PORT_OPER_VLS_F, vls); if (port_args[MTU].set) mad_set_field(data, 0, IB_PORT_NEIGHBOR_MTU_F, mtu); if (port_args[LID].set) mad_set_field(data, 0, IB_PORT_LID_F, lid); if (port_args[SMLID].set) mad_set_field(data, 0, IB_PORT_SMLID_F, smlid); if (port_args[LMC].set) mad_set_field(data, 0, IB_PORT_LMC_F, lmc); if (port_args[FDR10SPEED].set) { mad_set_field(data2, 0, IB_MLNX_EXT_PORT_STATE_CHG_ENABLE_F, FDR10); mad_set_field(data2, 0, IB_MLNX_EXT_PORT_LINK_SPEED_ENABLED_F, fdr10); set_mlnx_ext_port_info(&portid, data2, portnum); } if (port_args[MKEY].set) mad_set_field64(data, 0, IB_PORT_MKEY_F, mkey); if (port_args[MKEYLEASE].set) mad_set_field(data, 0, IB_PORT_MKEY_LEASE_F, mkeylease); if (port_args[MKEYPROT].set) mad_set_field(data, 0, IB_PORT_MKEY_PROT_BITS_F, mkeyprot); set_port_info(&portid, data, portnum, espeed_cap, is_switch); } else if (is_switch && portnum) { /* Now, make sure PortState is Active */ /* Or is PortPhysicalState LinkUp sufficient ? */ mad_decode_field(data, IB_PORT_STATE_F, &state); mad_decode_field(data, IB_PORT_PHYS_STATE_F, &physstate); if (state == 4) { /* Active */ mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &lwe); mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &lws); mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &lwa); mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &lss); mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &lsa); mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &lse); mad_decode_field(data2, IB_MLNX_EXT_PORT_LINK_SPEED_SUPPORTED_F, &fdr10s); mad_decode_field(data2, IB_MLNX_EXT_PORT_LINK_SPEED_ENABLED_F, &fdr10e); mad_decode_field(data2, IB_MLNX_EXT_PORT_LINK_SPEED_ACTIVE_F, &fdr10a); if (espeed_cap) { mad_decode_field(data, IB_PORT_LINK_SPEED_EXT_SUPPORTED_F, &lses); mad_decode_field(data, IB_PORT_LINK_SPEED_EXT_ACTIVE_F, &lsea); mad_decode_field(data, IB_PORT_LINK_SPEED_EXT_ENABLED_F, &lsee); } /* Setup portid for peer port */ memcpy(&peerportid, &portid, sizeof(peerportid)); if (portid.lid == 0) { peerportid.drpath.cnt++; if (peerportid.drpath.cnt == IB_SUBNET_PATH_HOPS_MAX) { IBEXIT("Too many hops"); } } else { peerportid.drpath.cnt = 1; /* Set DrSLID to local lid */ if (resolve_self(ibd_ca, ibd_ca_port, &selfportid, &selfport, 0) < 0) IBEXIT("could not resolve self"); peerportid.drpath.drslid = (uint16_t) selfportid.lid; peerportid.drpath.drdlid = 0xffff; } peerportid.drpath.p[peerportid.drpath.cnt] = (uint8_t) portnum; /* Get peer port NodeInfo to obtain peer port number */ is_peer_switch = get_node_info(&peerportid, data); rem_vendorid = (uint32_t) mad_get_field(data, 0, IB_NODE_VENDORID_F); rem_devid = (uint16_t) mad_get_field(data, 0, IB_NODE_DEVID_F); mad_decode_field(data, IB_NODE_LOCAL_PORT_F, &peerlocalportnum); printf("Peer PortInfo:\n"); /* Get peer port characteristics */ peer_espeed_cap = get_port_info(&peerportid, data, peerlocalportnum, is_peer_switch); if (is_mlnx_ext_port_info_supported(rem_vendorid, rem_devid)) get_mlnx_ext_port_info(&peerportid, data2, peerlocalportnum); show_port_info(&peerportid, data, peerlocalportnum, peer_espeed_cap, is_peer_switch); if (is_mlnx_ext_port_info_supported(rem_vendorid, rem_devid)) show_mlnx_ext_port_info(&peerportid, data2, peerlocalportnum); mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &peerlwe); mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &peerlws); mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &peerlwa); mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &peerlss); mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &peerlsa); mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &peerlse); mad_decode_field(data2, IB_MLNX_EXT_PORT_LINK_SPEED_SUPPORTED_F, &peerfdr10s); mad_decode_field(data2, IB_MLNX_EXT_PORT_LINK_SPEED_ENABLED_F, &peerfdr10e); mad_decode_field(data2, IB_MLNX_EXT_PORT_LINK_SPEED_ACTIVE_F, &peerfdr10a); if (peer_espeed_cap) { mad_decode_field(data, IB_PORT_LINK_SPEED_EXT_SUPPORTED_F, &peerlses); mad_decode_field(data, IB_PORT_LINK_SPEED_EXT_ACTIVE_F, &peerlsea); mad_decode_field(data, IB_PORT_LINK_SPEED_EXT_ENABLED_F, &peerlsee); } /* Now validate peer port characteristics */ /* Examine Link Width */ width = get_link_width(lwe, lws); peerwidth = get_link_width(peerlwe, peerlws); validate_width(width, peerwidth, lwa); /* Examine Link Speeds */ speed = get_link_speed(lse, lss); peerspeed = get_link_speed(peerlse, peerlss); validate_speed(speed, peerspeed, lsa); if (espeed_cap && peer_espeed_cap) { espeed = get_link_speed_ext(lsee, lses); peerespeed = get_link_speed_ext(peerlsee, peerlses); validate_extended_speed(espeed, peerespeed, lsea); } else { if (fdr10e & FDR10 && peerfdr10e & FDR10) { if (!(fdr10a & FDR10)) IBWARN("Peer ports operating at active speed %d rather than FDR10", lsa); } } } } close_port: mad_rpc_close_port(srcport); exit(0); }
bool cps_api_nodes::load_groups() { cps_api_object_guard og(cps_api_object_create()); if (!cps_api_key_from_attr_with_qual(cps_api_object_key(og.get()),CPS_NODE_GROUP, cps_api_qualifier_TARGET)) { EV_LOG(ERR,DSAPI,0,"CPS-CLS-MAP","Meta data for cluster set is not loaded."); return false; } cps_db::connection_request b(cps_db::ProcessDBCache(),DEFAULT_REDIS_ADDR); if (!b.valid()) { return false; } group_data_t cpy; cps_api_object_list_guard lg(cps_api_object_list_create()); if (!cps_db::get_objects(b.get(),og.get(),lg.get())) return false; for (size_t ix = 0,mx = cps_api_object_list_size(lg.get()); ix < mx ; ++ix ) { cps_api_object_t o = cps_api_object_list_get(lg.get(),ix); std::vector<_db_node_data> v; const char *name = (const char*) cps_api_object_get_data(o,CPS_NODE_GROUP_NAME); _node_data nd; cps_api_node_data_type_t *_type = (cps_api_node_data_type_t*)cps_api_object_get_data(o,CPS_NODE_GROUP_TYPE); if (_type==nullptr) { EV_LOGGING(DSAPI,ERR,"NODE-LOAD","Could not get the group type for group %s",name); return false; } nd.type = *_type; cps_api_object_attr_t _node_group = cps_api_object_attr_get(o,CPS_NODE_GROUP_NODE); if (_node_group==nullptr) continue; ///TODO log cps_api_object_it_t it; cps_api_object_it_from_attr(_node_group,&it); cps_api_object_it_inside(&it); while (cps_api_object_it_valid(&it)) { cps_api_attr_id_t id = cps_api_object_attr_id(it.attr); (void)id; cps_api_object_it_t elem = it; cps_api_object_it_inside(&elem); if (!cps_api_object_it_valid(&elem)) continue; _db_node_data db_node; cps_api_object_attr_t _ip =cps_api_object_it_find(&elem,CPS_NODE_GROUP_NODE_IP); cps_api_object_attr_t _name =cps_api_object_it_find(&elem,CPS_NODE_GROUP_NODE_NAME); if (_ip==nullptr || _name==nullptr) continue; const char *__ip = (const char*)cps_api_object_attr_data_bin(_ip); const char *__name =(const char*)cps_api_object_attr_data_bin(_name); if(nd.type == cps_api_node_data_1_PLUS_1_REDUNDENCY) { db_node._name = __name; if(get_port_info(name,&db_node)) { auto lst = cps_string::split(std::string(__ip),":"); if (lst.size()!=2) { return false; } db_node._addr = lst[0] + ':'+ db_node._addr; v.push_back(std::move(db_node)); } else { EV_LOGGING(DSAPI,ERR,"CPS-DB","Failed to get port info for group %s and node %s", name,__name); } } if(v.size()>0) { _db_node_map[name] = v; update_slaves(name); } _alias_map[__name] = __ip; const char * _alias = this->addr(__ip); if (_alias!=nullptr) __ip = _alias; nd._addrs.push_back(__ip); cps_api_object_it_next(&it); } cpy[name] = nd; } size_t _new_hash = cps_api_nodes::gen_hash(cpy); if (_new_hash==_hash) return false; ///TODO is this unique enough? std::swap(_groups,cpy); _hash = _new_hash; return true; }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS}; ib_portid_t portid = {0}; ib_portid_t *sm_id = 0, sm_portid = {0}; extern int ibdebug; int err; int timeout = 0, udebug = 0; char *ca = 0; int ca_port = 0; int port_op = 0; /* default to query */ int speed = 15; int is_switch = 1; int state, physstate, lwe, lws, lwa, lse, lss, lsa; int peerlocalportnum, peerlwe, peerlws, peerlwa, peerlse, peerlss, peerlsa; int width, peerwidth, peerspeed; uint8_t data[IB_SMP_DATA_SIZE]; ib_portid_t peerportid = {0}; int portnum = 0; ib_portid_t selfportid = {0}; int selfport = 0; static char const str_opts[] = "C:P:t:s:devDGVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "err_show", 0, 0, 'e'}, { "verbose", 0, 0, 'v'}, { "Direct", 0, 0, 'D'}, { "Guid", 0, 0, 'G'}, { "timeout", 1, 0, 't'}, { "s", 1, 0, 's'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(udebug); udebug++; break; case 'e': madrpc_show_errors(1); break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'G': dest_type = IB_DEST_GUID; break; case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'v': verbose++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc < 2) usage(); madrpc_init(ca, ca_port, mgmt_classes, 3); if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[0]); /* First, make sure it is a switch port if it is a "set" */ if (argc >= 3) { if (!strcmp(argv[2], "enable")) port_op = 1; else if (!strcmp(argv[2], "disable")) port_op = 2; else if (!strcmp(argv[2], "reset")) port_op = 3; else if (!strcmp(argv[2], "speed")) { if (argc < 4) IBERROR("speed requires an additional parameter"); port_op = 4; /* Parse speed value */ speed = strtoul(argv[3], 0, 0); if (speed > 15) IBERROR("invalid speed value %d", speed); } } err = get_node_info(&portid, data); if (err < 0) IBERROR("smp query nodeinfo failed"); if (err) { /* not switch */ if (port_op == 0) /* query op */ is_switch = 0; else if (port_op != 4) /* other than speed op */ IBERROR("smp query nodeinfo: Node type not switch"); } if (argc-1 > 0) portnum = strtol(argv[1], 0, 0); if (port_op) printf("Initial PortInfo:\n"); else printf("PortInfo:\n"); err = get_port_info(&portid, data, portnum, port_op); if (err < 0) IBERROR("smp query portinfo failed"); /* Only if one of the "set" options is chosen */ if (port_op) { if (port_op == 1) /* Enable port */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2); /* Polling */ else if ((port_op == 2) || (port_op == 3)) { /* Disable port */ mad_set_field(data, 0, IB_PORT_STATE_F, 1); /* Down */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 3); /* Disabled */ } else if (port_op == 4) { /* Set speed */ mad_set_field(data, 0, IB_PORT_LINK_SPEED_ENABLED_F, speed); mad_set_field(data, 0, IB_PORT_STATE_F, 0); mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 0); } err = set_port_info(&portid, data, portnum, port_op); if (err < 0) IBERROR("smp set portinfo failed"); if (port_op == 3) { /* Reset port - so also enable */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2); /* Polling */ err = set_port_info(&portid, data, portnum, port_op); if (err < 0) IBERROR("smp set portinfo failed"); } } else { /* query op */ /* only compare peer port if switch port */ if (is_switch) { /* First, exclude SP0 */ if (portnum) { /* Now, make sure PortState is Active */ /* Or is PortPhysicalState LinkUp sufficient ? */ mad_decode_field(data, IB_PORT_STATE_F, &state); mad_decode_field(data, IB_PORT_PHYS_STATE_F, &physstate); if (state == 4) { /* Active */ mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &lwe ); mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &lws); mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &lwa); mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &lss); mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &lsa); mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &lse); /* Setup portid for peer port */ memcpy(&peerportid, &portid, sizeof(peerportid)); peerportid.drpath.cnt = 1; peerportid.drpath.p[1] = portnum; /* Set DrSLID to local lid */ if (ib_resolve_self(&selfportid, &selfport, 0) < 0) IBERROR("could not resolve self"); peerportid.drpath.drslid = selfportid.lid; peerportid.drpath.drdlid = 0xffff; /* Get peer port NodeInfo to obtain peer port number */ err = get_node_info(&peerportid, data); if (err < 0) IBERROR("smp query nodeinfo failed"); mad_decode_field(data, IB_NODE_LOCAL_PORT_F, &peerlocalportnum); printf("Peer PortInfo:\n"); /* Get peer port characteristics */ err = get_port_info(&peerportid, data, peerlocalportnum, port_op); if (err < 0) IBERROR("smp query peer portinfofailed"); mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &peerlwe ); mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &peerlws); mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &peerlwa); mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &peerlss); mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &peerlsa); mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &peerlse); /* Now validate peer port characteristics */ /* Examine Link Width */ width = get_link_width(lwe, lws); peerwidth = get_link_width(peerlwe, peerlws); validate_width(width, peerwidth, lwa); /* Examine Link Speed */ speed = get_link_speed(lse, lss); peerspeed = get_link_speed(peerlse, peerlss); validate_speed(speed, peerspeed, lsa); } } } } exit(0); }
// _UpdateThread status_t ColorSlider::_UpdateThread(void* data) { // initializing ColorSlider* colorSlider = (ColorSlider*)data; bool looperLocked = colorSlider->LockLooper(); port_id port = colorSlider->fUpdatePort; orientation orient = colorSlider->fOrientation; if (looperLocked) colorSlider->UnlockLooper(); float h, s, v, r, g, b; int R, G, B; // drawing int32 msg_code; char msg_buffer; while (true) { port_info info; do { read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer)); get_port_info(port, &info); } while (info.queue_count); if (colorSlider->LockLooper()) { uint colormode = colorSlider->fMode; float fixedvalue1 = colorSlider->fFixedValue1; float fixedvalue2 = colorSlider->fFixedValue2; BBitmap* bitmap = colorSlider->fBgBitmap; BView* view = colorSlider->fBgView; bitmap->Lock(); colorSlider->UnlockLooper(); view->BeginLineArray(256); switch (colormode) { case R_SELECTED: { G = round(fixedvalue1 * 255); B = round(fixedvalue2 * 255); for (int R = 0; R < 256; ++R) { _DrawColorLineY( view, R, R, G, B ); } }; break; case G_SELECTED: { R = round(fixedvalue1 * 255); B = round(fixedvalue2 * 255); for (int G = 0; G < 256; ++G) { _DrawColorLineY( view, G, R, G, B ); } }; break; case B_SELECTED: { R = round(fixedvalue1 * 255); G = round(fixedvalue2 * 255); for (int B = 0; B < 256; ++B) { _DrawColorLineY( view, B, R, G, B ); } }; break; case H_SELECTED: { s = 1.0;//fixedvalue1; v = 1.0;//fixedvalue2; if (orient == B_VERTICAL) { for (int y = 0; y < 256; ++y) { HSV_to_RGB( (float)y*6.0/255.0, s, v, r, g, b ); _DrawColorLineY( view, y, r*255, g*255, b*255 ); } } else { for (int x = 0; x < 256; ++x) { HSV_to_RGB( (float)x*6.0/255.0, s, v, r, g, b ); _DrawColorLineX( view, x, r*255, g*255, b*255 ); } } }; break; case S_SELECTED: { h = fixedvalue1; v = 1.0;//fixedvalue2; for (int y = 0; y < 256; ++y) { HSV_to_RGB( h, (float)y/255, v, r, g, b ); _DrawColorLineY( view, y, r*255, g*255, b*255 ); } }; break; case V_SELECTED: { h = fixedvalue1; s = 1.0;//fixedvalue2; for (int y = 0; y < 256; ++y) { HSV_to_RGB( h, s, (float)y/255, r, g, b ); _DrawColorLineY( view, y, r*255, g*255, b*255 ); } }; break; } view->EndLineArray(); view->Sync(); bitmap->Unlock(); if (colorSlider->LockLooper()) { colorSlider->Update(1); colorSlider->UnlockLooper(); } } } return B_OK; }
int main(int argc, char* argv[]) { team_info teamInfo; int32 cookie = 0; while (get_next_team_info(&cookie, &teamInfo) == B_OK) { if (!strncmp(teamInfo.args, "/boot/beos/", 11) || !strncmp(teamInfo.args, "/boot/system/", 13)) { // this is a system component and not worth to investigate continue; } thread_info threadInfo; int32 threadCookie = 0; while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo) == B_OK) { // search for the roster thread if (!strcmp(threadInfo.name, "_roster_thread_")) { port_id port = find_port("haiku-test:roster"); port_info portInfo; if (get_port_info(port, &portInfo) == B_OK && portInfo.team == teamInfo.team) { puts("The Haiku Registrar is already running."); return 0; } } } } // the Haiku registrar doesn't seem to run yet, change this BPath currentPath("."); BQuery query; query.SetPredicate("name==test_registrar"); // search on current volume only dev_t device = dev_for_path("."); BVolume volume(device); query.SetVolume(&volume); query.Fetch(); entry_ref ref; while (query.GetNextRef(&ref) == B_OK) { BPath path(&ref); if (path.InitCheck() != B_OK) continue; const char* registrarPath = path.Path(); const char* generatedPath = strstr(registrarPath, "generated"); if (generatedPath == NULL) continue; if (!strncmp(currentPath.Path(), registrarPath, generatedPath - registrarPath)) { // gotcha! if (launch_registrar(registrarPath) == B_OK) return 0; } } // As a fallback (maybe the volume does not support queries for example) // try to find the test_registrar in the current folder... BString registrarPath(argv[0]); registrarPath.RemoveLast(__progname); registrarPath.Append("test_registrar"); if (launch_registrar(registrarPath.String()) == B_OK) return 0; fprintf(stderr, "%s: Could not find the Haiku Registrar.\n" " (This tool only works when used in the Haiku tree, but maybe\n" " the registrar just needs to be built.)\n", __progname); return -1; }
int32 ColorField::_UpdateThread(void *data) { // initialization ColorField *colorField = (ColorField *)data; BLooper *looper = colorField->Looper(); if (looper) looper->Lock(); BBitmap* bitmap = colorField->fBgBitmap[0]; BView* view = colorField->fBgView[0]; port_id port = colorField->fUpdatePort; if (looper) looper->Unlock(); // draw float h, s, v, r, g, b; int R, G, B; int32 msg_code; char msg_buffer; while (true) { port_info info; do { read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer)); get_port_info(port, &info); } while (info.queue_count); if (looper) looper->Lock(); uint colormode = colorField->fColorMode; float fixedvalue = colorField->fFixedValue; if (looper) looper->Unlock(); bitmap->Lock(); view->BeginLineArray(256 * 256); switch (colormode) { case R_SELECTED: { R = round(fixedvalue * 255); for (int G = 0; G < 256; ++G) for (int B = 0; B < 256; ++B) DrawColorPoint(BPoint(G, 255.0 - B), R, G, B); break; } case G_SELECTED: { G = round(fixedvalue * 255); for (int R = 0; R < 256; ++R) for (int B = 0; B < 256; ++B) DrawColorPoint(BPoint(R, 255.0 - B), R, G, B); break; } case B_SELECTED: { B = round(fixedvalue * 255); for (int R = 0; R < 256; ++R) for (int G = 0; G < 256; ++G) DrawColorPoint(BPoint(R, 255.0 - G), R, G, B); break; } case H_SELECTED: { h = fixedvalue; for (int x = 0; x < 256; ++x) { s = (float)x / 255.0; for (int y = 0; y < 256; ++y) { v = (float)y / 255.0; HSV_to_RGB(h, s, v, r, g, b); DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0), round(g * 255.0), round(b * 255.0)); } } break; } case S_SELECTED: { s = fixedvalue; for (int x = 0; x < 256; ++x) { h = 6.0 / 255 * x; for (int y = 0; y<256; ++y) { v = (float)y / 255.0; HSV_to_RGB(h, s, v, r, g, b); DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0), round(g * 255.0), round(b * 255.0)); } } break; } case V_SELECTED: { v = fixedvalue; for (int x = 0; x < 256; ++x) { h = 6.0 / 255 * x; for (int y = 0; y < 256; ++y) { s = (float)y / 255.0; HSV_to_RGB(h, s, v, r, g, b); DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0), round(g * 255.0), round(b * 255.0)); } } break; } } view->EndLineArray(); view->Sync(); bitmap->Unlock(); looper = colorField->Looper(); if (looper && looper->Lock()) { colorField->Update(2); looper->Unlock(); } } return 0; }
// _UpdateThread int32 ColorField::_UpdateThread(void* data) { // initializing ColorField* colorField = (ColorField *)data; bool looperLocked = colorField->LockLooper(); BBitmap* bitmap = colorField->fBgBitmap[0]; port_id port = colorField->fUpdatePort; orientation orient = colorField->fOrientation; if (looperLocked) colorField->UnlockLooper(); float h, s, v, r, g, b; int R, G, B; // drawing int32 msg_code; char msg_buffer; while (true) { port_info info; do { read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer)); get_port_info(port, &info); } while (info.queue_count); if (colorField->LockLooper()) { uint colormode = colorField->fMode; float fixedvalue = colorField->fFixedValue; int width = (int)colorField->Width(); int height = (int)colorField->Height(); colorField->UnlockLooper(); bitmap->Lock(); //bigtime_t now = system_time(); uint8* bits = (uint8*)bitmap->Bits(); uint32 bpr = bitmap->BytesPerRow(); // offset 2 pixels from top and left bits += 2 * 4 + 2 * bpr; switch (colormode) { case R_SELECTED: { R = round(fixedvalue * 255); for (int y = height; y >= 0; y--) { uint8* bitsHandle = bits; int B = y / height * 255; for (int x = 0; x <= width; ++x) { int G = x / width * 255; set_bits(bitsHandle, R, G, B); bitsHandle += 4; } bits += bpr; } }; break; case G_SELECTED: { G = round(fixedvalue * 255); for (int y = height; y >= 0; y--) { uint8* bitsHandle = bits; int B = y / height * 255; for (int x = 0; x <= width; ++x) { int R = x / width * 255; set_bits(bitsHandle, R, G, B); bitsHandle += 4; } bits += bpr; } }; break; case B_SELECTED: { B = round(fixedvalue * 255); for (int y = height; y >= 0; y--) { uint8* bitsHandle = bits; int G = y / height * 255; for (int x = 0; x <= width; ++x) { int R = x / width * 255; set_bits(bitsHandle, R, G, B); bitsHandle += 4; } bits += bpr; } }; break; case H_SELECTED: { h = fixedvalue; if (orient == B_VERTICAL) { for (int y = 0; y <= height; ++y) { v = (float)(height - y) / height; uint8* bitsHandle = bits; for (int x = 0; x <= width; ++x) { s = (float)x / width; HSV_to_RGB( h, s, v, r, g, b ); set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0)); bitsHandle += 4; } bits += bpr; } } else { for (int y = 0; y <= height; ++y) { s = (float)y / height; uint8* bitsHandle = bits; for (int x = 0; x <= width; ++x) { v = (float)(width - x) / width; HSV_to_RGB( h, s, v, r, g, b ); set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0)); bitsHandle += 4; } bits += bpr; } } }; break; case S_SELECTED: { s = fixedvalue; for (int y = 0; y <= height; ++y) { v = (float)(height - y) / height; uint8* bitsHandle = bits; for (int x = 0; x <= width; ++x) { h = 6.0 / width * x; HSV_to_RGB( h, s, v, r, g, b ); set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0)); bitsHandle += 4; } bits += bpr; } }; break; case V_SELECTED: { v = fixedvalue; for (int y = 0; y <= height; ++y) { s = (float)(height - y) / height; uint8* bitsHandle = bits; for (int x = 0; x <= width; ++x) { h = 6.0 / width * x; HSV_to_RGB( h, s, v, r, g, b ); set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0)); bitsHandle += 4; } bits += bpr; } }; break; } //printf("color field update: %lld\n", system_time() - now); bitmap->Unlock(); if (colorField->LockLooper()) { colorField->Update(2); colorField->UnlockLooper(); } } } }
status_t LinkSender::Attach(const void *passedData, size_t passedSize) { size_t size = passedSize; const void* data = passedData; if (fCurrentStatus < B_OK) return fCurrentStatus; if (size == 0) return fCurrentStatus = B_BAD_VALUE; if (fCurrentEnd == fCurrentStart) return B_NO_INIT; // need to call StartMessage() first bool useArea = false; if (size >= kMaxBufferSize) { useArea = true; size = sizeof(area_id); } if (SpaceLeft() < size) { // we have to make space for the data status_t status = FlushCompleted(size + CurrentMessageSize()); if (status < B_OK) return fCurrentStatus = status; } area_id senderArea = -1; if (useArea) { if (fTargetTeam < 0) { port_info info; status_t result = get_port_info(fPort, &info); if (result != B_OK) return result; fTargetTeam = info.team; } void* address = NULL; off_t alignedSize = (passedSize + B_PAGE_SIZE) & ~(B_PAGE_SIZE - 1); senderArea = create_area("LinkSenderArea", &address, B_ANY_ADDRESS, alignedSize, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (senderArea < B_OK) return senderArea; data = &senderArea; memcpy(address, passedData, passedSize); area_id areaID = senderArea; senderArea = _kern_transfer_area(senderArea, &address, B_ANY_ADDRESS, fTargetTeam); if (senderArea < B_OK) { delete_area(areaID); return senderArea; } } memcpy(fBuffer + fCurrentEnd, data, size); fCurrentEnd += size; return B_OK; }
int main() { team_info teamInfo; int32 cookie = 0; while (get_next_team_info(&cookie, &teamInfo) == B_OK) { if (!strncmp(teamInfo.args, "/boot/beos/", 11)) { // this is a system component and not worth to investigate continue; } thread_info threadInfo; int32 threadCookie = 0; while (get_next_thread_info(teamInfo.team, &threadCookie, &threadInfo) == B_OK) { // search for the roster thread if (!strcmp(threadInfo.name, "_roster_thread_")) { port_id port = find_port("antares-test:roster"); port_info portInfo; if (get_port_info(port, &portInfo) == B_OK && portInfo.team == teamInfo.team) { puts("The Antares Registrar is already running."); return 0; } } } } // the Antares registrar doesn't seem to run yet, change this BPath currentPath("."); BQuery query; query.SetPredicate("name==test_registrar"); // search on current volume only dev_t device = dev_for_path("."); BVolume volume(device); query.SetVolume(&volume); query.Fetch(); entry_ref ref; while (query.GetNextRef(&ref) == B_OK) { BPath path(&ref); if (path.InitCheck() != B_OK) continue; const char* registrarPath = path.Path(); const char* generatedPath = strstr(registrarPath, "generated"); if (generatedPath == NULL) continue; if (!strncmp(currentPath.Path(), registrarPath, generatedPath - registrarPath)) { // gotcha! const char* args[] = { registrarPath, NULL }; thread_id thread = load_image(1, args, (const char**)environ); if (thread < B_OK) { fprintf(stderr, "%s: Could not start the registrar: %s\n", __progname, strerror(thread)); return -1; } resume_thread(thread); return 0; } } fprintf(stderr, "%s: Could not find the Antares Registrar.\n" " (This tool only works when used in the Antares tree, but maybe\n" " the registrar just needs to be built.)\n", __progname); return -1; }