diff --git a/mem/idealmemcontroller/mock_sim_test.go b/mem/idealmemcontroller/mock_sim_test.go index b89ee48a..c34db6b8 100644 --- a/mem/idealmemcontroller/mock_sim_test.go +++ b/mem/idealmemcontroller/mock_sim_test.go @@ -272,6 +272,20 @@ func (mr *MockConnectionMockRecorder) Hooks() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Hooks", reflect.TypeOf((*MockConnection)(nil).Hooks)) } +// Name mocks base method. +func (m *MockConnection) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockConnectionMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockConnection)(nil).Name)) +} + // NotifyAvailable mocks base method. func (m *MockConnection) NotifyAvailable(arg0 sim.Port) { m.ctrl.T.Helper() diff --git a/sim/connection.go b/sim/connection.go index 59f6f6d8..2052b28c 100644 --- a/sim/connection.go +++ b/sim/connection.go @@ -11,6 +11,7 @@ func NewSendError() *SendError { // A Connection is responsible for delivering messages to its destination. type Connection interface { + Named Hookable // PlugIn connects a port to the connection. The connection should reserve diff --git a/sim/directconnection/builder.go b/sim/directconnection/builder.go index a23fba7f..077478f5 100644 --- a/sim/directconnection/builder.go +++ b/sim/directconnection/builder.go @@ -25,7 +25,11 @@ func (b Builder) WithFreq(f sim.Freq) Builder { func (b Builder) Build(name string) *Comp { c := &Comp{} c.TickingComponent = sim.NewSecondaryTickingComponent(name, b.engine, b.freq, c) - middleware := &middleware{Comp: c} + + middleware := &middleware{ + Comp: c, + } c.AddMiddleware(middleware) + return c } diff --git a/sim/directconnection/directconnection.go b/sim/directconnection/directconnection.go index d542e160..8f7ccbbe 100644 --- a/sim/directconnection/directconnection.go +++ b/sim/directconnection/directconnection.go @@ -80,7 +80,9 @@ func (m *middleware) forwardMany( break } - err := head.Meta().Dst.Deliver(head) + dst := head.Meta().Dst + + err := dst.Deliver(head) if err != nil { break } diff --git a/sim/directconnection/mock_sim_test.go b/sim/directconnection/mock_sim_test.go index d422fb26..972bfb25 100644 --- a/sim/directconnection/mock_sim_test.go +++ b/sim/directconnection/mock_sim_test.go @@ -464,6 +464,20 @@ func (mr *MockConnectionMockRecorder) Hooks() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Hooks", reflect.TypeOf((*MockConnection)(nil).Hooks)) } +// Name mocks base method. +func (m *MockConnection) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockConnectionMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockConnection)(nil).Name)) +} + // NotifyAvailable mocks base method. func (m *MockConnection) NotifyAvailable(arg0 sim.Port) { m.ctrl.T.Helper() diff --git a/sim/mock_sim_test.go b/sim/mock_sim_test.go index af4c4499..6c84be11 100644 --- a/sim/mock_sim_test.go +++ b/sim/mock_sim_test.go @@ -463,6 +463,20 @@ func (mr *MockConnectionMockRecorder) Hooks() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Hooks", reflect.TypeOf((*MockConnection)(nil).Hooks)) } +// Name mocks base method. +func (m *MockConnection) Name() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(string) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockConnectionMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockConnection)(nil).Name)) +} + // NotifyAvailable mocks base method. func (m *MockConnection) NotifyAvailable(arg0 Port) { m.ctrl.T.Helper() diff --git a/sim/port.go b/sim/port.go index dfbee3be..83eb45bf 100644 --- a/sim/port.go +++ b/sim/port.go @@ -1,6 +1,7 @@ package sim import ( + "fmt" "sync" ) @@ -51,6 +52,16 @@ var HookPosPortMsgRetrieve = &HookPos{Name: "Port Msg Retrieve"} // SetConnection sets which connection plugged in to this port. func (p *LimitNumMsgPort) SetConnection(conn Connection) { + if p.conn != nil { + connName := p.conn.Name() + newConnName := conn.Name() + panicMsg := fmt.Sprintf( + "connection already set to %s, now connecting to %s", + connName, newConnName, + ) + panic(panicMsg) + } + p.conn = conn }