Jump to content

Problem with CoProcess and SQLite


Recommended Posts

I'm getting \AutoIt3\Include\File.au3 (24) : ==> "Func" statement has no matching "EndFunc".: as an error when I try to run this script.

CODE
#region Controller

#include <Array.au3>

#include "coproc.au3"

$GUIProcess = _CoProc ("GUIProcess")

$DatabaseProcess = _CoProc ("DatabaseProcess")

$ExecutionerProcess = _CoProc ("ExecutionerProcess")

$SchedulerProcess = _CoProc ("SchedulerProcess")

_SuperGlobalSet ("ControllerID", @AutoItPID)

_CoProcReceiver ("MessageReceiver")

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIProcess) Then

ExitLoop

EndIf

WEnd

Exit

Func MessageReceiver($ReceivedMessage)

;Parse $ReceivedMessage for target, timestamp, message, and priority

;Add Parsed Message to MessageQueue

$ParsedMessage = StringLeft( $ReceivedMessage, 4 )

if $ParsedMessage = "CTRL" Then

MsgBox(0, "I WIN", $ReceivedMessage)

EndIf

EndFunc

#endregion

#region GUIProcess

Func GUIProcess()

#include <GUIConstants.au3>

_SuperGlobalSet ("GUIID", @AutoItPID)

$Form1 = GUICreate("GUI Process", 468, 289, 193, 125)

$Label1 = GUICtrlCreateLabel("Last GUI Event Sent", 8, 8, 102, 17)

$Label2 = GUICtrlCreateLabel("GUI EVENT", 24, 32, 62, 17)

$Label3 = GUICtrlCreateLabel("Current Controller Event", 136, 8, 116, 17)

$Label4 = GUICtrlCreateLabel("Controller Event", 152, 32, 79, 17)

$Label5 = GUICtrlCreateLabel("Database Event", 296, 32, 81, 17)

$Label6 = GUICtrlCreateLabel("Current Database Event", 280, 8, 118, 17)

$Label7 = GUICtrlCreateLabel("Executioner Event", 16, 104, 91, 17)

$Label8 = GUICtrlCreateLabel("Current Executioner Event", 0, 80, 128, 17)

$Label9 = GUICtrlCreateLabel("Scheduler Event", 168, 104, 83, 17)

$Label10 = GUICtrlCreateLabel("Current Scheduler Event", 152, 80, 120, 17)

$Button1 = GUICtrlCreateButton("Send Event 1", 64, 168, 75, 25, 0)

$Button2 = GUICtrlCreateButton("Send Event 2", 160, 168, 75, 25, 0)

$Button3 = GUICtrlCreateButton("Send Event 3", 264, 168, 75, 25, 0)

$Label11 = GUICtrlCreateLabel("Label11", 376, 88, 42, 17)

$Label12 = GUICtrlCreateLabel("Label12", 376, 120, 42, 17)

$Label13 = GUICtrlCreateLabel("Label13", 376, 152, 42, 17)

$Label14 = GUICtrlCreateLabel("Label14", 376, 184, 42, 17)

$Label15 = GUICtrlCreateLabel("Label15", 376, 216, 42, 17)

GUISetState(@SW_SHOW)

$GUIID = _SuperGlobalGet ('GUIID')

$DatabaseID = _SuperGlobalGet ('DatabaseID')

$ControllerID = _SuperGlobalGet ('ControllerID')

$SchedulerID = _SuperGlobalGet ('SchedulerID')

$ExecutionerID = _SuperGlobalGet ('ExecutionerID')

GUICtrlSetData($Label11, $GUIID)

GUICtrlSetData($Label12, $DatabaseID)

GUICtrlSetData($Label13, $ControllerID)

GUICtrlSetData($Label14, $SchedulerID)

GUICtrlSetData($Label15, $ExecutionerID)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

$target = "CTRL"

$timestamp = "PLACEHOLDER"

$priority = "OMG URGENT"

$message = "I need to use the bathroom!"

_CoProcSend ($ControllerID, $target &"|"& $timestamp &"|"& $priority &"|"& $message)

EndSwitch

WEnd

EndFunc

#endregion

#comments-start

#comments-end

#region Database

Func DatabaseProcess()

_SuperGlobalSet ("DatabaseID", @AutoItPID)

$GUIID = _SuperGlobalGet ('GUIID')

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIID) Then

ExitLoop

EndIf

WEnd

EndFunc

#endregion

;comments here

#region Executioner

Func ExecutionerProcess()

_SuperGlobalSet ("ExecutionerID", @AutoItPID)

$GUIID = _SuperGlobalGet ('GUIID')

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIID) Then

ExitLoop

EndIf

WEnd

EndFunc

#endregion

;comments here

#region Schedulers

Func SchedulerProcess()

#include <SQLite.au3>

#include <SQLite.dll.au3>

Local $hQuery, $aRow, $sMsg

_SQLite_Startup ()

_SQLite_Open ("TestDB.db3") ; open :memory: Database

_SQLite_Exec (-1, "INSERT INTO Test(test) VALUES ('r00r2');") ;

_SQlite_Query (-1, "SELECT test2 FROM Test", $hQuery) ; the query

While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK

$sMsg &= $aRow[0] & ", "

WEnd

MsgBox(0,"SQLite","Get Data using a Query : " & $sMsg )

_SQLite_Close()

_SQLite_Shutdown()

EndFunc

#endregion

;comments here

#region Functions

#endregion

;comments here

The problem is specifically due to my trying to launch SQLite in a CoProcess. I need this functionality so that I can have concurrent access to a database during the program runtime.

Here's the program without the SQLite, and it runs just fine. It launches a Controller process, then 4 CoProcesses, and sends data back and forth between each.

By pressing the Send Event 1 button, you send data from the GUI process to the Controller process. The Controller process then sends up a msgbox, but the GUI process is still accessible, and can be active.

Pseudo multi-threading :)

CODE
#region Controller

#include <Array.au3>

#include "coproc.au3"

$GUIProcess = _CoProc ("GUIProcess")

$DatabaseProcess = _CoProc ("DatabaseProcess")

$ExecutionerProcess = _CoProc ("ExecutionerProcess")

$SchedulerProcess = _CoProc ("SchedulerProcess")

_SuperGlobalSet ("ControllerID", @AutoItPID)

_CoProcReceiver ("MessageReceiver")

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIProcess) Then

ExitLoop

EndIf

WEnd

Exit

Func MessageReceiver($ReceivedMessage)

;Parse $ReceivedMessage for target, timestamp, message, and priority

;Add Parsed Message to MessageQueue

$ParsedMessage = StringLeft( $ReceivedMessage, 4 )

if $ParsedMessage = "CTRL" Then

MsgBox(0, "I WIN!", $ReceivedMessage)

EndIf

EndFunc

#endregion

#region GUIProcess

Func GUIProcess()

#include <GUIConstants.au3>

_SuperGlobalSet ("GUIID", @AutoItPID)

$Form1 = GUICreate("GUI Process", 468, 289, 193, 125)

$Label1 = GUICtrlCreateLabel("Last GUI Event Sent", 8, 8, 102, 17)

$Label2 = GUICtrlCreateLabel("GUI EVENT", 24, 32, 62, 17)

$Label3 = GUICtrlCreateLabel("Current Controller Event", 136, 8, 116, 17)

$Label4 = GUICtrlCreateLabel("Controller Event", 152, 32, 79, 17)

$Label5 = GUICtrlCreateLabel("Database Event", 296, 32, 81, 17)

$Label6 = GUICtrlCreateLabel("Current Database Event", 280, 8, 118, 17)

$Label7 = GUICtrlCreateLabel("Executioner Event", 16, 104, 91, 17)

$Label8 = GUICtrlCreateLabel("Current Executioner Event", 0, 80, 128, 17)

$Label9 = GUICtrlCreateLabel("Scheduler Event", 168, 104, 83, 17)

$Label10 = GUICtrlCreateLabel("Current Scheduler Event", 152, 80, 120, 17)

$Button1 = GUICtrlCreateButton("Send Event 1", 64, 168, 75, 25, 0)

$Button2 = GUICtrlCreateButton("Send Event 2", 160, 168, 75, 25, 0)

$Button3 = GUICtrlCreateButton("Send Event 3", 264, 168, 75, 25, 0)

$Label11 = GUICtrlCreateLabel("Label11", 376, 88, 42, 17)

$Label12 = GUICtrlCreateLabel("Label12", 376, 120, 42, 17)

$Label13 = GUICtrlCreateLabel("Label13", 376, 152, 42, 17)

$Label14 = GUICtrlCreateLabel("Label14", 376, 184, 42, 17)

$Label15 = GUICtrlCreateLabel("Label15", 376, 216, 42, 17)

GUISetState(@SW_SHOW)

$GUIID = _SuperGlobalGet ('GUIID')

$DatabaseID = _SuperGlobalGet ('DatabaseID')

$ControllerID = _SuperGlobalGet ('ControllerID')

$SchedulerID = _SuperGlobalGet ('SchedulerID')

$ExecutionerID = _SuperGlobalGet ('ExecutionerID')

GUICtrlSetData($Label11, $GUIID)

GUICtrlSetData($Label12, $DatabaseID)

GUICtrlSetData($Label13, $ControllerID)

GUICtrlSetData($Label14, $SchedulerID)

GUICtrlSetData($Label15, $ExecutionerID)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

$target = "CTRL"

$timestamp = "PLACEHOLDER"

$priority = "OMG URGENT"

$message = "I need to use the bathroom!"

_CoProcSend ($ControllerID, $target &"|"& $timestamp &"|"& $priority &"|"& $message)

EndSwitch

WEnd

EndFunc

#endregion

#comments-start

#comments-end

#region Database

Func DatabaseProcess()

_SuperGlobalSet ("DatabaseID", @AutoItPID)

$GUIID = _SuperGlobalGet ('GUIID')

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIID) Then

ExitLoop

EndIf

WEnd

EndFunc

#endregion

;comments here

#region Executioner

Func ExecutionerProcess()

_SuperGlobalSet ("ExecutionerID", @AutoItPID)

$GUIID = _SuperGlobalGet ('GUIID')

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIID) Then

ExitLoop

EndIf

WEnd

EndFunc

#endregion

;comments here

#region Schedulers

Func SchedulerProcess()

_SuperGlobalSet ("SchedulerID", @AutoItPID)

$GUIID = _SuperGlobalGet ('GUIID')

While 1

;Read Message Queue and Remove read message

;Send Next Message to Target

if Not ProcessExists($GUIID) Then

ExitLoop

EndIf

WEnd

EndFunc

#endregion

;comments here

#region Functions

#endregion

;comments here

At any rate, I can't figure out why I'm getting the error with File.au3

Edited by Jrowe
Link to comment
Share on other sites

It works if I place the SQLite access in the Controller (Main) Process.

I may just do away with everything in AutoIt memory and just run queries for data storage and retrieval, and delegate event handling to the Scheduler process. At any rate, if anyone has a solution, I would be greatly obliged :)

:)

Link to comment
Share on other sites

Still not sure as to what's going on; Is there a limit to #include that's causing the file.au3 to be incomplete as it's read? Or maybe I'm not giving it enough time to launch?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...