https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • c

    Cyrille QUÉMIN

    08/08/2019, 11:20 PM
    I tried something as bellow. In the common module I have:
    interface View{
      suspend fun myFunSuspend().
    }
    
    // for Android, normal implementation of co routine
    // for iOS see below, because I need to call a function in swift that uses callbacks
    
    class iOSViewWrapper(private val iOSImpl: IosView) : View {
    
      override suspend fun myFunSuspend(){
        return suspendCoroutine {
          iOSImpl.doAsyncJob{ data, error ->
            if(error != null){
              it.resumeWithException(error)
            }else{
              it.resume(data)
            }
          }
        } 
      }
    }
    
    interface IosView {
      fun doAsyncJob((data: ByteArray, error: Throwable?)-> Unit)
    }
    the function
    doAsyncJob
    implementation is done in Swift and is called many times inside my kotlin code. I have defined a coroutine scope that is using the ios
    dispatch_get_main_queue
    . I have made sure that
    doAsyncJob
    is execute AND invoke the closure on the main thread. The code works but crashes always in the swift invocation of the closure. Sometimes after 1 call sometimes after 6 or 10, ... I tried to declare the closure of
    doAsyncJob
    as a variable and call
    .freeze()
    on it, but I get
    kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[MainDispatcher@7d793018, Continuation @ $prepareCOROUTINE$11]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
            at 0   mylib                            0x0000000100f81e98 kfun:kotlin.Error.<init>(kotlin.String?;kotlin.Throwable?)kotlin.Error + 24
            at 1   mylib                            0x0000000100f81bc0 kfun:kotlinx.coroutines.CoroutinesInternalError.<init>(kotlin.String;kotlin.Throwable)kotlinx.coroutines.CoroutinesInternalError + 24
            at 2   mylib                            0x0000000100f81818 kfun:kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx-coroutines-core(kotlin.Throwable?;kotlin.Throwable?) + 284
            at 3   mylib                            0x0000000100f82540 kfun:kotlinx.coroutines.DispatchedTask.run() + 1224
    what am I doing wrong? I am using kotlin
    1.3.41
    and coroutine
    1.3.0-RC
    with an mpp project android and ios
    k
    s
    4 replies · 3 participants
  • l

    louiscad

    08/09/2019, 7:09 AM
    Are Objective-C Nullability symbols (https://developer.apple.com/swift/blog/?id=25) recognized by cinterop?
    a
    1 reply · 2 participants
  • n

    Nabil

    08/09/2019, 8:44 AM
    Hi, In Kotlin/Native is there a pattern that could be used to get notified about the object that is being collected through Reference Counting? here’s my use case: Let’s say you have a Kotlin class that calls (using C-interop) some dynamic library which perform dynamic allocation on the heap, the pointer of this allocation is stored in the Kotlin class as a
    Long
    so it can be passed later to make some invocations via the C-interop (the
    Long
    value is
    reinterpret_cast<CppObj*>(pointer)
    to whatever the original C/C++ object is), usually we want to deallocate explicitly this pointer when the object get GC’ed via the reference counter. I’m aware of the existing memory management approaches (memScope/arena etc.) but in this scenario we can not wrap every instance of the Kotlin class inside a memScope/arena, these are instances passed to the user of the API so we don’t control their lifecycles, this is why deallocating the C++ resources should be tied to the collection of the original Kotlin instance (to draw a parallel, this is the pattern used in Java with Phantom reference & a referenceQueue to close native pointers, see CrazyBob presentation

    https://www.youtube.com/watch?v=KTC0g14ImPc)▾

    ➕ 2
    a
    a
    +1
    21 replies · 4 participants
  • y

    Yan Pujante

    08/09/2019, 3:18 PM
    The kotlin native tutorial about dynamic libraries (https://kotlinlang.org/docs/tutorials/native/dynamic-libraries.html) has an example about the C++ code creating a Kotlin object instance and releasing it later:
    libnative_kref_example_Clazz newInstance = lib->kotlin.root.example.Clazz.Clazz();
      long x = lib->kotlin.root.example.Clazz.memberFunction(newInstance, 42);
      lib->DisposeStablePointer(newInstance.pinned);
    What happens if instead I have the following Kotlin code:
    interface Foo {}
    
    private class FooImpl : Foo {}
    
    createFoo() : Foo { return FooImpl() }
    and I call
    createFoo
    from C++ (in other words, the object is created on the Kotlin side not the C++ side). How do I tell the Kotlin side that I am going to keep the
    Foo
    instance for a while? Does it work the same and I am supposed to call
    DisposeStablePointer
    when I am done?
    s
    1 reply · 2 participants
  • j

    Jeremy

    08/11/2019, 4:04 AM
    When accessing ktor from worker thread gives error: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread. All variables are initialized inside of the job and the string constant "OK" is returned
    Is ktor worker supported or is usage incorrect?
    s
    a
    4 replies · 3 participants
  • m

    Marko Mitic

    08/11/2019, 3:08 PM
    Hi everybody, I'm trying to do K/N hands on, using libcurl. However on Windows, libcurl is not a system lib. I've downloaded binaries but I'm not sure where to drop them inside the project and whether additional buildscript changes are needed to reference it.
    g
    m
    7 replies · 3 participants
  • s

    Sam

    08/12/2019, 9:36 PM
    I have an issue compiling some code that compiles for the jvm and android targets but fails to compile for iOS. From what I can tell it may be serialization related but I'm not 100% positive. I'm using versions kotlin_version = 1.3.41 & kotlin_serialization_version = 0.11.1
    Compilation with kotlinx-serialization
    k
    a
    8 replies · 3 participants
  • f

    fcosta

    08/13/2019, 12:08 AM
    Is it possible to run/debug unit test with kotlin native inside IntelliJ?
    t
    2 replies · 2 participants
  • f

    Filippo Pizzicola

    08/13/2019, 2:02 PM
    Hey guys, I am beginning to study kotlin native, does someone knows, or has an article to explain me the advantages and disvantages of it, comparing it with the quarkus project?
    s
    2 replies · 2 participants
  • s

    SBNTT

    08/13/2019, 4:10 PM
    Hi, how can i make all existing build tasks depends on a custom one ? thannnks
    l
    8 replies · 2 participants
  • p

    pandawarrior

    08/14/2019, 10:09 AM
    I have this problem when using coroutines, ktor and sqldelight in Kotlin Multiplatform on iOS
    /Users/teamcity/buildAgent/work/4d622a065c544371/runtime/src/main/cpp/Memory.cpp:770: runtime assert: Must be positive
    . I am currently looking at https://github.com/JetBrains/kotlin-native/blob/v1.3.1/runtime/src/main/cpp/Memory.cpp#L770 for clues. Anyone has any ideas how to go about this?
    l
    a
    +1
    3 replies · 4 participants
  • a

    Andrei Marshalov

    08/16/2019, 8:40 AM
    Hi, i’m using kotlin-multiplatform plugin to create ios framework and android aar library. Since i use interop with c-libraries in my project i need to do some special stuff at the end of using my objects: call function, that will free memory, allocated by c-functions. To be sure that memory is always freed (eg if an exception is thrown) i added my own
    Closeable
    interface and copied
    use
    extension from
    <http://kotlin.io|kotlin.io>
    package. It looks like:
    interface Closeable {
    
        fun close()
    }
    
    @Throws(Throwable::class)
    inline fun <T : Closeable?, R> T.use(block: (T) -> R): R {
        var exception: Throwable? = null
        try {
            return block(this)
        } catch (e: Throwable) {
            exception = e
            throw e
        } finally {
            when {
                this == null -> {}
                exception == null -> close()
                else ->
                    try {
                        close()
                    } catch (closeException: Throwable) {
                        // cause.addSuppressed(closeException) // ignored here
                    }
            }
        }
    }
    It works fine for android, but in Swift i have some problem. Function signature from xCode:
    UtilitiesKt.use(receiver: Closeable?, block: (Closeable?) -> Any?, result: AutoreleasingUnsafeMutablePointer<AnyObject??)
    use
    function in xCode marked as
    trowable
    , due to
    @Throws(Throwable::class)
    annotation, but if i try use
    trowable
    functions in
    block
    lambda, xCode says:
    Invalid conversion from throwing function of type '(Closeable?) throws -> Any?' to non-throwing function type '(Closeable?) -> Any?'
    Maybe someone know, how can i mark lambda parameter as
    throwable
    in kotlin?
    a
    4 replies · 2 participants
  • g

    gmaciel

    08/18/2019, 8:32 PM
    Do i have to do anything special to be able to use the
    @Throws
    annotation in a
    commonMain
    module? The IDE doesn't find and i'm using kotlin 1.3.41
    r
    e
    +1
    5 replies · 4 participants
  • n

    napperley

    08/19/2019, 7:15 AM
    What is the URL to use for downloading a tar.gz version of Kotlin Native 1.3.41? Need the file to compile a Kotlin Native program inside a Docker image.
    a
    3 replies · 2 participants
  • s

    salomonbrys

    08/19/2019, 9:29 AM
    I've needed to get this out of my system for a while now. I just published "Why the Kotlin/Native memory model cannot hold". https://link.medium.com/3qoLYItchZ
    🌶️ 5
    🍿 8
    👍 9
    m
    o
    +7
    75 replies · 10 participants
  • k

    kpgalligan

    08/19/2019, 3:38 PM
    I’m sure I knew this but now forget. How does one get around the 32bit/64bit interop situation where NSInteger is an Int in 32 and a Long in 64?
    Type mismatch: inferred type is Long but NSInteger /* = Int */ was expected
    l
    a
    +4
    30 replies · 7 participants
  • e

    elect

    08/21/2019, 9:51 AM
    does anyone here have some experience playing native on embedded devices?
    l
    2 replies · 2 participants
  • s

    Slackbot

    08/22/2019, 6:09 AM
    This message was deleted.
    g
    u
    3 replies · 3 participants
  • k

    Kris Wong

    08/22/2019, 3:38 PM
    are there any variables that I can use within a .DEF file?
    d
    o
    +1
    20 replies · 4 participants
  • i

    ivan.savytskyi

    08/22/2019, 3:39 PM
    question folks: if I need to define a KN function that will be called on Objective-C that returns a string and it has this signature
    override fun foo(): CPointer<ByteVar>?
    , should I use
    StableRef
    like:
    override fun foo(): CPointer<ByteVar>? {
            return StableRef
                .create(name.encodeToByteArray())
                .asCPointer()
                .rawValue
                .let { interpretCPointer(it) }
        }
    d
    o
    12 replies · 3 participants
  • t

    tapchicoma

    08/22/2019, 7:40 PM
    This release brings more pre-imported Apple frameworks for all platforms, including macOS and iOS.
    Is there any list of this additional frameworks? Or they all listed here: https://github.com/JetBrains/kotlin-native/tree/master/platformLibs/src/platform/ios?
    s
    1 reply · 2 participants
  • i

    ivan.savytskyi

    08/22/2019, 7:59 PM
    another question: external C library defines a protocol that KN class implements
    class MyFooModule : NSObject(), FooModuleProtocol {
    . But this information is erased
    @interface MyFooModule : KotlinBase
    in the result generated header file. How to make header file to look like this
    @interface MyFooModule : KotlinBase <FooModule>
    ?
    k
    s
    7 replies · 3 participants
  • d

    Dominaezzz

    08/22/2019, 9:44 PM
    Oooh K/N compiler performance boost in new release! Has anyone tried it yet?
    ➕ 3
    🎉 3
    u
    n
    9 replies · 3 participants
  • m

    msink

    08/22/2019, 9:54 PM
    And
    enableFeaturePreview("GRADLE_METADATA")
    on consumer side can be removed with 1.3.50 and Gradle 5.6
    l
    3 replies · 2 participants
  • s

    Sam

    08/23/2019, 5:08 AM
    Now that K/N produces Apple compatible bitcode in frameworks, what would the effort be like to support tvOS? It’s a similar but different SDK from iOS.
    m
    l
    +4
    8 replies · 7 participants
  • y

    Yan Pujante

    08/23/2019, 2:44 PM
    After upgrading to 1.3.50 running the build on my ~30 lines of code of kotlin native fails with the following error:
    error: Invalid value (Producer: 'LLVM6.0.1' Reader: 'LLVM APPLE_1_900.0.39.2_0')
    1 error generated.
    e: Compilation failed: The /Applications/Xcode9.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ command returned non-zero exit code: 1.
    output: 
    
     * Source files: SampleMacos.kt, PlatformView.kt
     * Compiler version info: Konan: 1.3.50 / Kotlin: 1.3.50
     * Output kind: STATIC
    
    e: org.jetbrains.kotlin.konan.KonanExternalToolFailure: The /Applications/Xcode9.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ command returned non-zero exit code: 1.
    > Process 'command '/local/sdkman/candidates/java/8.0.212-zulu/bin/java'' finished with non-zero exit value 2
    Just an FYI if you plan to migrate...
    o
    m
    4 replies · 3 participants
  • c

    cubesky

    08/23/2019, 3:57 PM
    Hello, I just want to use Kotlin Native to access OpenCV library But, cinterops only process c header but not c++ header Unfortunately OpenCV only has full access with c++ header, is there any solution can I access c++ header with cinterops to generate klib?
    k
    s
    +1
    8 replies · 4 participants
  • n

    napperley

    08/25/2019, 2:06 AM
    After updating Kotlin from 1.3.10 to 1.3.50 for a Kotlin Native project, and running the project as a program a strange error appears:
    type Nothing? is not supported here: doesn't correspond to any C type
    Double checked the mapping (in the knm file) and found that the return type is
    CPointer<gtk3.GtkWidget>?
    for the function (
    gtk_file_chooser_dialog_new
    ) that is called in the program. However the function definition looks very odd:
    @kotlinx.cinterop.internal.CCall public external fun gtk_file_chooser_dialog_new(@kotlinx.cinterop.internal.CCall.CString title: kotlin.String?, parent: kotlinx.cinterop.CValuesRef<gtk3.GtkWindow /* = gtk3._GtkWindow */>?, action: gtk3.GtkFileChooserAction, @kotlinx.cinterop.internal.CCall.CString first_button_text: kotlin.String?, vararg variadicArguments: kotlin.Any?): kotlinx.cinterop.CPointer<gtk3.GtkWidget /* = gtk3._GtkWidget */>? { /* compiled code */ }
    m
    o
    +1
    7 replies · 4 participants
  • n

    napperley

    08/25/2019, 4:14 AM
    Been looking through some of the mappings generated for the libudev library:
    public fun udev_list_entry_get_by_name(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?, @kotlinx.cinterop.internal.CCall.CString name: kotlin.String?): kotlinx.cinterop.CPointer<cnames.structs.udev_list_entry>? { /* compiled code */ }
    
    public fun udev_list_entry_get_name(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?): kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>? { /* compiled code */ }
    
    public fun udev_list_entry_get_next(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?): kotlinx.cinterop.CPointer<cnames.structs.udev_list_entry>? { /* compiled code */ }
    
    public fun udev_list_entry_get_value(list_entry: kotlinx.cinterop.CValuesRef<cnames.structs.udev_list_entry>?): kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>? { /* compiled code */ }
    There doesn't appear to be a definition in any of the knm files for
    udev_list_entry
    (a C struct), however
    cnames.structs.udev_list_entry
    does exist but its definition doesn't seem to appear in any of the knm files which is strange.
    m
    o
    9 replies · 3 participants
  • n

    napperley

    08/26/2019, 2:54 AM
    Found a C macro called
    udev_list_entry_foreach
    which is used to access each entry in the list. Would manually iterating over the list (via
    udev_list_entry_get_next
    ) be the way to workaround the macro? I am using this C example as a reference: https://github.com/gavv/snippets/blob/master/udev/udev_monitor_usb.c
    m
    d
    7 replies · 3 participants
Powered by Linen
Title
n

napperley

08/26/2019, 2:54 AM
Found a C macro called
udev_list_entry_foreach
which is used to access each entry in the list. Would manually iterating over the list (via
udev_list_entry_get_next
) be the way to workaround the macro? I am using this C example as a reference: https://github.com/gavv/snippets/blob/master/udev/udev_monitor_usb.c
Tried the iteration method however it doesn't seem to iterate over the list, and the same USB device appears twice.
main.kt
Definition file for the udev library.
udev.def
Below is the program's output:
> Task :runSerial_reading_demoReleaseExecutableLinux
Starting USB monitor example...
Device Path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-0:1.0
* Device: Action - exists, Vendor - 0000, Product - 0000
Device Path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-0:1.0
* Device: Action - exists, Vendor - 0000, Product - 0000
Below is the output from the
lsusb
command:
Bus 002 Device 002: ID 0bda:0316 Realtek Semiconductor Corp. 
Bus 002 Device 008: ID 2109:0813 VIA Labs, Inc. 
Bus 002 Device 007: ID 2109:0813 VIA Labs, Inc. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 04f2:b604 Chicony Electronics Co., Ltd 
Bus 001 Device 013: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light
Bus 001 Device 012: ID 2109:2813 VIA Labs, Inc. 
Bus 001 Device 011: ID 2109:2813 VIA Labs, Inc. 
Bus 001 Device 002: ID 046d:c52f Logitech, Inc. Unifying Receiver
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
m

msink

08/26/2019, 6:02 AM
Maybe you use wrong definition of list_entry In systemd it defined as
struct udev_list_entry {
        struct udev_list *list;
        char *name;
        char *value;

        LIST_FIELDS(struct udev_list_entry, entries);
};
n

napperley

08/26/2019, 6:44 AM
Was close but forgot to assign the output of
udev_enumerate_get_list_entry
to a property 🤦‍♂️. Iterating through the registered devices now looks like this:
val devices = udev_enumerate_get_list_entry(enumerate)
        val usbDevices = mutableListOf<UsbDevice>()
        if (devices != null) {
            val tmp = processListEntry(udev, devices)
            if (tmp.vendor.isNotEmpty()) usbDevices += tmp
        }
        var entry = udev_list_entry_get_next(devices)
        while (entry != null) {
            val tmp = processListEntry(udev, entry)
            if (tmp.vendor.isNotEmpty()) usbDevices += tmp
            entry = udev_list_entry_get_next(entry)
        }
        usbDevices.forEach { println("* $it") }
        println("Total USB Devices: ${usbDevices.size}")
d

Dominaezzz

08/26/2019, 10:43 AM
Have a look at
generateSequence
, you might find it useful here.
❓ 1
View count: 14