void CBTHidConnection::DropConnection() { TRACE_FUNC (_L("[BTHID]\tCBTHidConnection::DropConnection")); // Close the Bluetooth Channels. CloseChannels(); // Update the connection state. ChangeState(ELinkLost); // If a command is outstanding if (iCommandIssued) { // Generate an error to the parent. iObserver.HandleCommandAck(iConnID, KErrNotReady); // Reset the command flag. iCommandIssued = EFalse; // Reset this, so we don't leave it in a bad state. if (iCommandSegmenter) { iCommandSegmenter->Reset(); } } }
void CBTHidConnection::ConnectionLost() { TRACE_FUNC (_L("[BTHID]\tCBTHidConnection::ConnectionLost")); CloseChannels(); // First go into link loss state ChangeState(ELinkLost); // If a command is outstanding if (iCommandIssued) { TRACE_INFO(_L("[BTHID]\tCBTHidConnection::ConnectionLost, command outstanding")); // Generate an error to the parent. iObserver.HandleCommandAck(iConnID, KErrNotReady); // Reset the command flag. iCommandIssued = EFalse; // Reset this, so we don't leave it in a bad state. if (iCommandSegmenter) { iCommandSegmenter->Reset(); } } // Check if the device will reconnect to us. if (iDevice->iReconnectInit) { TRACE_INFO(_L("[BTHID]\tCBTHidConnection::ConnectionLost, device inits reconnect")); // Inform the parent of the link loss and the fact we are not // reconnecting iObserver.LinkLost(iConnID); } else { TRACE_INFO(_L("[BTHID]\tCBTHidConnection::ConnectionLost, host inits reconnect")); // Device won't reconnect, check if we are able to. if (iDevice->iNormallyConnectable) { TRACE_INFO(_L("[BTHID]\tCBTHidConnection::ConnectionLost, device is normally connectable")); // Attempt to initiate reconnection to the device. TRAPD(res, iSocketInitiator->ConnectSocketsL(iDevice->iAddress, iDevice->iUseSecurity, iControlSocket, iInterruptSocket);) if (res == KErrNone) { // Reconnection is in progress, so record this and inform // the parent. ChangeState(EHostReconnecting); iObserver.LinkLost(iConnID); } else { // Inform the parent of the link loss and the fact we are not // reconnecting iObserver.LinkLost(iConnID); } }
int zmain(int argc, char **argv){ /* argv[0] is node name * expecting in format : "name-%d", * format for single node without decimal id: "name" */ WRITE_FMT_LOG(LOG_DEBUG, "Source node started argv[0]=%s\n", argv[0] ); if ( argc < 2 ){ WRITE_LOG(LOG_ERR, "argv[1] is expected, items count need to be passed.\n" ); return -1; } set_items_count_to_sortjob( atoi(argv[1]) ); int ownnodeid= -1; int extracted_name_len=0; int res =0; /*get node type names via environnment*/ char *source_node_type_text = getenv(ENV_SOURCE_NODE_NAME); char *dest_node_type_text = getenv(ENV_DEST_NODE_NAME); char *man_node_type_text = getenv(ENV_MAN_NODE_NAME); assert(source_node_type_text); assert(dest_node_type_text); assert(man_node_type_text); ownnodeid = ExtractNodeNameId( argv[0], &extracted_name_len ); /*nodename should be the same we got via environment and extracted from argv[0]*/ assert( !strncmp(source_node_type_text, argv[0], extracted_name_len ) ); if ( ownnodeid == -1 ) ownnodeid=1; /*node id not specified for single node by default assign nodeid=1*/ /*setup channels conf, now used static data but should be replaced by data from zrt*/ struct ChannelsConfigInterface chan_if; SetupChannelsConfigInterface( &chan_if, ownnodeid, ESourceNode ); /*********************************************************************** Add channels configuration into config object */ res = AddAllChannelsRelatedToNodeTypeFromDir( &chan_if, IN_DIR, EChannelModeRead, EManagerNode, man_node_type_text ); assert( res == 0 ); res = AddAllChannelsRelatedToNodeTypeFromDir( &chan_if, IN_DIR, EChannelModeRead, EDestinationNode, dest_node_type_text ); assert( res == 0 ); res = AddAllChannelsRelatedToNodeTypeFromDir( &chan_if, OUT_DIR, EChannelModeWrite, EManagerNode, man_node_type_text ); assert( res == 0 ); res = AddAllChannelsRelatedToNodeTypeFromDir( &chan_if, OUT_DIR, EChannelModeWrite, EDestinationNode, dest_node_type_text ); assert( res == 0 ); /*add input channel into config*/ res = chan_if.AddChannel( &chan_if, EInputOutputNode, 1, STDIN, EChannelModeRead ) != NULL? 0: -1; assert( res == 0 ); /*--------------*/ res = start_node(&chan_if, ownnodeid); CloseChannels(&chan_if); return res; }
void CBTHidConnection::OfferInterruptSocket(const TBTDevAddr& aAddress, RSocket*& aSocket) { TRACE_FUNC (_L("[BTHID]\tCBTHidConnection::OfferInterruptSocket")); if (aAddress == iDevice->iAddress) { __ASSERT_DEBUG((iConnectionState == EHIDReconnecting) ||(iConnectionState == EHIDInitConnecting) , User::Panic(KPanicBTConnection, ESocketsBadState)); // Take ownership of this socket delete iInterruptSocket; iInterruptSocket = aSocket; aSocket = 0; TRAPD(error, PrepareSocketsL()); if (KErrNone == error) { // Mark that we are now reconnected. TBTConnectionState prevState = iConnectionState; ChangeState(EConnected); if (prevState == EHIDInitConnecting) { // If this was an remote HID initial connection, start the SDP Search. iObserver.StartSDPSearch(iConnID); } else { // Inform the observer that the connection has been restored. iObserver.LinkRestored(iConnID); } } else { // Close the sockets as they can't be used CloseChannels(); if (iConnectionState == EHIDInitConnecting) { ChangeState(ENotConnected); // If this was an remote HID initial connection inform the observer iObserver.FirstTimeConnectionCompleteFromRemote(iConnID, error); } else { ChangeState(ELinkLost); } } } }
/* * finalize networking (if there are network channels) * note: will run only once. should be called from channel destructor */ static INLINE void NetDtor() { /* context will be destroyed at the last call */ if(--channels_cnt) return; /* temporary fix to make zmq_term() working */ CloseChannels(); /* terminate context */ zmq_term(context); /* release name service */ NameServiceDtor(); }
int main( int argc, char **argv ) { unsigned int num_channels, compress; struct stat stat_buf; profile_param_info_t *profile_list; char *rfile, *ffile, *filename, *Mdirs, *tstring; char *profile_datadir, *profile_statdir, *nameserver; int c, syntax_only, subdir_index, stdin_profile_params, do_xstat; time_t tslot; tstring = NULL; profile_datadir = NULL; profile_statdir = NULL; Mdirs = NULL; tslot = 0; syntax_only = 0; do_xstat = 0; compress = 0; subdir_index = 0; profile_list = NULL; nameserver = NULL; stdin_profile_params = 0; is_anonymized = 0; strncpy(Ident, "none", IDENTLEN); Ident[IDENTLEN-1] = '\0'; // default file names ffile = "filter.txt"; rfile = NULL; while ((c = getopt(argc, argv, "D:HIL:p:P:hf:r:n:M:S:t:VzZ")) != EOF) { switch (c) { case 'h': usage(argv[0]); exit(0); break; case 'D': nameserver = optarg; if ( !set_nameserver(nameserver) ) { exit(255); } break; case 'I': stdin_profile_params = 1; break; case 'H': do_xstat = 1; break; case 'L': if ( !InitLog("nfprofile", optarg) ) exit(255); break; case 'Z': syntax_only = 1; break; case 'p': profile_datadir = optarg; break; case 'P': profile_statdir = optarg; break; case 'S': subdir_index = atoi(optarg); break; case 'V': printf("%s: Version: %s\n",argv[0], nfdump_version); exit(0); break; case 'f': ffile = optarg; break; case 't': tslot = atoi(optarg); break; case 'M': Mdirs = optarg; break; case 'r': rfile = optarg; break; case 'z': compress = 1; break; default: usage(argv[0]); exit(0); } } if ( subdir_index && !InitHierPath(subdir_index) ) { exit(255); } if ( !profile_datadir ) { LogError("Profile data directory required!\n"); exit(255); } if ( !profile_statdir ) { profile_statdir = profile_datadir; } if ( stat(profile_datadir, &stat_buf) || !S_ISDIR(stat_buf.st_mode) ) { LogError("'%s' not a directory\n", profile_datadir); exit(255); } if ( stdin_profile_params ) { profile_list = ParseParams(profile_datadir); if ( !profile_list ) { exit(254); } } if ( syntax_only ) { filename = NULL; rfile = NULL; } else { char *p; if ( rfile == NULL ) { LogError("-r filename required!\n"); exit(255); } p = strrchr(rfile, '/'); filename = p == NULL ? rfile : ++p; if ( strlen(filename) == 0 ) { LogError("Filename error: zero length filename\n"); exit(254); } } if ( chdir(profile_datadir)) { LogError("Error can't chdir to '%s': %s", profile_datadir, strerror(errno)); exit(255); } num_channels = InitChannels(profile_datadir, profile_statdir, profile_list, ffile, filename, subdir_index, syntax_only, compress, do_xstat); // nothing to do if ( num_channels == 0 ) { LogInfo("No channels to process.\n"); return 0; } if ( syntax_only ) { printf("Syntax check done.\n"); return 0; } if ( !rfile ) { LogError("Input file (-r) required!\n"); exit(255); } extension_map_list = InitExtensionMaps(NEEDS_EXTENSION_LIST); if ( !InitExporterList() ) { exit(255); } SetupInputFileSequence(Mdirs,rfile, NULL); process_data(GetChannelInfoList(), num_channels, tslot, do_xstat); CloseChannels(tslot, compress); FreeExtensionMaps(extension_map_list); return 0; }