source: UH/SAMGAR/SAMGAR Gui/SourceFiles/Key.cpp @ 125

Revision 125, 3.7 KB checked in by KDucasse, 10 years ago (diff)
Line 
1
2
3
4//#include "includes.h"
5#include "juce_amalgamated.h"
6#include "MainComponent.h"
7#include "LogComponent.h"
8//#include <stdio.h>
9#include <time.h>
10
11using namespace std;
12using namespace yarp::os;
13
14static MainComponent* MyComponent;
15
16
17
18
19 // this port is connected to the server
20 class DataPort : public BufferedPort<Bottle>
21{
22public:
23
24int hasitworked;
25   
26
27        DataPort(MainComponent* MyComp)
28        {
29                // cant init mycomponent here but need it to be static so its done elsewhere
30                MyComponent=MyComp; //transfer over pointer to the main gui
31                useCallback();      // set the port to use onRead
32                MyComponent->AddToLog("Connecting to server \n ",1); // add to the log
33                open("/KeyToLocalServer"); // open the port
34        //      setStrict(true);
35                hasitworked=Network::connect(Network::getNameServerName(),"/KeyToLocalServer","tcp"); // connect them up
36        }
37
38
39          virtual void onRead(Bottle& b)
40         {
41                static String myvar;
42                static String TempVar;
43        //      MyComponent->stopTimer();
44                myvar=b.toString().c_str();
45        //      MyComponent->AddToLog("Misc "+myvar+" \n",1);
46                // this adds new ports to the gui
47
48                if(myvar.indexOfWholeWord(String("[add]"))==0) // if a port is addid
49                {
50                        if(myvar.indexOfWholeWord(String("/Main"))==7) // if main is the next word signifying its a module and not just a port
51                        {
52                        TempVar = myvar.substring(13);
53                        TempVar=TempVar.dropLastCharacters(1);
54                        MyComponent->AddModule(TempVar);
55                        Network::connect(string(TempVar).c_str(),"/PortForModules");
56                        Network::connect("/PortForModules",string(TempVar).c_str());
57                        }
58                        else if(myvar.indexOfWholeWord(String("/Port"))==7)
59                        {
60                        TempVar = myvar.substring(13);
61                        String parent=TempVar.dropLastCharacters(TempVar.length()-TempVar.indexOf(String("_")));
62                        String Child =TempVar.replaceSection(0,TempVar.indexOf(String("_"))+1,String(" "));
63                        Child = Child.dropLastCharacters(1);
64                        MyComponent->AddPort(parent,Child);
65                        }
66                }
67        //      MyComponent->startTimer(5000);
68     }
69
70};
71
72
73class HelloWorldWindow  : public DocumentWindow
74{
75public:
76    //==============================================================================
77    HelloWorldWindow(): DocumentWindow (T("SAMGAR network profile"),Colours::lightgrey,DocumentWindow::allButtons,true)
78    {
79        MainComponent* const contentComponent = new MainComponent();
80        setContentComponent (contentComponent, true, true);
81        centreWithSize (getWidth(), getHeight());
82        setVisible (true);
83                MyComponent= new MainComponent();// used for port, needs to be setup outside class
84                static DataPort PortForLocalServer(contentComponent); // make sure the port is static and pass it the pointer to the gui
85    }
86
87    ~HelloWorldWindow()   { /* (the content component will be deleted automatically, so no need to do it here) */    }
88
89    void closeButtonPressed()   {JUCEApplication::quit();} // little cross top right
90};
91
92class JUCEHelloWorldApplication : public JUCEApplication
93{
94   
95    HelloWorldWindow* helloWorldWindow;
96
97public:
98 
99    void initialise (const String& commandLine)
100    {
101        helloWorldWindow = new HelloWorldWindow();
102    }
103
104    void shutdown()
105    {
106        if (helloWorldWindow != 0)
107            delete helloWorldWindow;
108    }
109
110    //==============================================================================
111    const String getApplicationName()
112    {
113        return T("SAMGAR Network Profile");
114    }
115
116    const String getApplicationVersion()
117    {
118        return T("1.0");
119    }
120
121    bool moreThanOneInstanceAllowed()
122    {
123        return true;
124    }
125
126    void anotherInstanceStarted (const String& commandLine)
127    {
128    }
129};
130
131
132
133START_JUCE_APPLICATION (JUCEHelloWorldApplication)
Note: See TracBrowser for help on using the repository browser.