Check-in [839163987a]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fix client connection handling in topcua subtree
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 839163987ae0377b6f76787f8147ba5486fc88b9
User & Date: chw 2018-09-19 03:32:28
Context
2018-09-20
04:30
update SQLite to version 3.25.1 check-in: e7414c6869 user: chw tags: trunk
2018-09-19
03:32
fix client connection handling in topcua subtree check-in: 839163987a user: chw tags: trunk
2018-09-17
17:53
update SQLite to version 3.25.0 check-in: c2fa0bf108 user: chw tags: trunk
Changes

Changes to jni/topcua/examples/client.tcl.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# wait a while
after 1000

# connect again
opcua connect C opc.tcp://localhost:4840
puts stderr Reconnected

# monitor calback proc
proc monitor {data} {
    puts stderr "Monitor: $data"
}

# make a subscription
set sub [opcua subscription C new 1 1000.0]








|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# wait a while
after 1000

# connect again
opcua connect C opc.tcp://localhost:4840
puts stderr Reconnected

# monitor callback proc
proc monitor {data} {
    puts stderr "Monitor: $data"
}

# make a subscription
set sub [opcua subscription C new 1 1000.0]

Added jni/topcua/examples/uacam_client.tcl.

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# A little OPC/UA webcam client example
package require Tk
package require topcua

wm title . "Client of LilWebCam"
set img [image create photo]
label .label -image $img
pack .label

# create client
opcua new client C

# connect to server
opcua connect C opc.tcp://localhost:4840

# get the namespace
set ns [opcua namespace C LilWebCam]

# monitor callback proc
proc monitor {data} {
    $::img configure -format png -data [dict get $data value]
}

# make a subscription with 200 ms rate
set sub [opcua subscription C new 1 200.0]

# make a monitor to the camera image
set mon [opcua monitor C new $sub data monitor "ns=${ns};Image"]

# handle OPC/UA traffic (the subscription/monitor)
proc do_opcua_traffic {} {
    after cancel do_opcua_traffic
    if {[catch {opcua run C 20}]} {
	# this most likely is the server shutting down
	exit
    }
    after 200 do_opcua_traffic
}

do_opcua_traffic

Changes to jni/topcua/topcua.c.

342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
...
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

477
478
479
480
481
482
483
...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

529
530
531
532
533
534
535
...
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
...
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
...
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
....
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
    { "HasAlarmSuppressionGroup", 16361 },
    { "AlarmGroupMember", 16362 },
    { "HasEffectDisable", 17276 },
    { "HasEffectEnable", 17983 },
    { "HasEffectSuppressed", 17984 },
    { "HasEffectUnsuppressed", 17985 }
};

/*
 * Still, bad things are needed for open62541 release 0.3
 */

typedef struct {
    UA_ClientState nothing_to_see_here;
    UA_ClientConfig config;
    UA_Connection connection;
} Fake_UA_Client;

#define GET_UA_CLIENT_SOCK_FD(c) (((Fake_UA_Client *) (c)))->connection.sockfd

 
/*
 *-------------------------------------------------------------------------
 *
 * DoNotLog --
 *
 *	Silence log messages.
................................................................................
    mon->dv = UA_DataValue_new();
    if (mon->dv == NULL) {
	return;
    }
    UA_DataValue_copy(value, mon->dv);

    if (!mon->pending) {
	int *pendPtr = &mon->sub->uah->pending;

	mon->pending = 1;
	pendPtr[0] += 1;
	if (pendPtr[0] == 64) {
	    /* Highwater mark. */
#ifndef _WIN32
	    Tcl_DeleteFileHandler(GET_UA_CLIENT_SOCK_FD(mon->sub->uah->client));
#endif
	}

	Tcl_DoWhenIdle(MonIdleProc, (ClientData) mon);
    }
}
 
/*
 *-------------------------------------------------------------------------
 *
................................................................................
			  &UA_TYPES[UA_TYPES_VARIANT]);
    if (uaret != UA_STATUSCODE_GOOD) {
	return;
    }
    mon->vvSize = nevt;

    if (!mon->pending) {
	int *pendPtr = &mon->sub->uah->pending;

	mon->pending = 1;
	pendPtr[0] += 1;
	if (pendPtr[0] == 64) {
	    /* Highwater mark. */
#ifndef _WIN32
	    Tcl_DeleteFileHandler(GET_UA_CLIENT_SOCK_FD(mon->sub->uah->client));
#endif
	}

	Tcl_DoWhenIdle(MonIdleProc, (ClientData) mon);
    }
}
 
/*
 *-------------------------------------------------------------------------
 *
................................................................................

static void
MonIdleProc(ClientData clientData)
{
    UAM *mon = (UAM *) clientData;
    UAH *uah = mon->sub->uah;
    UAI *uai = uah->uai;
    int *pendPtr = &uah->pending;
    Tcl_InterpState state;
    int i, ret, nCmdObjs;
    Tcl_Obj **cmdObjs;

    mon->pending = 0;
    pendPtr[0] -= 1;
    if (pendPtr[0] == 32) {
	/* Lowwater mark. */
#ifndef _WIN32
	Tcl_CreateFileHandler(GET_UA_CLIENT_SOCK_FD(uah->client),
			      TCL_READABLE, FileHandler, (ClientData) uah);
#endif
    }
    Tcl_Preserve(uai);
    Tcl_Preserve(uah);
    Tcl_Preserve(uah->interp);
    state = Tcl_SaveInterpState(uah->interp, TCL_OK);
    nCmdObjs = mon->nCmdObjs;
    cmdObjs = mon->cmdObjs;
    mon->nCmdObjs = 0;
................................................................................
	ms = 10;
    } else if (ms > 500) {
	ms = 500;
    }
    uah->timer = Tcl_CreateTimerHandler(ms, RunServer, clientData);
}
 
/*
 *-------------------------------------------------------------------------
 *
 * FileHandler --
 *
 *	POSIX: callback for readability of socket.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	May trigger other callbacks.
 *
 *-------------------------------------------------------------------------
 */

#ifndef _WIN32
static void
FileHandler(ClientData clientData, int mask)
{
    UAH *uah = (UAH *) clientData;

    if ((mask & TCL_READABLE) && (uah->client != NULL)) {
	UA_Client_runAsync(uah->client, 1);
    }
}
#endif
 
/*
 *-------------------------------------------------------------------------
 *
 * ReleaseSubCB --
 *
 *	Deletion callback for a subscription.
 *
................................................................................
 *-------------------------------------------------------------------------
 */

static void
DisconnectClient(UAH *uah)
{
    if (uah->connected) {
#ifndef _WIN32
	Tcl_DeleteFileHandler(GET_UA_CLIENT_SOCK_FD(uah->client));
#endif
	UA_Client_disconnect(uah->client);
	ReleaseSubs(uah);
	uah->connected = 0;
    }
}

static void
................................................................................
					   Tcl_GetString(objv[3]),
					   Tcl_GetString(objv[4]));
    }
    if (uaret != UA_STATUSCODE_GOOD) {
	ReportError(interp, uai, "ClientConnect", uaret);
	return TCL_ERROR;
    }
#ifndef _WIN32
    Tcl_CreateFileHandler(GET_UA_CLIENT_SOCK_FD(uah->client),
			  TCL_READABLE, FileHandler, (ClientData) uah);
#endif
    uah->connected = 1;
    return TCL_OK;
}
 
/*
 *-------------------------------------------------------------------------
 *







<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<

<
<
<
<
<
<
<
>







 







<
<

<
<
<
<
<
<
<
>







 







<





|
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<







 







<
<
<
<







342
343
344
345
346
347
348













349
350
351
352
353
354
355
...
447
448
449
450
451
452
453


454







455
456
457
458
459
460
461
462
...
491
492
493
494
495
496
497


498







499
500
501
502
503
504
505
506
...
520
521
522
523
524
525
526

527
528
529
530
531
532







533
534
535
536
537
538
539
...
627
628
629
630
631
632
633




























634
635
636
637
638
639
640
...
869
870
871
872
873
874
875



876
877
878
879
880
881
882
....
3848
3849
3850
3851
3852
3853
3854




3855
3856
3857
3858
3859
3860
3861
    { "HasAlarmSuppressionGroup", 16361 },
    { "AlarmGroupMember", 16362 },
    { "HasEffectDisable", 17276 },
    { "HasEffectEnable", 17983 },
    { "HasEffectSuppressed", 17984 },
    { "HasEffectUnsuppressed", 17985 }
};













 
/*
 *-------------------------------------------------------------------------
 *
 * DoNotLog --
 *
 *	Silence log messages.
................................................................................
    mon->dv = UA_DataValue_new();
    if (mon->dv == NULL) {
	return;
    }
    UA_DataValue_copy(value, mon->dv);

    if (!mon->pending) {


	mon->pending = 1;







	mon->sub->uah->pending += 1;
	Tcl_DoWhenIdle(MonIdleProc, (ClientData) mon);
    }
}
 
/*
 *-------------------------------------------------------------------------
 *
................................................................................
			  &UA_TYPES[UA_TYPES_VARIANT]);
    if (uaret != UA_STATUSCODE_GOOD) {
	return;
    }
    mon->vvSize = nevt;

    if (!mon->pending) {


	mon->pending = 1;







	mon->sub->uah->pending += 1;
	Tcl_DoWhenIdle(MonIdleProc, (ClientData) mon);
    }
}
 
/*
 *-------------------------------------------------------------------------
 *
................................................................................

static void
MonIdleProc(ClientData clientData)
{
    UAM *mon = (UAM *) clientData;
    UAH *uah = mon->sub->uah;
    UAI *uai = uah->uai;

    Tcl_InterpState state;
    int i, ret, nCmdObjs;
    Tcl_Obj **cmdObjs;

    mon->pending = 0;
    uah->pending -= 1;







    Tcl_Preserve(uai);
    Tcl_Preserve(uah);
    Tcl_Preserve(uah->interp);
    state = Tcl_SaveInterpState(uah->interp, TCL_OK);
    nCmdObjs = mon->nCmdObjs;
    cmdObjs = mon->cmdObjs;
    mon->nCmdObjs = 0;
................................................................................
	ms = 10;
    } else if (ms > 500) {
	ms = 500;
    }
    uah->timer = Tcl_CreateTimerHandler(ms, RunServer, clientData);
}
 




























/*
 *-------------------------------------------------------------------------
 *
 * ReleaseSubCB --
 *
 *	Deletion callback for a subscription.
 *
................................................................................
 *-------------------------------------------------------------------------
 */

static void
DisconnectClient(UAH *uah)
{
    if (uah->connected) {



	UA_Client_disconnect(uah->client);
	ReleaseSubs(uah);
	uah->connected = 0;
    }
}

static void
................................................................................
					   Tcl_GetString(objv[3]),
					   Tcl_GetString(objv[4]));
    }
    if (uaret != UA_STATUSCODE_GOOD) {
	ReportError(interp, uai, "ClientConnect", uaret);
	return TCL_ERROR;
    }




    uah->connected = 1;
    return TCL_OK;
}
 
/*
 *-------------------------------------------------------------------------
 *