|
Define your own protocol to be used with the socket communication. Then send a packet when data has been updated by a calculation. The protocol should be able handle the possible amount of data that is updated by your calculations.
A possible protocol structure may be:
typedef struct
{
int updateType; int firstNdx; int lastNdx; int dataLen; char data[1]; } MyUpdateProtocol;
The updateType may be an enum instead of an <code> int:
enum MyDataMembers
{
IVKK,
FIL,
FDDD,
FCDCP,
};
To create a protocol block calculate the amount of data bytes, allocate memory, cast it, fill it, and send it. Example:
int firstNdx = 0;
int lastNdx = 10;
int dataSize = ((lastNdx - firstNdx) + 1) * sizeof(float);
char *buf = new char[dataSize + sizeof(MyUpdateProtocol) - 1];
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
pProto->updateType = IVKK;
pProto->firstNdx = firstNdx;
pProto->lastNdx = lastNdx;
pProto->dataLen = dataSize;
memcpy(pProto->data, &pModDB->IVKK[firstNdx], dataSize);
sendData(buf, dataSize + sizeof(MyUpdateProtocol) - 1);
delete [] buf;
On the receiving side copy the data according to the protocol header fields:
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
void *dest = NULL;
switch (pProto->updateType)
{
case IVKK : dest = &pModDb->IVKK[pProto->firstNdx]; break;
case FIL : dest = &pModDb->FIL[pProto->firstNdx]; break;
}
memcpy(dest, pProto->data, pProto->dataLen);
|
|
|
|
|
EDIT: LOL hadn't read Jochen's response who did it same way but with some nice protocol sizing. That is pretty nice makes the case statements on the copy enumerate easier. Anyhow you get the idea it isn't a hard task. I will leave the code so you can see what his protocol sizing is simplifying. Did you ever get the network transfer sorted?
Like the people said whats the problem?
You can just do as basic as memcpy I just grabbed your struct and made a zeroed instance and did it to show you.
struct TModDB MyModDB = { 0 };
float DupFXS[30][60];
memcpy(DupFXS, MyModDB.FXS, sizeof(DupFXS));
Really as a commercial thing I would make an enumerator and a single function to copy whatever field I pass the enumerate of or if I can use C++ make it a class or object.
The C enumerate option looks something like follows, your job is to provide a buffer and it's size to the function for the field you are copying
enum DBENUM {
DE_IVKK = 0,
DE_FIL,
DE_FDDD,
DE_FCDCP,
DE_FLH,
};
BOOL DBCopyFunction (enun DBNUM whatToCopy, struct TModDB* TheDB, void* Buf, long SizeOfBuf){
BOOL success = FALSE;
if (TheDb){
switch(whatToCopy){
case DE_IVKK: {
if (sizeof(TheDB->IVKK) <= SizeofBuf) {
memcpy(Buf, TheDB->IVKK, sizeof(TheDB->IVKK));
success = TRUE;
}
}
break;
case DE_FIL: {
if (sizeof(TheDB->FIL) <= SizeofBuf) {
memcpy(Buf, TheDB->FIL, sizeof(TheDB->FIL));
success = TRUE;
}
}
break;
}
}
return (success);
}
There isn't anything complicated that it's just a large complex structure.
In vino veritas
modified 31-May-16 10:28am.
|
|
|
|
|
Thanks a lot for the suggestions.
Let me brief the architecture for your kind understanding
We have 3 applications involved.
1. Model (Runs along with the server and shares the data with Server through Shared memory. Changes the data through formulas and calculations continuously)
2. Server (Updates the data in the shared memory that is changed by the user for recalculation. Gets/Puts the data in shared memory and shares data with model. Also updates client with the updated data from model. Receives user changes from the client.
3. Client (Has number of GUI windows to show the values and receives values from user.)
The Server and the model runs locally and communicates using shared memory. The Client can run either locally or remotely within the network and the communication is using TCP/IP Sockets
I have 2 problems here.
Problem 1:
We dont have hold with the model code. So I cannot detect the value changes from the model.
But both the model and the Server shares the same structure what I have mentioned previously.
So, Is it possible to detect the value changes through shared memory from the Server side?
Problem 2:
As an example if I assume that every alternate member variable array(entire array) is changing, then I have to send 'n' number of times the data through the socket every cycle, where n is the number of member variable arrays in the structure. My concern is the load or performance problem that I had already faced while splitting the data as packets for sending every cycle. I am afraid if the same problem may occur if I send it 'n' number of times.
Please help me and correct me if I am wrong.
|
|
|
|
|
Hi,
You try to detect whether an update has taken place from a remote station.
I take it that you are writing an Application where Clients access the database Direct.
You have two lines of defence here. the function 'stat' will give you the last modify time. If it has not changed since the last time you read it, or wrote to it, your private copy items are still in date.
What to do Next, if the File Stamp has changed. In any case, we need to reload the data, if it affects the records we are dealing with. A Simple check sum will do!
Regards,
Bram
Bram van Kampen
|
|
|
|
|
Thanks a lot for your suggestion.
I think that Stat function is unix based. Can you please give me an example of to detect the structure member variable change using the stat function in windows.
|
|
|
|
|
I think you have already worked out the problem it is going to take you a lot of power to work out what has changed in the mapped file.
The best approach but the hardest would be to intercept the Writefile calls from the Model application since you don't have the code. The process is called IAT patching and you hook the model application write calls and simply send the data for each write call to your client before letting it drop thru to write to the mapfile as normal. There are a couple of IAT patching articles right here on Code Project. It obviously has the massive advantage that effectively it slows the model program down if your update dispatch is slowed and there is no searching to be done you are transmitting the changes as they are made. The downside is this is not something a novice can code it requires a level of experience.
The second alternative is to make an application that simply cycles around comparing the mapfile comparing the mapfile to a local copy of the last scan thru the file and transmitting changes as it encounters them. So you have a local copy of the mapfile as you last visited this position as you then find a change you hold the position in the file and then keep reading while you have differences. All you do then is send a simple structure File position, size of change, change data to the client. Then you continue back to looking for a changes. All the client does is grab a packet, move to the position given and copies the changed data. So the client copy just changes slowly to mirror the server mapfile at whatever rate the packets can be sent. This is how remote terminal services work sending your screen to another user.
The downside of the second alternative is you will often get your fields having part of current data and part old data. For you that is not to bad because you know the structure layout so you can probably carry field flags to indicate if they are currently half changed because you in the process of writing them.
Anyhow whichever technique you use this will not be a trivial task
In vino veritas
|
|
|
|
|
I was thinking a bit more about your problem and there is a possible all be it highly technical solution which is a thing called a file filter. It jogged my interest as to whether you could run a memory mapped file in a file filter so you can get all the raw file access commands and it appears you can
Memory Mapped Files in a File System Filter Driver[^]
It wouldn't be trivial but you would know exactly what and where is being written by the model program to the memory mapped file to then duplicate and send to your client.
In vino veritas
|
|
|
|
|
manoharbalu wrote: Now I need to transfer some of the data values that are changed to another application... A third application, not one of the two applications sharing the structure in memory?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Hello, i've decided to code a application for our committees in our university section. The basic function of the program should be to inform students about upcoming events hosted by different student unions/committees.
Events will be stored in an SQL database. Every event will have a few datas like "Committee name" "Description of event" "Date". The idea is that the app will get all events from the database that hasn't already been. It will display these in a list inside the application. If a new event is uploaded to the SQL database the application will give away a push-notification. And user will be able to display it. I have experience in C.
My questions are
Is there good graphic libraries and is it possible to do this with ease in C++?
Is it possible to make a program like this work in Android and IOS?
Would also appreciate general tips for people that've made mobile applications
|
|
|
|
|
C++ is not very popular in standard mobile applications (and it is not recommended, see, for instance Getting Started with the NDK | Android Developers[^].
For the an Android platform, Java is the natuaral programming language (altough you migh as well use C# via Xamarin ).
|
|
|
|
|
As CPallini said C,C++ coding of Android is not for the faint hearted and I would not recommend it as things stand at current.
I can offer you a funny way into the problem for a medium level programmer which is to use the free Unity game engine. You write in C# and can run your code and debug it as a windows application on windows. Then you just select the target as android and it does all the conversion and crossing to Android for you.
There are several good sample applications right here on Code Project in the Unity section but the cross platform is this simple
Tutorial: Creating your first Unity Android App [2015 Update] « Rabidgremlin's Soapbox[^]
You have a bit of learning to do with the unity interface but there are plenty of tutorials. The SQL classes already exist as standards in Unity like they do in .NET and is rather trivial as most online games store data in/from server databases.
On the plus side all the finger swipe libraries exist already and you can develop a groovy application look on the UI using the graphics stuff
In vino veritas
modified 30-May-16 5:08am.
|
|
|
|
|
Google calendar provides most of this as standard already.
|
|
|
|
|
Yes, I agree Richard but unless someone has done some work since I last tried compiling the code samples for the API even it was not trivial. I lost hours of time playing around with it as I needed old frameworks as well as 5 or 6 newer ones. If they have not improved it I would rate it as needing expert level knowledge but you may have more recent experience.
In vino veritas
|
|
|
|
|
I did not mean the API, just Google calendar.
|
|
|
|
|
I was thinking the same thing.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I have been trying to create a puzzle that can solve itself using BFS algorithm. Currently, the search algorithm and the main but I don't know how to integrate both of them together.
my BFS:
#ifndef BFS_h
#define BFS_h
#include<iostream>
#include <list>
using namespace std;
class Graph
{
int V;
list<int> *adj;
public:
Graph(int V);
void addEdge(int v, int w);
void BFS(int s);
};
Graph::Graph(int V)
{
this->V = V;
adj = new list<int>[V];
}
void Graph::addEdge(int v, int w)
{
adj[v].push_back(w);
}
void Graph::BFS(int s)
{
bool *visited = new bool[V];
for(int i = 0; i < V; i++)
visited[i] = false;
list<int> queue;
visited[s] = true;
queue.push_back(s);
list<int>::iterator i;
while(!queue.empty())
{
s = queue.front();
cout << s << " ";
queue.pop_front();
for(i = adj[s].begin(); i != adj[s].end(); ++i)
{
if(!visited[*i])
{
visited[*i] = true;
queue.push_back(*i);
}
}
}
}
and my main:
#include "queue"
#include <iostream>
#include <iomanip>
#include "BFS.h"
#include "A*search.h"
using namespace std;
int main()
{
int s;
int box1=3,box2=6,box3=9,box4=1,box5=s,box6=7,box7=5,box8=8,box9=2;
cout << " -----------" << endl;
cout << " | " << box1 << " | " << box2 << " | " << box3 << " | " << endl;
cout << " -----------" << endl;
cout << " | " << box4 << " | " << box5 << " | " << box6 << " | " << endl;
cout << " -----------" << endl;
cout << " | " << box7 << " | " << box8 << " | " << box9 << " | " << endl;
cout << " -----------" << endl;
void BFS(int s);
return 0;
|
|
|
|
|
You need to create a Graph object, with one of its constructors, and then call the various methods to construct and solve the puzzle:
int main()
{
int s;
int box1=3,box2=6,box3=9,box4=1,box5=s,box6=7,box7=5,box8=8,box9=2;
cout << " -----------" << endl;
cout << " | " << box1 << " | " << box2 << " | " << box3 << " | " << endl;
cout << " -----------" << endl;
cout << " | " << box4 << " | " << box5 << " | " << box6 << " | " << endl;
cout << " -----------" << endl;
cout << " | " << box7 << " | " << box8 << " | " << box9 << " | " << endl;
cout << " -----------" << endl;
Graph graph = new Graph(V); graph.addEdge(v, w); graph.BFS(int s);
return 0;
}
|
|
|
|
|
So did someone give you these two pieces of code?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I cant use SetItemText() for an owner drawn list control. I try
using
HWND hWnd1 = ::GetDlgItem (m_hWnd,IDC_LIST_1095C);
LVITEM lvi;
lvi.iSubItem = 3;
lvi.pszText = (LPTSTR) "123";
::SendMessage(hWnd1, LVM_SETITEMTEXT, 0, (LPARAM)&lvi);
But it doesnt update the text in the list. Im missing something and I cant
figure out what Im missing.
Please any response any one can give me will be greatly appreciated.
|
|
|
|
|
Are you capturing all messags related to the update?
|
|
|
|
|
I dont know what that means.
|
|
|
|
|
It's owner draw ... have you hooked the draw messages you are supposed to.
We can't see what you are doing or not doing in the draw parts which are your responsibility.
In vino veritas
|
|
|
|
|
Seriously? You have created an owner drawn control and you don't check all the messages that the control receives?
|
|
|
|
|
Have you checked the handle hWnd1 in the debugger since you have done zero error checking before you dispatch the message to it?
Next you haven't zero lvi half it's fields will have rubbish in them, well at least in release mode.
Is the subitem index right, don't forget it is a one-based index ?
Finally try calling an update after the message to force a redraw, I can't tell if it's needed or not because this is owner draw and depends what you have done.
In vino veritas
|
|
|
|
|
You must be desperate, seeing that you reverted to the SDK! Been there too, more than once!
Did you set the item(s) specifically as 'Owner Draw' in the Resource Editor!
If you did not, all the above quoted messages will end up in the 'Bit and Byte Bin', in the nearest toilet!
Hope this is helpful,
Bram van Kampen
|
|
|
|