112855Sgabeblack@google.com#include "systemc.h"
212855Sgabeblack@google.com
312855Sgabeblack@google.com// Interface
412855Sgabeblack@google.comclass C_if : virtual public sc_interface
512855Sgabeblack@google.com{
612855Sgabeblack@google.compublic:
712855Sgabeblack@google.com    virtual void run() = 0;
812855Sgabeblack@google.com};
912855Sgabeblack@google.com
1012855Sgabeblack@google.com// Channel
1112855Sgabeblack@google.comclass C : public C_if, public sc_channel
1212855Sgabeblack@google.com{
1312855Sgabeblack@google.compublic:
1412855Sgabeblack@google.com    SC_CTOR(C) { }
1512855Sgabeblack@google.com    virtual void run()
1612855Sgabeblack@google.com    {
1712855Sgabeblack@google.com        cout << sc_time_stamp() << " In Channel run() " << endl;
1812855Sgabeblack@google.com    }
1912855Sgabeblack@google.com};
2012855Sgabeblack@google.com
2112855Sgabeblack@google.com// --- D: export channel C through IFP --------
2212855Sgabeblack@google.comSC_MODULE( D )
2312855Sgabeblack@google.com{
2412855Sgabeblack@google.com    sc_export<C_if> IFP;
2512855Sgabeblack@google.com
2612855Sgabeblack@google.com    SC_CTOR( D )
2712855Sgabeblack@google.com	: IFP("IFP"),   // explicit name
2812855Sgabeblack@google.com	  m_C("C")
2912855Sgabeblack@google.com    {
3012855Sgabeblack@google.com	IFP( m_C );     // bind sc_export->interface by name
3112855Sgabeblack@google.com    }
3212855Sgabeblack@google.com private:
3312855Sgabeblack@google.com    C m_C;            // channel
3412855Sgabeblack@google.com};
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com// --- E: module with two interface-ports ---
3712855Sgabeblack@google.comSC_MODULE( E )
3812855Sgabeblack@google.com{
3912855Sgabeblack@google.com private:
4012855Sgabeblack@google.com    C m_C;
4112855Sgabeblack@google.com    D m_D;
4212855Sgabeblack@google.com
4312855Sgabeblack@google.com public:
4412855Sgabeblack@google.com    sc_export<C_if> IFP1;
4512855Sgabeblack@google.com    sc_export<C_if> IFP2;
4612855Sgabeblack@google.com
4712855Sgabeblack@google.com    SC_CTOR( E )
4812855Sgabeblack@google.com	: m_C("C"),
4912855Sgabeblack@google.com	  m_D("D"),
5012855Sgabeblack@google.com          IFP1("IFP1")
5112855Sgabeblack@google.com    {
5212855Sgabeblack@google.com        IFP1( m_C );
5312855Sgabeblack@google.com	IFP2( m_D.IFP );          // bind sc_export->sc_export by name
5412855Sgabeblack@google.com        IFP1.get_interface();     // just to see whether it compiles
5512855Sgabeblack@google.com    }
5612855Sgabeblack@google.com};
5712855Sgabeblack@google.com
5812855Sgabeblack@google.com// Module X connected to the channels through E
5912855Sgabeblack@google.comSC_MODULE( X )
6012855Sgabeblack@google.com{
6112855Sgabeblack@google.com    sc_port<C_if> P1;
6212855Sgabeblack@google.com    sc_port<C_if> P2;
6312855Sgabeblack@google.com    SC_CTOR(X) {
6412855Sgabeblack@google.com        SC_THREAD(run);
6512855Sgabeblack@google.com    }
6612855Sgabeblack@google.com    void run() {
6712855Sgabeblack@google.com        wait(10, SC_NS);
6812855Sgabeblack@google.com	P1->run();
6912855Sgabeblack@google.com	wait(10, SC_NS);
7012855Sgabeblack@google.com	P2->run();
7112855Sgabeblack@google.com    }
7212855Sgabeblack@google.com};
7312855Sgabeblack@google.com
7412855Sgabeblack@google.comint sc_main(int argc, char** argv) {
7512855Sgabeblack@google.com  E the_E("E");
7612855Sgabeblack@google.com  X the_X("X");
7712855Sgabeblack@google.com  // port->IFP
7812855Sgabeblack@google.com  the_X.P1( the_E.IFP1 );
7912855Sgabeblack@google.com  the_X.P2( the_E.IFP2 );
8012855Sgabeblack@google.com
8112855Sgabeblack@google.com  sc_start(17, SC_NS);
8212855Sgabeblack@google.com  the_E.IFP1->run();  // testing the operator-> of sc_export
8312855Sgabeblack@google.com  sc_start(50, SC_NS);
8412855Sgabeblack@google.com
8512855Sgabeblack@google.com  return 0;
8612855Sgabeblack@google.com}
87