VERSION 5.00
Begin VB.Form frmArbitrator 
   BorderStyle     =   3  'ŒÅ’èÀÞ²±Û¸Þ
   Caption         =   "Blackboard Arbitrator"
   ClientHeight    =   5805
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   9165
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5805
   ScaleWidth      =   9165
   StartUpPosition =   3  'Windows ‚ÌŠù’è’l
   Begin VB.CommandButton cmdResign 
      Caption         =   "Res"
      Enabled         =   0   'False
      Height          =   375
      Left            =   3630
      TabIndex        =   29
      ToolTipText     =   "Resign from the arbitrator"
      Top             =   960
      Width           =   615
   End
   Begin VB.CommandButton cmdTake 
      Caption         =   "Take"
      Enabled         =   0   'False
      Height          =   375
      Left            =   2970
      TabIndex        =   28
      ToolTipText     =   "Take up a arbitrator"
      Top             =   960
      Width           =   615
   End
   Begin VB.TextBox txtMsg 
      BackColor       =   &H8000000F&
      Height          =   675
      Left            =   300
      MultiLine       =   -1  'True
      TabIndex        =   27
      Top             =   4920
      Width           =   3915
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "Delete"
      Enabled         =   0   'False
      Height          =   375
      Left            =   6000
      TabIndex        =   25
      Top             =   960
      Width           =   1215
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "Add"
      Enabled         =   0   'False
      Height          =   375
      Left            =   4680
      TabIndex        =   24
      Top             =   960
      Width           =   1215
   End
   Begin VB.Frame fraItem 
      Caption         =   "Item Properties"
      Enabled         =   0   'False
      Height          =   3975
      Left            =   4560
      TabIndex        =   9
      Top             =   1620
      Width           =   4455
      Begin VB.ComboBox cmbAttr 
         Height          =   300
         ItemData        =   "frmArbitrator.frx":0000
         Left            =   300
         List            =   "frmArbitrator.frx":0010
         Style           =   2  'ÄÞÛ¯ÌßÀÞ³Ý Ø½Ä
         TabIndex        =   26
         Top             =   2190
         Width           =   2595
      End
      Begin VB.CommandButton cmdGet 
         Caption         =   "Get"
         Height          =   375
         Index           =   2
         Left            =   3000
         TabIndex        =   22
         Top             =   1740
         Width           =   1215
      End
      Begin VB.TextBox txtVal 
         BackColor       =   &H8000000F&
         Height          =   315
         Index           =   2
         Left            =   300
         Locked          =   -1  'True
         TabIndex        =   21
         Top             =   1800
         Width           =   2595
      End
      Begin VB.CommandButton cmdGet 
         Caption         =   "Put"
         Height          =   375
         Index           =   3
         Left            =   3000
         TabIndex        =   20
         Top             =   2160
         Width           =   1215
      End
      Begin VB.CommandButton cmdGet 
         Caption         =   "Get"
         Height          =   375
         Index           =   4
         Left            =   3000
         TabIndex        =   18
         Top             =   2940
         Width           =   1215
      End
      Begin VB.TextBox txtVal 
         BackColor       =   &H8000000F&
         Height          =   315
         Index           =   4
         Left            =   300
         Locked          =   -1  'True
         TabIndex        =   17
         Top             =   3000
         Width           =   2595
      End
      Begin VB.TextBox txtVal 
         Height          =   315
         Index           =   5
         Left            =   300
         TabIndex        =   16
         Top             =   3360
         Width           =   2595
      End
      Begin VB.CommandButton cmdGet 
         Caption         =   "Put"
         Height          =   375
         Index           =   5
         Left            =   3000
         TabIndex        =   15
         Top             =   3360
         Width           =   1215
      End
      Begin VB.CommandButton cmdGet 
         Caption         =   "Get"
         Height          =   375
         Index           =   0
         Left            =   3000
         TabIndex        =   13
         Top             =   600
         Width           =   1215
      End
      Begin VB.TextBox txtVal 
         BackColor       =   &H8000000F&
         Height          =   315
         Index           =   0
         Left            =   300
         Locked          =   -1  'True
         TabIndex        =   12
         Top             =   660
         Width           =   2595
      End
      Begin VB.TextBox txtVal 
         Height          =   315
         Index           =   1
         Left            =   300
         TabIndex        =   11
         Top             =   1020
         Width           =   2595
      End
      Begin VB.CommandButton cmdGet 
         Caption         =   "Put"
         Height          =   375
         Index           =   1
         Left            =   3000
         TabIndex        =   10
         Top             =   1020
         Width           =   1215
      End
      Begin VB.Label Label1 
         Caption         =   "Attibute : "
         Height          =   255
         Index           =   5
         Left            =   300
         TabIndex        =   23
         Top             =   1500
         Width           =   2535
      End
      Begin VB.Label Label1 
         Caption         =   "Description : "
         Height          =   255
         Index           =   4
         Left            =   300
         TabIndex        =   19
         Top             =   2700
         Width           =   2535
      End
      Begin VB.Label Label1 
         Caption         =   "Value : "
         Height          =   255
         Index           =   2
         Left            =   300
         TabIndex        =   14
         Top             =   360
         Width           =   2535
      End
   End
   Begin VB.TextBox txtVar 
      Height          =   315
      Left            =   4680
      TabIndex        =   7
      Text            =   "a.b.c.d"
      Top             =   540
      Width           =   2595
   End
   Begin VB.CommandButton cmdDisconnect 
      Caption         =   "Disconnect"
      Enabled         =   0   'False
      Height          =   375
      Left            =   1590
      TabIndex        =   6
      Top             =   960
      Width           =   1215
   End
   Begin VB.CheckBox chkArbit 
      Caption         =   "Arbitrator"
      Height          =   420
      Left            =   3000
      TabIndex        =   5
      Top             =   510
      Width           =   1215
   End
   Begin VB.ListBox lstMsg 
      Height          =   3120
      Left            =   300
      TabIndex        =   3
      Top             =   1740
      Width           =   3915
   End
   Begin VB.CommandButton cmdConnect 
      Caption         =   "Connect"
      Height          =   375
      Left            =   300
      TabIndex        =   1
      Top             =   960
      Width           =   1215
   End
   Begin VB.TextBox txtBB 
      Height          =   315
      Left            =   300
      TabIndex        =   0
      Text            =   "bb"
      Top             =   540
      Width           =   2595
   End
   Begin VB.Label Label1 
      Caption         =   "Item (variable name) : "
      Height          =   255
      Index           =   1
      Left            =   4680
      TabIndex        =   8
      Top             =   240
      Width           =   2535
   End
   Begin VB.Label Label1 
      Caption         =   "Event log : "
      Height          =   255
      Index           =   3
      Left            =   300
      TabIndex        =   4
      Top             =   1440
      Width           =   2535
   End
   Begin VB.Label Label1 
      Caption         =   "Blackboard (controller name) : "
      Height          =   255
      Index           =   0
      Left            =   300
      TabIndex        =   2
      Top             =   240
      Width           =   2535
   End
End
Attribute VB_Name = "frmArbitrator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'
' A Simple Knowledge Source
'
Option Explicit

Dim m_caoEng As CaoEngine
Dim m_caoWs As CaoWorkspace
Dim WithEvents m_caoCtrl As CaoController
Attribute m_caoCtrl.VB_VarHelpID = -1
Dim m_caoVar As CaoVariable


' Initialize
Private Sub Form_Load()

    Set m_caoEng = New CaoEngine
    Set m_caoWs = m_caoEng.Workspaces(0)

End Sub

' Create a blackboard and data
Private Sub cmdConnect_Click()

    On Error GoTo ErrShow
    
    Set m_caoCtrl = m_caoWs.AddController(txtBB.Text, "CaoProv.Blackboard", "", "Arbitrator=" & IIf(chkArbit.Value = vbChecked, "True", "False"))
    
    cmdConnect.Enabled = False
    cmdDisconnect.Enabled = True
    cmdAdd.Enabled = True
    cmdTake.Enabled = True
    cmdResign.Enabled = True
    
    frmArbitrator.Caption = "Blackboard Arbitrator [" & m_caoCtrl.ID & "]"
    
    Exit Sub
ErrShow:
    MsgBox Err.Description
    
End Sub

Private Sub cmdDisconnect_Click()
   
    cmdDelete_Click
    
    Set m_caoCtrl = Nothing
    If Not (m_caoWs Is Nothing) Then m_caoWs.Controllers.Clear
    
    cmdConnect.Enabled = True
    cmdDisconnect.Enabled = False
    cmdAdd.Enabled = False
    cmdTake.Enabled = False
    cmdResign.Enabled = False
    
End Sub

Private Sub cmdTake_Click()
    
    On Error GoTo ErrShow
    
    m_caoCtrl.Execute "TakeArbitrator", vbEmpty     ' Any data can be submitted.
    chkArbit.Value = vbChecked
    
    Exit Sub
ErrShow:
    MsgBox Err.Description

End Sub

Private Sub cmdResign_Click()

    On Error GoTo ErrShow
    
    m_caoCtrl.Execute "ResignArbitrator", vbEmpty   ' Any data can be submitted.
    chkArbit.Value = vbUnchecked
    
    Exit Sub
ErrShow:
    MsgBox Err.Description
    
End Sub

' Add a variable
Private Sub cmdAdd_Click()

    On Error GoTo ErrShow
    
    Set m_caoVar = m_caoCtrl.AddVariable(txtVar.Text)
    
    cmdAdd.Enabled = False
    cmdDelete.Enabled = True
    fraItem.Enabled = True
    
    Exit Sub
ErrShow:
    MsgBox Err.Description

End Sub

Private Sub cmdDelete_Click()

    Set m_caoVar = Nothing
    If Not (m_caoCtrl Is Nothing) Then m_caoCtrl.Variables.Clear

    cmdAdd.Enabled = True
    cmdDelete.Enabled = False
    fraItem.Enabled = False
    
End Sub


' Event sink
Private Sub m_caoCtrl_OnMessage(ByVal pICaoMess As CAOLib.ICaoMessage)

    On Error GoTo ErrSkip
        
    With pICaoMess
        If IsArray(.Value) Then
            lstMsg.AddItem .Description & " : msgid=" & .Number & ", name=" & .Destination & ", sender" & .Source & ", value(0)=" & .Value(0)
        Else
            lstMsg.AddItem .Description & " : msgid=" & .Number & ", name=" & .Destination & ", sender=" & .Source & ", value=" & .Value
        End If
    End With
    
    Exit Sub
ErrSkip:
    lstMsg.AddItem Err.Description

End Sub

' Item Properties
Private Sub cmdGet_Click(Index As Integer)
    
    On Error GoTo ErrShow
    
    Select Case Index
    Case 0  ' get value
        txtVal(0).Text = m_caoVar.Value

    Case 1  ' put value
        m_caoVar.Value = txtVal(1).Text
    
    Case 2  ' get attribute
        txtVal(2).Text = m_caoVar.Attribute

    Case 3  ' put attribute
        m_caoCtrl.Execute "PutItemAttribute", Array(m_caoVar.Name, cmbAttr.ListIndex)
    
    Case 4  ' get help
        txtVal(4).Text = m_caoVar.Help

    Case 5  ' put help
        m_caoCtrl.Execute "PutItemHelp", Array(m_caoVar.Name, txtVal(5).Text)
   
   End Select
    
    Exit Sub
ErrShow:
    MsgBox Err.Description
    
End Sub

Private Sub lstMsg_Click()

    txtMsg.Text = lstMsg.Text
    
End Sub
