#NEWLINE# def advertise_service( sock , name , service_id = '' , service_classes = [ ] , profiles = [ ] , provider = '' , description = '' , protocols = [ ] ) : #NEWLINE# #INDENT# if ( ( service_id != '' ) and ( not is_valid_uuid ( service_id ) ) ) : #NEWLINE# #INDENT# raise ValueError ( 'invalid UUID specified for service_id' ) #NEWLINE# #UNINDENT# for uuid in service_classes : #NEWLINE# #INDENT# if ( not is_valid_uuid ( uuid ) ) : #NEWLINE# #INDENT# raise ValueError ( 'invalid UUID specified in service_classes' ) #NEWLINE# #UNINDENT# #UNINDENT# for ( uuid , version ) in profiles : #NEWLINE# #INDENT# if ( ( not is_valid_uuid ( uuid ) ) or ( version < 0 ) or ( version > 65535 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid Profile Descriptor' ) #NEWLINE# #UNINDENT# #UNINDENT# for uuid in protocols : #NEWLINE# #INDENT# if ( not is_valid_uuid ( uuid ) ) : #NEWLINE# #INDENT# raise ValueError ( 'invalid UUID specified in protocols' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( sock . _raw_sdp_record is not None ) : #NEWLINE# #INDENT# raise IOError ( 'service already advertised' ) #NEWLINE# #UNINDENT# avpairs = [ ] #NEWLINE# if ( len ( service_id ) > 0 ) : #NEWLINE# #INDENT# avpairs . append ( ( 'UInt16' , SERVICE_ID_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'UUID' , service_id ) ) #NEWLINE# #UNINDENT# if ( len ( service_classes ) > 0 ) : #NEWLINE# #INDENT# seq = [ ( 'UUID' , svc_class ) for svc_class in service_classes ] #NEWLINE# avpairs . append ( ( 'UInt16' , SERVICE_CLASS_ID_LIST_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'ElemSeq' , seq ) ) #NEWLINE# #UNINDENT# assert ( sock . _proto == RFCOMM ) #NEWLINE# ( addr , port ) = sock . getsockname ( ) #NEWLINE# avpairs . append ( ( 'UInt16' , PROTOCOL_DESCRIPTOR_LIST_ATTRID ) ) #NEWLINE# l2cap_pd = ( 'ElemSeq' , ( ( 'UUID' , L2CAP_UUID ) , ) ) #NEWLINE# rfcomm_pd = ( 'ElemSeq' , ( ( 'UUID' , RFCOMM_UUID ) , ( 'UInt8' , port ) ) ) #NEWLINE# proto_list = [ l2cap_pd , rfcomm_pd ] #NEWLINE# for proto_uuid in protocols : #NEWLINE# #INDENT# proto_list . append ( ( 'ElemSeq' , ( ( 'UUID' , proto_uuid ) , ) ) ) #NEWLINE# #UNINDENT# avpairs . append ( ( 'ElemSeq' , proto_list ) ) #NEWLINE# avpairs . append ( ( 'UInt16' , BROWSE_GROUP_LIST_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'ElemSeq' , ( ( 'UUID' , PUBLIC_BROWSE_GROUP ) , ) ) ) #NEWLINE# if ( len ( profiles ) > 0 ) : #NEWLINE# #INDENT# seq = [ ( 'ElemSeq' , ( ( 'UUID' , uuid ) , ( 'UInt16' , version ) ) ) for ( uuid , version ) in profiles ] #NEWLINE# avpairs . append ( ( 'UInt16' , BLUETOOTH_PROFILE_DESCRIPTOR_LIST_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'ElemSeq' , seq ) ) #NEWLINE# #UNINDENT# avpairs . append ( ( 'UInt16' , SERVICE_NAME_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'String' , name ) ) #NEWLINE# if ( len ( description ) > 0 ) : #NEWLINE# #INDENT# avpairs . append ( ( 'UInt16' , SERVICE_DESCRIPTION_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'String' , description ) ) #NEWLINE# #UNINDENT# if ( len ( provider ) > 0 ) : #NEWLINE# #INDENT# avpairs . append ( ( 'UInt16' , PROVIDER_NAME_ATTRID ) ) #NEWLINE# avpairs . append ( ( 'String' , provider ) ) #NEWLINE# #UNINDENT# sock . _raw_sdp_record = sdp_make_data_element ( 'ElemSeq' , avpairs ) #NEWLINE# sock . _sdp_handle = bt . set_service_raw ( sock . _raw_sdp_record , True )