Add some docs

This commit is contained in:
Atos1337 2021-12-16 23:14:32 +03:00
parent fe1575c5ee
commit 3ebbec35fe
4 changed files with 78 additions and 0 deletions

26
controls-mongo/README.md Normal file
View File

@ -0,0 +1,26 @@
# Description
This module allows you to store [DeviceMessages](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt)
from certain [DeviceManager](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/DeviceManager.kt)
or [MagixMessages](magix/magix-api/src/commonMain/kotlin/ru/mipt/npm/magix/api/MagixMessage.kt)
from [magix server](/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/server.kt)
in [mongoDB](https://www.mongodb.com/).
# Usage
All usage examples can be found in [VirtualCarController](/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCarController.kt).
## Storage from Device Manager
Just call storeMessagesInXodus. For more details, you can see comments in [source code](/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt)
## Storage from Magix Server
Just pass such lambda as parameter to startMagixServer:
```kotlin
{ flow ->
// some code
storeInMongo(flow)
// some code
}
```
For more details, you can see comments in [source code](/controls-mongo/src/main/kotlin/ru/mipt/npm/controls/mongo/connections.kt)

View File

@ -39,6 +39,13 @@ public object DefaultMongoClientFactory : Factory<CoroutineClient> {
} ?: KMongo.createClient(DEFAULT_MONGO_DATABASE_URL).coroutine } ?: KMongo.createClient(DEFAULT_MONGO_DATABASE_URL).coroutine
} }
/**
* Begin to store DeviceMessages from this DeviceManager
* @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default.
* DeviceManager's meta and context will be used for in invoke method.
* @param filterCondition allow you to specify messages which we want to store. Always true by default.
* @return Job which responsible for our storage
*/
@OptIn(InternalCoroutinesApi::class) @OptIn(InternalCoroutinesApi::class)
public fun DeviceManager.connectMongo( public fun DeviceManager.connectMongo(
factory: Factory<CoroutineClient>, factory: Factory<CoroutineClient>,
@ -70,6 +77,12 @@ internal fun Flow<GenericMagixMessage>.storeInMongo(
} }
} }
/** Begin to store MagixMessages from certain flow
* @param flow flow of messages which we will store
* @param meta Meta which may have some configuration parameters for our storage and will be used in invoke method of factory
* @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default.
* @param flowFilter allow you to specify messages which we want to store. Always true by default.
*/
@OptIn(InternalCoroutinesApi::class) @OptIn(InternalCoroutinesApi::class)
public fun Application.storeInMongo( public fun Application.storeInMongo(
flow: MutableSharedFlow<GenericMagixMessage>, flow: MutableSharedFlow<GenericMagixMessage>,

26
controls-xodus/README.md Normal file
View File

@ -0,0 +1,26 @@
# Description
This module allows you to store [DeviceMessages](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt)
from certain [DeviceManager](/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/DeviceManager.kt)
or [MagixMessages](magix/magix-api/src/commonMain/kotlin/ru/mipt/npm/magix/api/MagixMessage.kt)
from [magix server](/magix/magix-server/src/main/kotlin/ru/mipt/npm/magix/server/server.kt)
in [xodus database](https://github.com/JetBrains/xodus).
# Usage
All usage examples can be found in [VirtualCarController](/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCarController.kt).
## Storage from Device Manager
Just call connectMongo. For more details, you can see comments in [source code](/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt)
## Storage from Magix Server
Just pass such lambda as parameter to startMagixServer:
```kotlin
{ flow ->
// some code
storeInXodus(flow)
// some code
}
```
For more details, you can see comments in [source code](/controls-xodus/src/main/kotlin/ru/mipt/npm/controls/xodus/connections.kt)

View File

@ -36,6 +36,13 @@ internal val defaultPersistentStoreFactory = object : Factory<PersistentEntitySt
override fun invoke(meta: Meta, context: Context): PersistentEntityStore = context.getPersistentEntityStore(meta) override fun invoke(meta: Meta, context: Context): PersistentEntityStore = context.getPersistentEntityStore(meta)
} }
/**
* Begin to store DeviceMessages from this DeviceManager
* @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default.
* DeviceManager's meta and context will be used for in invoke method.
* @param filterCondition allow you to specify messages which we want to store. Always true by default.
* @return Job which responsible for our storage
*/
@OptIn(InternalCoroutinesApi::class) @OptIn(InternalCoroutinesApi::class)
public fun DeviceManager.storeMessagesInXodus( public fun DeviceManager.storeMessagesInXodus(
factory: Factory<PersistentEntityStore> = defaultPersistentStoreFactory, factory: Factory<PersistentEntityStore> = defaultPersistentStoreFactory,
@ -83,6 +90,12 @@ internal fun Flow<GenericMagixMessage>.storeInXodus(
} }
} }
/** Begin to store MagixMessages from certain flow
* @param flow flow of messages which we will store
* @param meta Meta which may have some configuration parameters for our storage and will be used in invoke method of factory
* @param factory factory that will be used for creating persistent entity store instance. DefaultPersistentStoreFactory by default.
* @param flowFilter allow you to specify messages which we want to store. Always true by default.
*/
@OptIn(InternalCoroutinesApi::class) @OptIn(InternalCoroutinesApi::class)
public fun Application.storeInXodus( public fun Application.storeInXodus(
flow: MutableSharedFlow<GenericMagixMessage>, flow: MutableSharedFlow<GenericMagixMessage>,